作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在分布式 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/
我是一名优秀的程序员,十分优秀!