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

Andy
  • 405
  • 1
  • 5
  • 16
  • So where is the code that you are getting this error from? Did you install the module using pip? – J. Murray Oct 13 '19 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:https://drive.google.com/open?id=1XHpnr5rsENzOOSzoWNTvRqhEbLKXaenL – Andy Oct 13 '19 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 '19 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 '19 at 12:03
  • Just copy & paste the code within your Question area; that'll do. – J. Murray Oct 13 '19 at 13:56
  • This worked for me, check it out https://stackoverflow.com/a/58222195/9895080 – Jaffer Al-Delphi Dec 08 '20 at 08:54

4 Answers4

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

user1318499
  • 1,327
  • 11
  • 33
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
matthias_h
  • 11,356
  • 9
  • 22
  • 40
Yerry Aguirre
  • 101
  • 1
  • 3
2

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

Tim Uzlov
  • 181
  • 2
  • 6
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

Shaina Raza
  • 1,474
  • 17
  • 12