Tensorflow框架学习记录–day01–FileWriter使用报错总结
代码:
# 1) 将图写入本地生成events文件
# tf.summary.FileWriter("./tmp/summary",graph=sess.graph)
如果这样写会报以下错,是因为tensorflow版本不兼容的问题
AttributeError: module ‘tensorboard.summary._tf.summary’ has no attribute 'FileWriter’
如果换成create_file_writer就像下面,也会出现报错,原因是没有graph这个模块:
tf.summary.create_file_writer("./tensorborad/summary" ,graph=sess.graph)
通过查阅网上的一些解决办法我发现,事实上,这两种方法都是可以使用的,但由于版本问题如果要使用FileWriter我们必须在compat.v1里使用,而在使用create_file_writer的时候要注意,它是没有graph类型的。
所以最后代码修改如下:
# 1) 将图写入本地生成events文件
# tf.summary.FileWriter("./tmp/summary",graph=sess.graph)
#tf.summary.create_file_writer("./tensorborad/summary" ,graph=sess.graph)
tf.compat.v1.summary.FileWriter("./tmp/summary",graph=sess.graph)
成功生成tmp文件: