13

我在Google Colab上使用tensorflow 2.0训练了一个简单的 mnist 模型,并将其保存为.json格式。单击此处查看我编写代码的 Colab Notebook。然后在运行命令

!simple_tensorflow_serving --model_base_path="/" --model_platform="tensorflow"

它显示错误 AttributeError: module 'tensorflow' has no attribute 'gfile'

simple_tensorflow_serving有助于轻松地将经过训练的 tensorflow 模型部署到生产中。

我正在使用的版本:

(1) TensorFlow - 2.0

(2) simple_tensorflow_serving - 0.6.4

先感谢您 :)

4

4 回答 4

23

在 2.0 中,tf.gfile.* 被 tf.io.gfile.* 取代。

当我收到错误时:

  File "/Users/MRJ/anaconda3/envs/python37-tf2.1/lib/python3.7/
site-packages/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'

1.找到第137label_map_util.py行。

2.替换tf.gfile.GFiletf.io.gfile.GFile

它对我有用。

张量流问题 #31315

于 2020-05-12T09:18:14.373 回答
21

简单的 Tensorflow Serving 还没有为 Tensorflow 2.0 做好准备,因为它使用的是旧的 API。在 TensorFlow 2.0 中,该gfile包已移至tf.io.

然后,您必须使用 Simple Tensorflow Serving 将您的 Tensorflow 实例降级到 TF 1.13

于 2019-04-09T14:32:39.517 回答
2

相反,尝试

tf.io.gfile.GFile(
    name, mode='r'
)

即“.io”将解决您的所有问题,而不是降级您的 tf

于 2021-12-05T16:23:25.637 回答
0

tf.gfile.GFile更改为tf.io.gfile.GFile 它适用于此实例,但不适用于所有其他文件,例如tf.io.gfile.FastGFile抛出错误,提示“ AttributeError: module 'tensorflow._api.v2.io. gfile'没有属性'FastGFile' ”。我希望它能节省你的时间。

于 2021-11-20T23:45:10.577 回答