简体   繁体   English

AttributeError:即使在第 131 行将 tf.gfile.* 更改为 tf.io.gfile.*,模块“tensorflow”也没有属性“gfile”

[英]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.

相关问题 AttributeError:模块&#39;tensorflow&#39;没有属性&#39;gfile&#39;Tensorflow 2.8.2 - AttributeError: module 'tensorflow' has no attribute 'gfile' Tensorflow 2.8.2 为什么 Tensorflow 即使在我更改文件后也没有属性“gfile”? - Why Tensorflow has no attribute 'gfile' even after I changed the file? 使用 tf.gfile.GFile 时 Python 退出 - Python exiting when using tf.gfile.GFile TensorFlow2 替代 tf.io.gfile.Open()? - TensorFlow2 alternative to tf.io.gfile.Open()? tf.gfile 在 TensorFlow 中有什么作用? - What does tf.gfile do in TensorFlow? TensorFlow2.0.0 Alpha-模块'tensorflow'没有属性'gfile' - TensorFlow2.0.0 Alpha- module 'tensorflow' has no attribute 'gfile' 仍然得到 AttributeError: module &#39;tensorflow&#39; has no attribute &#39;gfile&#39; 在尝试了每件事来解决这个问题之后 - Still getting AttributeError: module 'tensorflow' has no attribute 'gfile' after trying every thing to solve that tensorflow:“ tf.gfile.GFile”中带有“&#39;utf-8&#39;编解码器的错误”无法解码...” - tensorflow: Something wrong in “ tf.gfile.GFile” with “'utf-8' codec can't decode…” 关于读取图像时,tf.gfile.GFile()。read()和cv2.imread()有什么区别 - what's the difference between tf.gfile.GFile().read() and cv2.imread() when it is about reading images tf.gfile.GFile() 中使用的编码是什么? - What is the encoding getting used in tf.gfile.GFile()?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM