繁体   English   中英

AttributeError:模块“tensorflow”没有属性“app”:错误

[英]AttributeError: module 'tensorflow' has no attribute 'app': error

我目前正在关注第 4 节中的本教程。当我运行生成 TF 记录的命令时,它会返回 generate_tfrecord.py 文件的回溯错误。 第一个错误是:

flags = tf.compat.v1.flags
flags.DEFINE_string('csv_input', '', 'Path to the CSV input')
flags.DEFINE_string('image_dir', '', 'Path to the image directory')
flags.DEFINE_string('output_path', '', 'Path to output TFRecord')
FLAGS = flags.FLAGS

我只是通过添加 .compat.v1 行来修复它,因为我使用的是 TF 2.0。

我得到的下一个错误是最后一行;

if __name__ == '__main__':
    tf.app.run()

它返回:

Traceback (most recent call last):
  File "generate_tfrecord.py", line 101, in <module>
    tf.app.run()
AttributeError: module 'tensorflow' has no attribute 'app'

任何帮助将不胜感激! -干杯

在这个 TensorFlow 2 指南https://www.tensorflow.org/guide/effective_tf2 中,它说tf.app已被删除。 要解决,要么卸载 TensorFlow 2.x,然后安装 1.x,要么修改代码使其使用 2.x API。 您应该能够只调用 main 方法而不是 tf.app.run()。

参考: https : //github.com/tensorflow/tensorflow/issues/34431

或者你可以简单地添加import tensorflow.compat.v1 as tf tf.disable_v2_behavior()而不是import tensorflow as tf

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM