hanugm
hanugm

Reputation: 1417

Module 'Tensorflow' has no attribute 'summary'

I am executing a program containing the following lines:

def write_log(callback, name, loss, batch_no):
    """
    Write training summary to TensorBoard
    """
    summary = tf.Summary()
    summary_value = summary.value.add()
    summary_value.simple_value = loss
    summary_value.tag = name
    callback.writer.add_summary(summary, batch_no)
    callback.writer.flush()

summary = tf.Summary() is causing the following error

Error: AttributeError: module 'tensorflow' has no attribute 'Summary'

Tensorflow version I am using is 2.3.0. Remaining functions related to 'TensorFlow' are working fine.

How can I fix this?

Upvotes: 3

Views: 7300

Answers (1)

Guillem
Guillem

Reputation: 2647

Looking at the documentation of tensorflow, the usage of the tensorboard summary is different now:

writer = tf.summary.create_file_writer("/tmp/mylogs")
with writer.as_default():
  for step in range(100):
    # other model code would go here
    tf.summary.scalar("my_metric", 0.5, step=step)
    writer.flush()

Upvotes: 6

Related Questions