【问题标题】:Error: Module 'tensorflow' has no attribute 'gfile' error while running tensorflow object detection api tutorial错误:运行 tensorflow 对象检测 api 教程时模块“tensorflow”没有属性“gfile”错误
【发布时间】:2019-10-13 11:31:42
【问题描述】:

我正在尝试使用 tensor flow api 中的对象检测教程。我正在使用 python 3 和张量流版本 2。但出现以下错误。我尝试了几种方法:

File "C:\Aniruddhya\object_detection\object_detection\utils\label_map_util.py", line 137, in load_labelmap
    with tf.gfile.GFile(path, 'r') as fid:

AttributeError: module 'tensorflow' has no attribute 'gfile'

有人可以帮我运行这个吗? 代码链接:https://drive.google.com/drive/u/3/folders/1XHpnr5rsENzOOSzoWNTvRqhEbLKXaenL

【问题讨论】:

  • 那么你从哪里得到这个错误的代码?您是否使用 pip 安装了模块?
  • 感谢您的回复。我已经使用 pip install 安装了 ananconda 中的所有模块。它是 tesnor flow api 文档中的标准代码。这里是:drive.google.com/open?id=1XHpnr5rsENzOOSzoWNTvRqhEbLKXaenL
  • 您应该将相关代码添加到帖子中,以便人们更容易查看(以及将来其他人遇到类似问题时可用)
  • 我对 Stackoverflow 有点陌生。但不知道如何上传代码。这就是我提供 gdrive 链接的原因。
  • 只需将代码复制并粘贴到您的问题区域即可;就可以了。

标签: python-3.x tensorflow


【解决方案1】:

在 TensorFlow 2 中没有这样称呼。您可能正在使用 TensorFlow 1 教程。

版本 1 tf.gfile.GFile https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/io/gfile/GFile

第 2 版 tf.io.gfile.GFile https://www.tensorflow.org/api_docs/python/tf/io/gfile/GFile

【讨论】:

    【解决方案2】:

    如果你有 Tensorflow 版本 2。你也可以使用与版本 1 兼容的下一个模块。

    import tensorflow.compat.v1 as tf
    

    【讨论】:

      【解决方案3】:

      我通过使用以前的版本重新安装张量解决了这个问题:sudo pip3 install tensorflow==1.14.0

      【讨论】:

        【解决方案4】:

        您可以选择降级到以前版本的 tensorflow:

        !pip install tensorflow==1.12.0
        import tensorflow as tf
        print(tf.__version__)
        

        否则,制作 if tf.io.gfile 并导入 tf.io

        【讨论】:

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