Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'tensorflow' has no attribute 'Summary' #9

Open
palunel opened this issue Apr 23, 2019 · 4 comments
Open

AttributeError: module 'tensorflow' has no attribute 'Summary' #9

palunel opened this issue Apr 23, 2019 · 4 comments

Comments

@palunel
Copy link

palunel commented Apr 23, 2019

I use pytorch with the following implementation:

from tensorboardcolab import TensorBoardColab
tb = TensorBoardColab()

and this call:

tb.save_value('Validation Accuracy', 'valid_acc',i, validation_acc)

Traceback gives me this error:

AttributeError                            Traceback (most recent call last)

<ipython-input-23-1106bec90267> in <module>()
      6 optimizer = optim.Adam(model.parameters(), lr=0.001, weight_decay=0.0001)
      7 training_epochs = 150
----> 8 metrics = train(model, train_loader, test_loader, loss, optimizer, training_epochs)
      9 
     10 summary(model, (3, 32,32))

1 frames

/usr/local/lib/python3.6/dist-packages/tensorboardcolab/core.py in save_value(self, graph_name, line_name, epoch, value)
     99                 tf.contrib.summary.scalar(graph_name, value)
    100         else:
--> 101             summary = tf.Summary()
    102             summary_value = summary.value.add()
    103             summary_value.simple_value = value

AttributeError: module 'tensorflow' has no attribute 'Summary'
@denabazazian
Copy link

denabazazian commented Jan 15, 2020

In the recent version of TensorFlow, you should replace these lines:

summary = tf.Summary()
summary_value = summary.value.add()
summary_value.simple_value = value
summary_value.tag = graph_name

with:

with self.writer.as_default():

              tf.summary.scalar(graph_name, value)

              self.writer.flush()

Also, replace this line:

self.writer = tf.summary.FileWriter(log_dir)

with:

self.writer = tf.summary.create_file_writer(log_dir)

@Michael-J98
Copy link

I got another error after following the above instruction:

ValueError Traceback (most recent call last)
in ()
19 if x%10==0:
20 print("Epoch[{}], Train_Iterations[{}]--mean_loss:{} ".format(epoch,x,loss))
---> 21 tb.save_value('Train Loss', 'train_loss', global_iter, loss.item())
22 optimizer.zero_grad()
23 loss.backward()

2 frames
/usr/local/lib/python3.6/dist-packages/tensorboardcolab/core.py in save_value(self, graph_name, line_name, epoch, value)
100 else:
101 with self.writer.as_default():
--> 102 tf.summary.scalar(graph_name, value)
103 self.writer.flush()
104

/usr/local/lib/python3.6/dist-packages/tensorboard/plugins/scalar/summary_v2.py in scalar(name, data, step, description)
66 tensor=tf.cast(data, tf.float32),
67 step=step,
---> 68 metadata=summary_metadata,
69 )
70

/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/summary_ops_v2.py in write(tag, tensor, step, metadata, name)
647 step = get_step()
648 if step is None:
--> 649 raise ValueError("No step set via 'step' argument or "
650 "tf.summary.experimental.set_step()")
651 if metadata is None:

ValueError: No step set via 'step' argument or tf.summary.experimental.set_step()

Is this about the version too?

@YaraAlnaggar
Copy link

I got another error after following the above instruction:

ValueError Traceback (most recent call last)
in ()
19 if x%10==0:
20 print("Epoch[{}], Train_Iterations[{}]--mean_loss:{} ".format(epoch,x,loss))
---> 21 tb.save_value('Train Loss', 'train_loss', global_iter, loss.item())
22 optimizer.zero_grad()
23 loss.backward()

2 frames
/usr/local/lib/python3.6/dist-packages/tensorboardcolab/core.py in save_value(self, graph_name, line_name, epoch, value)
100 else:
101 with self.writer.as_default():
--> 102 tf.summary.scalar(graph_name, value)
103 self.writer.flush()
104

/usr/local/lib/python3.6/dist-packages/tensorboard/plugins/scalar/summary_v2.py in scalar(name, data, step, description)
66 tensor=tf.cast(data, tf.float32),
67 step=step,
---> 68 metadata=summary_metadata,
69 )
70

/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/summary_ops_v2.py in write(tag, tensor, step, metadata, name)
647 step = get_step()
648 if step is None:
--> 649 raise ValueError("No step set via 'step' argument or "
650 "tf.summary.experimental.set_step()")
651 if metadata is None:

ValueError: No step set via 'step' argument or tf.summary.experimental.set_step()

Is this about the version too?

Have met the same error and adding step argument which indicates batch/epoch number to tf.summary.scalar(graph_name, value) solves the issue.
tf.summary.scalar(graph_name, value) to tf.summary.scalar(graph_name, value,step=step)

@pvhdhxd
Copy link

pvhdhxd commented Jun 3, 2021

In the recent version of TensorFlow, you should replace these lines:

summary = tf.Summary()
summary_value = summary.value.add()
summary_value.simple_value = value
summary_value.tag = graph_name

with:

with self.writer.as_default():

tf.summary.scalar(graph_name, value)

self.writer.flush()

Also, replace this line:

self.writer = tf.summary.FileWriter(log_dir)

with:

self.writer = tf.summary.create_file_writer(log_dir)

Dear denabazazian,
I followed to your guidance, however I met an error:

~\AppData\Roaming\Python\Python38\site-packages\keras\callbacks.py in on_epoch_end(self, epoch, logs)
902 #.
903 # Doi self.write to writer
--> 904 with self.writer.as_default():
905 tf.summary.scalar(graph_name, value)
906 self.writer.flush()

AttributeError: 'FileWriter' object has no attribute 'as_default'

I am using python 3.8.5 and tensorflow 2.5.0

Could anyone help me to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants