Skip to content

Commit

Permalink
Updated code to mesh with get_weights returning a dict and new tf code (
Browse files Browse the repository at this point in the history
ray-project#187)

* Updated code to mesh with get_weights returning a dict and new tf code

* Added tf.global_variables_initalizer to hyperopt example as well

* Small fix.

* Small name change.
  • Loading branch information
Wapaul1 authored and robertnishihara committed Jan 7, 2017
1 parent 0ac2abe commit c45342e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions doc/using-ray-with-tensorflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def net_vars_initializer():
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)
# Define the weight initializer and session.
init = tf.initialize_all_variables()
init = tf.global_variables_initializer()
sess = tf.Session()
# Additional code for setting and getting the weights.
variables = ray.experimental.TensorFlowVariables(loss, sess)
Expand Down Expand Up @@ -159,9 +159,10 @@ for iteration in range(NUM_ITERS):
new_weights_ids = [step.remote(weights_id, x_ids[i], y_ids[i]) for i in range(NUM_BATCHES)]
# Get all of the weights.
new_weights_list = ray.get(new_weights_ids)
# Add up all the different weights. Each element of new_weights_list is a list
# of weights, and we want to add up these lists component wise.
weights = [sum(weight_tuple) / NUM_BATCHES for weight_tuple in zip(*new_weights_list)]
# Add up all the different weights. Each element of new_weights_list is a dict
# of weights, and we want to add up these dicts component wise using the keys
# of the first dict.
weights = {variable: sum(weight_dict[variable] for weight_dict in new_weights_list) / NUM_BATCHES for variable in new_weights_list[0]}
# Print the current weights. They should converge to roughly to the values 0.1
# and 0.3 used in generate_fake_x_y_data.
if iteration % 20 == 0:
Expand Down
2 changes: 1 addition & 1 deletion examples/hyperopt/hyperopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def train_cnn_and_compute_accuracy(params, steps, train_images, train_labels, va
# Do the training and evaluation.
with tf.Session() as sess:
# Initialize the network weights.
sess.run(tf.initialize_all_variables())
sess.run(tf.global_variables_initializer())
for i in range(1, steps + 1):
# Fetch the next batch of data.
image_batch = get_batch(train_images, i, batch_size)
Expand Down

0 comments on commit c45342e

Please sign in to comment.