合并张量板的摘要时出错

error while merging summaries for tensorboard

我正在尝试为 MNIST 初学者教程生成图表,但出现以下错误。由于某种原因,merged_summary_op 对象是 None。

Traceback (most recent call last):
  File "mnist1.py", line 48, in <module>
    summary_str = sess.run(merged_summary_op)
  File "/home/vagrant/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 307, in run
    % (subfetch, fetch, type(subfetch), e.message))
TypeError: Fetch argument None of None has invalid type <type 'NoneType'>, must be a string or Tensor. (Can not convert a NoneType into a Tensor or Operation.)

我想我在这里漏掉了一步。我先启动会话,然后 运行 声明:

merged_summary_op = tf.merge_all_summaries()

我有同样的错误。

就我而言,在调用 tf.merge_all_summaries() 之前至少添加一个 tf.scalar_summary() 解决了问题。

例如,

cross_entropy = -tf.reduce_sum(y_*tf.log(y))
tf.scalar_summary("cross_entropy", cross_entropy)
merged_summary_op = tf.merge_all_summaries()

希望这段代码对您有所帮助。