gpt4 book ai didi

tensorflow - 如何在 MonitoredTrainingSession 中获取 global_step?

转载 作者:行者123 更新时间:2023-12-05 07:38:18 25 4
gpt4 key购买 nike

我在分布式 TensorFlow 中运行分布式 mnist 模型。我想“手动”监视 global_step 的演变以进行调试。在分布式 TensorFlow 设置中获得全局步骤的最佳且干净的方法是什么?

下面是我的代码

 ...

with tf.device(device):
images = tf.placeholder(tf.float32, [None, 784], name='image_input')
labels = tf.placeholder(tf.float32, [None], name='label_input')
data = read_data_sets(FLAGS.data_dir,
one_hot=False,
fake_data=False)
logits = mnist.inference(images, FLAGS.hidden1, FLAGS.hidden2)
loss = mnist.loss(logits, labels)
loss = tf.Print(loss, [loss], message="Loss = ")
train_op = mnist.training(loss, FLAGS.learning_rate)

hooks=[tf.train.StopAtStepHook(last_step=FLAGS.nb_steps)]

with tf.train.MonitoredTrainingSession(
master=target,
is_chief=(FLAGS.task_index == 0),
checkpoint_dir=FLAGS.log_dir,
hooks = hooks) as sess:


while not sess.should_stop():
xs, ys = data.train.next_batch(FLAGS.batch_size, fake_data=False)
sess.run([train_op], feed_dict={images:xs, labels:ys})

global_step_value = # ... what is the clean way to get this variable

最佳答案

通常一个好的做法是在图形定义过程中初始化全局步骤变量,例如global_step = tf.Variable(0, trainable=False, name='global_step')。然后,您可以使用 graph.get_tensor_by_name("global_step:0") 轻松获取全局步骤。

关于tensorflow - 如何在 MonitoredTrainingSession 中获取 global_step?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48022577/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com