Running the following code
AttributeError: module'tensorflow_core.summary'has no attribute'FileWriter'
appears.I wonder why
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
a=tf.constant(10,name='10'
b=tf.constant(20,name='20')
c=tf.constant(30,name='30')
add_op=tf.add(a,b,name='mul')
mul_op=tf.multiple(add_op,c,name='mul')
sess=tf.compat.v1.Session()
res=sess.run(mul_op)
print(res)
tf.summary.FileWriter('./logs', sess.graph)`
The Tensorflow version is 2.
python python3 tensorflow
tf.summary.FileWrite
was present in Tensorflow 1.x is removed in Tensorflow 2.0, and instead tf.summary.create_file_writer
.The questioner's program seems to have written in Tensorflow 1st style, so you can avoid it by using tf.compat.v1.summary
as a temporary solution.
tf.compat.v1.summary.FileWriter('./logs', sess.graph)
If you want to write more in Tensorflow 2nd style, you need to be aware of eager execution and rewrite it as a whole.For more information, see the document "Effective TensorFlow2" or "Migrating tf.summary usage to TF 2.0".
© 2024 OneMinuteCode. All rights reserved.