首页 > 解决方案 > tf.app.run(main=main, argv=[sys.argv[0]] + unparsed) AttributeError: module 'tensorflow' has no attribute 'app'

问题描述

我正在尝试遵循用于 ML 图像分类的诗人指南的张量流。到目前为止,我无法重新训练我的数据集,因为我遇到了以下错误:

Traceback (most recent call last):
 File "C:\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
   "__main__", mod_spec)
 File "C:\Python\Python37\lib\runpy.py", line 85, in _run_code
   exec(code, run_globals)
 File "C:\Users\I352778\tensorflow-for-poets-2\tensorflow-for-poets-2\scripts\retrain.py", line 1326, in <module>
   tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
AttributeError: module 'tensorflow' has no attribute 'app' 

现在我明白这是由于运行 v1 功能而导致的问题,我正在使用 Tensorflow v2,但仍然不确定我能否解决这个问题。我使用的训练代码如下:

C:\Users\I352778\tensorflow-for-poets-2\tensorflow-for-poets-2>python -m scripts.retrain ^
More?   --bottleneck_dir=tf_files/bottlenecks ^
More?   --model_dir=tf_files/models/%ARCHITECTURE% ^
More?   --summaries_dir=tf_files/training_summaries/%ARCHITECTURE% ^
More?   --output_graph=tf_files/retrained_graph.pb ^
More?   --output_labels=tf_files/retrained_labels.txt ^
More?   --architecture=%ARCHITECTURE% ^
More?   --image_dir=tf_files/C:\Users\I352778\Pictures\dataset-resized 

我应该如何或输入什么代码来克服我试图实现 v1 功能的事实

标签: pythonwindowstensorflowmachine-learning

解决方案


你能用这个导入吗import tensorflow.compat.v1 as tf


推荐阅读