tensorflow2.1报no attribute 'Summary' && tf.contrib.summary instead

前后遇到两个错

1、AttributeError: module tensorflow has no attribute 'Summary'

通过将 tf.Summary  换成   tf.compat.v1.Summary,可利用tensorflow 2.1.0接口自动转换工具,将整个项目批量转换

tf_upgrade_v2 \
  --intree my_project/ \
  --outtree my_project_v2/ \
  --reportfile report.txt

替换完成后,遇到如下报错

2、RuntimeError: tf.summary.FileWriter is not compatible with eager execution. Use tf.contrib.summary instead

tensorflow 2.1.0已经舍弃tf.contrib,不能这么改。为了不跟eager execution(tensorflow 2.1.0默认开启)冲突,需在summary代码前面关闭

tf.compat.v1.disable_eager_execution()

吐槽:百度根本找不到这些信息,推荐google

参考网页:

1、 https://www.uedbox.com/post/54776/(google网址)

2、https://github.com/tensorflow/docs/blob/master/site/en/guide/upgrade.ipynb(接口转换)

3、https://github.com/tensorflow/tensorflow/pull/36593(关闭eager execution)

 

 

 

 

  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据您提供的引用内容,您遇到了一个名为"module 'tensorflow' has no attribute 'summary.histogram'"的错误。这个错误通常是由于TensorFlow版本不兼容或导入模块错误引起的。下面是两种可能的解决方法: 1. 检查TensorFlow版本:首先,确保您正在使用的是兼容的TensorFlow版本。在较新的TensorFlow版本中,`summary.histogram`已经被弃用。您可以尝试使用`tf.compat.v1.summary.histogram`来替代。如果您的TensorFlow版本较旧,您可以尝试升级到最新版本。 2. 检查模块导入:另一个可能的原因是导入模块错误。请确保您正确导入了所需的模块。例如,正确导入`summary.histogram`应该是`from tensorflow.summary import histogram`。 下面是一个示例代码,演示了如何使用`tf.compat.v1.summary.histogram`来创建直方图: ```python import tensorflow as tf # 创建一个TensorFlow会话 sess = tf.compat.v1.Session() # 创建一个变量 x = tf.Variable([1, 2, 3], dtype=tf.float32) # 使用tf.compat.v1.summary.histogram创建直方图 histogram_summary = tf.compat.v1.summary.histogram("histogram", x) # 初始化变量并运行会话 sess.run(tf.compat.v1.global_variables_initializer()) # 创建一个写入器并将直方图写入事件文件 writer = tf.compat.v1.summary.FileWriter("logs/") writer.add_summary(sess.run(histogram_summary)) writer.close() ``` 请注意,上述代码中使用了`tf.compat.v1.summary.histogram`来创建直方图,并且使用`tf.compat.v1.summary.FileWriter`将直方图写入事件文件。您可以根据自己的需求进行修改和调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值