wintermouse
wintermouse

Reputation: 11

AttributeError: module 'tensorflow' has no attribute 'value'

I am training pytorch-yolov3 in custom dataset. I prepared all the required txt, data and names files .

while runninng following command:

python3 train.py --model_def config/yolov3.cfg --data_config config/custom.data

I got following error:

Warning: indexing with dtype torch.uint8 is now deprecated, please use a dtype torch.bool instead. (expandTensors at /pytorch/aten/src/ATen/native/IndexingUtils.h:20)
Warning: indexing with dtype torch.uint8 is now deprecated, please use a dtype torch.bool instead. (expandTensors at /pytorch/aten/src/ATen/native/IndexingUtils.h:20)
Traceback (most recent call last):
  File "train.py", line 136, in <module>
    logger.list_of_scalars_summary(tensorboard_log, batches_done)
  File "/home/sudip/torch/PyTorch-YOLOv3/utils/logger.py", line 16, in list_of_scalars_summary
    summary = tf.summary(value=[tf.summary.Value(tag=tag, simple_value=value) for tag, value in tag_value_pairs])
  File "/home/sudip/torch/PyTorch-YOLOv3/utils/logger.py", line 16, in <listcomp>
    summary = tf.summary(value=[tf.summary.Value(tag=tag, simple_value=value) for tag, value in tag_value_pairs])
AttributeError: module 'tensorboard.summary._tf.summary' has no attribute 'Value'

This is logger.py file:

import tensorflow as tf 
class Logger(object):
    def __init__(self, log_dir):
        self.writer = tf.summary.create_file_writer(log_dir)

    def scalar_summary(self, tag, value, step):
        """Log a scalar variable."""
        summary = tf.summary(value=[tf.summary.Value(tag=tag, simple_value=value)])
        self.writer.add_summary(summary, step)

    def list_of_scalars_summary(self, tag_value_pairs, step):
        """Log scalar variables."""
        summary = tf.summary(value=[tf.summary.Value(tag=tag, simple_value=value) for tag, value in tag_value_pairs])
        self.writer.add_summary(summary, step)

Any idea or suggestions to solve this problem?

Any help would be appreciated.

Thank you

Upvotes: 1

Views: 2593

Answers (4)

Abdalwhab Bakheet
Abdalwhab Bakheet

Reputation: 1163

For me this problem was due to the code being in TF 1.x while I have TF 2.x. So just replacing self.tf.Summary with tf.compat.v1.Summary (as dspencer suggested) solved the issue.

Upvotes: 1

Sushil Surana
Sushil Surana

Reputation: 41

Change

summary = tf.summary(value=[tf.summary.Value(tag=tag, simple_value=value)])

To

summary = tf.summary.scalar(tag=tag, simple_value=value)

Upvotes: 1

Xiang Zhao
Xiang Zhao

Reputation: 51

In the recent version of TensorFlow, you should modify logger.py as follows:

import tensorflow as tf


class Logger(object):
    def __init__(self, log_dir):
        """Create a summary writer logging to log_dir."""
        self.writer = tf.summary.create_file_writer(log_dir) 

    def scalar_summary(self, tag, value, step):
        """Log a scalar variable."""
        with self.writer.as_default():
            tf.summary.scalar(tag, value, step=step)
            self.writer.flush()

    def list_of_scalars_summary(self, tag_value_pairs, step):
        """Log scalar variables."""
        with self.writer.as_default():
            for tag, value in tag_value_pairs:
                tf.summary.scalar(tag, value, step=step)
            self.writer.flush()

Upvotes: 0

dspencer
dspencer

Reputation: 4481

After updating your logger.py file to the version actually being called from train.py, the error

AttributeError: module 'tensorboard.summary._tf.summary' has no attribute 'Value'

occurs. This is likely because you are using tensorflow 2.1.0 whereas the logger.py script, from an open source project, uses an earlier version of tensorflow with a different API.

Upvotes: 0

Related Questions