首页 > 解决方案 > AttributeError:模块“tensorflow_core.summary”没有属性“FileWriter”

问题描述

我在使用 Tensorflow v2.1.0 时遇到错误:

AttributeError: module 'tensorflow_core.summary' has no attribute 'FileWriter

我的代码是:

import tensorflow as tf

a = tf.constant(5.0)
b = tf.constant(6.0)

c = a*b

sess = tf.compat.v1.Session()

File_Writer = tf.summary.FileWriter(r"C:\Users\Name\Desktop\TensorFlow\graph", sess.graph)

print(sess.run(c))

输出错误是:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-19-898c56a41b1a> in <module>
      6 sess = tf.compat.v1.Session()
      7 
----> 8 File_Writer = tf.summary.FileWriter(r"C:\Users\Name\Desktop\TensorFlow\graph", sess.graph)
      9 
     10 print(sess.run(c))

AttributeError: module 'tensorflow_core.summary' has no attribute 'FileWriter'

我该怎么做才能修复它?

标签: pythontensorflowtensorflow2.0

解决方案


利用tf.summary.create_file_writer('log_path')


推荐阅读