python - 属性错误: module 'tensorflow' has no attribute 'app' : error

标签 python tensorflow machine-learning artificial-intelligence

我目前正在关注这个tutorial在第 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

关于python - 属性错误: module 'tensorflow' has no attribute 'app' : error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59272234/

相关文章:

python - 为什么 __init__() 缺少参数?

python - 使用 Tensorflow 的目标数组形状与预期输出不同

tensorflow - keras.model.predict 引发 ValueError : Error when checking input

machine-learning - 神经网络 - 为什么有这么多学习规则?

python - 修改 python 可调用函数,使其调用 before() ,实际函数然后调用 after()

python - 如何在 Ajax 验证中使用 WTForms?

python - Polars API 注册和类型检查器

machine-learning - TensorFlow:向预训练的 Inception 模型添加类并输出完整图像层次结构

python - Tensorflow_core._api.v2.train没有属性 'slice_input_producer'

python - 是否使用 Caffe 还是 Theano 进行 Moore-Penrose 伪逆?