mirror of
https://github.com/wassname/ray.git
synced 2026-07-28 11:25:04 +08:00
Updated code to mesh with get_weights returning a dict and new tf code (#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.
This commit is contained in:
committed by
Robert Nishihara
parent
0ac2abee51
commit
c45342e39d
@@ -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)
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user