【问题标题】:AttributeError: module 'tensorflow' has no attribute 'gfile' even when changed tf.gfile.* to tf.io.gfile.* in line 131AttributeError:即使在第 131 行将 tf.gfile.* 更改为 tf.io.gfile.*,模块“tensorflow”也没有属性“gfile”
【发布时间】:2021-01-08 11:28:15
【问题描述】:
!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", 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'

我已按照建议在第 111 行将 tf.gfile.* 更改为 tf.io.gfile.*,执行时出现上述错误。

MacOS Catalina 10.15.3。 Google 协作(在线)

感谢您的帮助!

【问题讨论】:

    标签: python tensorflow tensorflow2.0 tfrecord


    【解决方案1】:

    由于在 Tensorflow 2 中 Gfile 移动到 tf.io.gfile 下,您可以转到 label_map_util.py 文件并将名称从 tf.gfile.GFile 替换为 tf.io.gfile.GFile
    如果您已经尝试过该选项,那么您可以在导入 Tensorflow 之前使用以下魔法命令将 Tensorflow 中的 1.x 版本降级为 1.x

    %tensorflow_version 1.x
    import tensorflow as tf
    

    【讨论】:

      猜你喜欢
      • 2020-10-04
      • 2019-08-30
      • 2021-06-16
      • 2021-06-17
      • 1970-01-01
      • 2020-04-29
      • 2017-04-08
      • 2020-02-04
      • 2020-02-12
      相关资源
      最近更新 更多