DrMcCleod
DrMcCleod

Reputation: 4053

In Tensorflow, how do I generate a scalar summary?

Does anyone have a minimal example of using a SummaryWriter with a scalar_summary in order to see (say) a cross entropy result during a training run?

The example given in the documentation:

merged_summary_op = tf.merge_all_summaries()
summary_writer = tf.train.SummaryWriter('/tmp/mnist_logs', sess.graph_def)
total_step = 0
while training:
    total_step += 1
    session.run(training_op)
    if total_step % 100 == 0:
        summary_str = session.run(merged_summary_op)
        summary_writer.add_summary(summary_str, total_step)

Returns an error: TypeError: Fetch argument None of None has invalid type , must be a string or Tensor. (Can not convert a NoneType into a Tensor or Operation.) When I run it.

If I add a:

tf.scalar_summary('cross entropy', cross_entropy)

operation after my cross entropy calculation, then instead I get the error:

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

Which suggests that I need to add a feed_dict to the

summary_str = session.run(merged_summary_op)

call, but I am not clear what that feed_dict should contain....

Upvotes: 3

Views: 4471

Answers (2)

Andrzej Pronobis
Andrzej Pronobis

Reputation: 36106

The feed_dict should contain the same values that you use for running the training_op. It basically specifies the input values to your network for which you want to calculate the summaries.

Upvotes: 3

dga
dga

Reputation: 21927

The error is probably coming from:

session.run(training_op)

Did you paste the example code into a version of the mnist code that requires a feed_dict for feeding in training examples? Check the backtrace it gave you (and include it above if that doesn't solve the problem).

Upvotes: 2

Related Questions