我收到了这个错误,尽管我到处都提到
file_writer = tf.summary.FileWriter('/path/to/logs', sess.graph)
是this和this的正确实现。
这是错误:
回溯(最近一次调用最后一次):文件“tfvgg.py”,第 304 行,位于 writer = tf.summary.FileWriter("/tmp/tfvgg", sess.graph) AttributeError: 模块 'tensorflow.python.summary.summary' 没有 属性“文件写入器”
这是我正在使用的代码:
# init
sess = tf.Session()
writer = tf.summary.FileWriter("/tmp/tfvgg", sess.graph)
init = tf.initialize_all_variables()
sess.run(init)
使用
FileWriter
的正确方法是否与其他 summary
方法一样发生了变化?
为了以后遇到相同情况的人参考,将
tf.summary.FileWriter()
更改为 tf.train.SummaryWriter()
解决了这个问题,并允许在 Tensorboard 中进行图形可视化。正如我所想,似乎 FileWriter
可能已被弃用(尽管在 IDE 中搜索 tf
方法时它仍然奇怪地出现)
如果您使用的是 tesorflow 2.0.0 版本,请使用
writer = tf.summary.create_file_writer("/tmp/tfvgg")
而不是
writer = tf.summary.FileWriter("/tmp/tfvgg", sess.graph)
。
如果您从 tf1.x 升级到 tf2.x
更好地使用
writer = tf.compat.v1.summary.create_file_writer("/tmp/tfvgg", sess.graph)
否则,代码的其他部分也可能会引发错误。