Tensorboard - add_summary 让我的代码崩溃

Tensorboad - add_summary makes my code crashes

我是tensorflow的新手,我尝试展示我的第一个tensorboard。

我为此处给出的示例下载并执行了 ok 板 https://www.tensorflow.org/versions/r0.7/how_tos/summaries_and_tensorboard/index.html

按照方法,我的代码中有:

weights_hidden = tf.Variable(tf.truncated_normal([image_size * image_size, 1024]), name='weights_hidden')
_ = tf.histogram_summary('weights_hidden', weights_hidden)

当我 运行 会话

with tf.Session(graph=graph) as session:
  merged = tf.merge_all_summaries()
  writer = tf.train.SummaryWriter("/tmp/test", session.graph_def)
  tf.initialize_all_variables().run()
  for step in range(num_steps):
    summary_str, l, predictions = session.run(
      [optimizer, loss, train_prediction], feed_dict=feed_dict)

    if (step % 500 == 0):
      writer.add_summary(summary_str, step)

进程崩溃并出现以下错误

Traceback (most recent call last):
  File "/home/xxx/Desktop/xxx/xxx.py", line 108, in <module>
    writer.add_summary(summary_str, step)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/summary_io.py", line 128, in add_summary
    event = event_pb2.Event(wall_time=time.time(), summary=summary)
  File "/usr/local/lib/python2.7/dist-packages/google/protobuf/internal/python_message.py", line 522, in init
    _ReraiseTypeErrorWithFieldName(message_descriptor.name, field_name)
  File "/usr/local/lib/python2.7/dist-packages/google/protobuf/internal/python_message.py", line 453, in _ReraiseTypeErrorWithFieldName
    six.reraise(type(exc), exc, sys.exc_info()[2])
  File "/usr/local/lib/python2.7/dist-packages/google/protobuf/internal/python_message.py", line 520, in init
    copy.MergeFrom(new_val)
  File "/usr/local/lib/python2.7/dist-packages/google/protobuf/internal/python_message.py", line 1237, in MergeFrom
    "expected %s got %s." % (cls.__name__, type(msg).__name__))
TypeError: Parameter to MergeFrom() must be instance of same class: expected Summary got NoneType. for field Event.summary

我错过了什么? 任何 help/comment 都将非常受欢迎

非常感谢您的帮助

K。

你应该写:

_, summary_str, l, predictions = session.run(
  [optimizer, merged, loss, train_prediction], feed_dict=feed_dict)

我添加了第 4 个参数 merged,它对应于您试图获得的摘要(您只获得了优化步骤的结果)。