错误:运行 tensorflow 对象检测 api 教程时,模块“tensorflow”没有属性“gfile”错误

Ani*_*tta 9 python-3.x tensorflow

我正在尝试使用来自张量流 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'
Run Code Online (Sandbox Code Playgroud)

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

use*_*499 12

在 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


小智 7

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

import tensorflow.compat.v1 as tf
Run Code Online (Sandbox Code Playgroud)