簡體   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