如何解决AttributeError: 即使在第 131 行将 tf.gfile.* 更改为 tf.io.gfile.* 时,模块“tensorflow”也没有属性“gfile”
!python {'/generate_tfrecord.py'} -x {'/content/Training'} -l {'/label_map.pbtxt'} -o {ANNOTATION_PATH + '/train.record'}
!python {'/generate_tfrecord.py'} -x{'/content/Testing'} -l {'/label_map.pbtxt'} -o {ANNOTATION_PATH + '/test.record'}
运行这给了我错误:
Traceback (most recent call last):
File "/generate_tfrecord.py",line 61,in <module>
label_map = label_map_util.load_labelmap(args.labels_path)
File "/usr/local/lib/python3.6/dist-packages/object_detection/utils/label_map_util.py",line 132,in load_labelmap
with tf.gfile.GFile(path,'r') as fid:
AttributeError: module 'tensorflow' has no attribute 'gfile'
Traceback (most recent call last):
File "/generate_tfrecord.py",'r') as fid:
AttributeError: module 'tensorflow' has no attribute 'gfile'
我已按照建议将第 111 行中的 tf.gfile.* 更改为 tf.io.gfile.*,执行该操作时出现上述错误。
MacOS Catalina 10.15.3。 Google 协作(在线)
感谢您的帮助!
解决方法
由于在 Tensorflow 2 Gfile 移动到 tf.io.gfile 下,您可以转到 label_map_util.py
文件并将名称从 tf.gfile.GFile
替换为 tf.io.gfile.GFile
。
如果您已经尝试过该选项,那么您可以在导入 Tensorflow
之前使用以下魔术命令将 1.x
中的 colab
版本降级为 Tensorflow
。
%tensorflow_version 1.x
import tensorflow as tf
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。