【问题标题】:Custom object-detection AttributeError: module 'tensorflow' has no attribute 'app'自定义对象检测 AttributeError:模块 'tensorflow' 没有属性 'app'
【发布时间】:2019-10-12 05:10:41
【问题描述】:
我正在使用 tensorflow 进行自定义对象检测 this project。
当我尝试使用以下命令为火车图像创建 TF 记录时:
python generate_tfrecord.py
--csv_input=images\train_labels.csv
--image_dir=images\train
--output_path=train.record
我收到以下错误:
“generate_tfrecord.py”,第 102 行,在 tf.app.run()
AttributeError: 模块 'tensorflow' 没有属性 'app'
怎么了?
【问题讨论】:
标签:
python-3.x
tensorflow
object-detection
【解决方案1】:
我遇到了同样的问题,
您可以通过更改 generate_tfrecords.py 文件来解决此问题
第 45 行:将 tf.gfile.GFile(os.path.join(path, '{}'.format(group.filename)), 'rb') 替换为 fid:
作为
tftf.compat.v1.gfile.GFile(os.path.join(path, '{}'.format(group.filename)), 'rb') 作为fid:
第 23 行:flags = tf.app.flags as tf.compat.v1.flags
第 86 行: writer = writer = tf.python_io.TFRecordWriter(FLAGS.output_path) as tf.compat.v1.python_io.TFRecordWriter(FLAGS.output_path)
和
第 100 行:tf.app.run() as tf.compat.v1.app.run()
基本上有一些方法是根据 Tensorflow 1.0 版构建的,因此您可以使用 tf.compat.v1 以便针对这些引发错误的特定方法修改您的代码。