tensorflow: Cannot get TensorBoard example working

Here’s my code:

merged_summary_op = tf.merge_all_summaries()
summary_writer = tf.train.SummaryWriter('/tmp/mnist_logs', sess.graph_def)
for i in range(200):
    batch = mnist.train.next_batch(50)
    sess.run(train_step, feed_dict={x: batch[0], y_: batch[1])
    if i % 100 == 0:
        train_accuracy = sess.run(train_step, feed_dict={x: batch[0], y_: batch[1]})
        summary_str = sess.run(merged_summary_op, feed_dict={x: batch[0], y_: batch[1]})
        summary_writer.add_summary(summary_str, i)

but got this error at line sess.run(merged_summary_op, ...)

InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-39-f56ad86fef0b> in <module>()
----> sess.run(merged_summary_op, feed_dict={x: batch[0], y_: batch[1]})

/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in run(self, fetches, feed_dict)
    343 
    344     # Run request and get response.
--> 345     results = self._do_run(target_list, unique_fetch_targets, feed_dict_string)
    346 
    347     # User may have fetched the same tensor multiple times, but we

/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in _do_run(self, target_list, fetch_list, feed_dict)
    417         # pylint: disable=protected-access
    418         raise errors._make_specific_exception(node_def, op, e.error_message,
--> 419                                               e.code)
    420         # pylint: enable=protected-access
    421       raise e_type, e_value, e_traceback

InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder' with dtype float

The error message you must feed a value for placeholder tensor doesn’t make much sense. The line above that with similar structure ran just fine.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 2
  • Comments: 18 (2 by maintainers)

Commits related to this issue

Most upvoted comments

I was getting the same error although my code looked similar to the one above. I’m using the interactive Jupyter Notebook environment, and I figured out that shutting down and restarting the notebook somehow solved my problem.

same error, can confirm mine was also a jupyter notebook problem. I think this arises when running the graph definition more than once (there are all sorts of problems with this!).

I had similar issues with jupyter notebooks and discovered that explicitly flushing and closing the summary writer helped.

tw = tf.train.SummaryWriter('./logDir',sess.graph)

# Train your network

tw.flush()
tw.close()

I faced same problem with Jupyter notebook. The reason is not clear yet. But I agree with achristensen56-san’s comment.

If I run scripts more than 2 times, including # placeholder, I faced same issue.

Unfortunatelly. hblasins-san’s method didn’t work well in my case.

You don’t need use Jupyter’s restart. (it is stressful) With executing tf.reset_default_graph(), you can start your session from graph definition.

This was written by Guillermo-san in stackoverflow. https://stackoverflow.com/questions/39356714/using-tensorboard-with-jupyter-notebooks

Just Kernel:Restart & Run All