【问题标题】:AttributeError: module 'tensorflow' has no attribute 'value'AttributeError:模块“张量流”没有属性“值”
【发布时间】:2020-03-10 09:28:18
【问题描述】:

我正在自定义数据集中训练 pytorch-yolov3。我准备了所有必需的 txt、数据和名称文件。

在运行以下命令时:

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

我收到以下错误:

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'

这是logger.py文件:

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)

有解决这个问题的想法或建议吗?

任何帮助将不胜感激。

谢谢

【问题讨论】:

  • 您确定您发布了正确的文件吗?错误是抱怨您在list_of_scalars_summary 中调用tf.value,但提供的代码正确调用tf.summary.Value
  • 对不起,现在我添加了从开源获得的正确文件。仍然显示相同的错误。

标签: python tensorflow deep-learning pytorch yolo


【解决方案1】:

将您的logger.py 文件更新为实际从train.py 调用的版本后,出现错误

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

发生。这可能是因为您使用的是 tensorflow 2.1.0,而来自开源项目的 logger.py 脚本使用具有不同 API 的早期版本的 tensorflow。

【讨论】:

  • 我编辑了它并更新了我的问题。仍然给我同样的错误。有办法解决这个问题吗?
  • 您使用的是哪个版本的 Tensorflow?从documentation 开始,标量摘要将使用tf.summary.scalar 编写。
  • 我使用的是 2.1.0。我还尝试用tf.compat.v1.summary 替换tf.summary,但没有解决我的问题。
  • 是这样想的。如果你说logger.py 文件来自一个开源项目,我希望它被设计为使用早期版本的 Tensorflow。您可能想尝试更新 2.1.0 的脚本。
  • 您可以使用您尝试解决问题所采取的步骤来更新您的问题,例如使用tf.compat.v1.summary 以及为什么它们不起作用。
【解决方案2】:

在最新版本的 TensorFlow 中,你应该修改 logger.py 如下:

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()

【讨论】:

    【解决方案3】:

    改变

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

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

    【讨论】:

      猜你喜欢
      • 2020-06-09
      • 2018-09-25
      • 2020-01-04
      • 2017-12-25
      • 2018-04-01
      • 2020-04-29
      • 2018-04-29
      • 2019-12-28
      • 2020-06-15
      相关资源
      最近更新 更多