Attributeerror: Module 'Tensorflow' Has No Attribute 'Gfile'

I trained a simple mnist model with tensorflow 2.0 on Google Colab and saved it in the .json format. Click here to check out the Colab Notebook where I've written the code. Then on running the command

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

It is showing the error AttributeError: module 'tensorflow' has no attribute 'gfile'

simple_tensorflow_serving helps in easily deploying trained tensorflow model into production.

Versions I'm using:

(1) TensorFlow - 2.0

(2) simple_tensorflow_serving - 0.6.4

Thank you in advance :)

1

4 Answers

In 2.0, tf.gfile.* is replaced by tf.io.gfile.*.

when I get error:

  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.Find label_map_util.py line 137.

2.Replace tf.gfile.GFile to tf.io.gfile.GFile

It's worked for me.

tensorflow issue #31315

2

Simple Tensorflow Serving is not ready for Tensorflow 2.0, since it is using the old API. In Tensorflow 2.0 the gfile package has been moved into tf.io.

Then, you have to downgrade your Tensorflow instance to TF 1.13 use Simple Tensorflow Serving

3

Instead, try

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

i.e ".io" will solve your all problems instead of downgrading your tf

change tf.gfile.GFile to tf.io.gfile.GFile it works for this instance but not for all other files example tf.io.gfile.FastGFile throws an error saying"AttributeError: module 'tensorflow._api.v2.io.gfile' has no attribute 'FastGFile'". I hope it save you time.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest