我目前正在按照这个教程进行学习,到了第4节。当我运行生成TF记录的命令时,generate_tfrecord.py文件返回了一个追溯错误。第一个错误是关于以下代码的:
flags = tf.compat.v1.flagsflags.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()。