Error: Module 'tensorflow' has no attribute 'gfile' error while running tensorflow object detection api tutorial

Viewed 26305

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

4 Answers

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

import tensorflow.compat.v1 as tf

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

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

Related