[英]AttributeError: module 'tensorflow' has no attribute 'gfile' even when changed tf.gfile.* to tf.io.gfile.* in line 131
!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'}
running which gives me the error:运行这给了我错误:
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", 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'
I have followed a recommended me to change tf.gfile.* to tf.io.gfile.* in line 111, executing which I'm getting the above error.我已按照建议在第 111 行将 tf.gfile.* 更改为 tf.io.gfile.* ,执行该操作时出现上述错误。
MacOS Catalina 10.15.3. MacOS Catalina 10.15.3。 Google Collab (Online)谷歌协作(在线)
Thank you for your help!谢谢您的帮助!
Since in Tensorflow 2 Gfile is moved under tf.io.gfile you can go to label_map_util.py
file and replace the name from tf.gfile.GFile
to tf.io.gfile.GFile
. Since in Tensorflow 2 Gfile is moved under tf.io.gfile you can go to label_map_util.py
file and replace the name from tf.gfile.GFile
to tf.io.gfile.GFile
.
If you have already tried that option then you can downgrade the version of Tensorflow
to 1.x
in colab
using below magic command before importing Tensorflow
.如果您已经尝试过该选项,那么您可以在导入Tensorflow
之前使用以下魔法命令在Tensorflow
colab
1.x
版本降级为 1.x。
%tensorflow_version 1.x
import tensorflow as tf
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.