11

I am trying to use the object detection tutorial from tensor flow api. I am using python 3 and tensor flow version 2. But getting the below error.I tried several ways:

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'

can someone help me to run this? code link: https://drive.google.com/drive/u/3/folders/1XHpnr5rsENzOOSzoWNTvRqhEbLKXaenL

6
  • So where is the code that you are getting this error from? Did you install the module using pip?
    – J. Murray
    Oct 13, 2019 at 11:43
  • Thaks Murray for your reply.I have installed all the modules in ananconda using pip install. Its a standard code present in the tesnor flow api documentation .Here it goes:drive.google.com/open?id=1XHpnr5rsENzOOSzoWNTvRqhEbLKXaenL
    – Andy
    Oct 13, 2019 at 11:56
  • You should add your relevant code to the posting, so that its easier for people to view it (as well as be available in the future when other people have similar issues)
    – J. Murray
    Oct 13, 2019 at 12:01
  • I am bit new to Stackoverflow.Yet to know how to upload a code.Thats why I have given the gdrive link.
    – Andy
    Oct 13, 2019 at 12:03
  • Just copy & paste the code within your Question area; that'll do.
    – J. Murray
    Oct 13, 2019 at 13:56

4 Answers 4

15

It's not called that in TensorFlow 2. You might be using a TensorFlow 1 tutorial.

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

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

8

If you have Tensorflow version 2. You can use the next module compatible with the version 1, too.

import tensorflow.compat.v1 as tf
2

I solved this problem by reinstalling tensor using the previous version: sudo pip3 install tensorflow==1.14.0

1

You may optionally downgrade to previous version of tensorflow:

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

otherwise , make if tf.io.gfile and import tf.io

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.