Error: Module 'tensorflow' has no attribute 'gfile' error while running tensorflow object detection api tutorial - python-3.x

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

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

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

why YOLO v3 Keras buggy?

I am running this colab from Roboflow: https://colab.research.google.com/drive/1ByRi9d6_Yzu0nrEKArmLMLuMaZjYfygO#scrollTo=WgHANbxqWJPa
The code should be as-is, but i get errors at the end...
I suspect a TF versioning issue, but how do i know which version of TF i should install instead?
It should use TF1:
%tensorflow_version 1.x
But
!python -c 'import keras;
print(keras.version)'
returns: Using TensorFlow backend. 2.2.4
What am i doing wrong here? Unistall TF & reinstall which version?
Thanx
Fred

AttributeError: module 'tensorflow_core.keras.layers.experimental.preprocessing' has no attribute 'RandomFlip'

I use Tensorflow 2.1.0
In this code
data_augmentation = tf.keras.Sequential([
tf.keras.layers.experimental.preprocessing.RandomFlip('horizontal'),
tf.keras.layers.experimental.preprocessing.RandomRotation(0.3)
])
I find this error:
AttributeError: module 'tensorflow_core.keras.layers.experimental.preprocessing' has no attribute 'RandomFlip'
So how can I change it without changing version of tensorflow
To work your code as expected, firstly Tensorflow has to be upgrade to the latest version
! pip install tensorflow --upgrade
If you are looking for solution in TF 2.1.0, then there are two options are available
First solution: tf.image.random_flip_left_right ( horizontal flip)
tf.image.random_flip_left_right(
image, seed=None)
Second solution: tf.keras.preprocessing.image.ImageDataGenerator
tf.keras.preprocessing.image.ImageDataGenerator(
rotation_range=30, horizontal_flip=True)
! pip install tensorflow --upgrade --user
--user option can help you without the permission problem
Add this line to the importing section (of course after import tensorflow as tf)
tf.config.experimental_run_functions_eagerly(True)
Almost any tf.keras.layers.experimental.preprocessing.SomeClass in the listed classes here, should work.
But need to do sanity check with plotting results.

Unable to import sklearn and statsmodels from Anaconda from windows 10 pro

I'm relatively new to python, so please excuse my ignorance on what could be a very easy fix. I am running python 3.6 through the Rodeo IDE, and it has been great, as it is similar to R-Studio (which I am very familiar with). As an aspiring data scientist, I am trying to learn how to fit regression and time series models to data, and all of the tutorials that I have found all say that I need various packages, all of which should be included in the Anaconda library. After downloading and re-downloading Python, Rodeo, and Anaconda, and trying various online fixes, I have been unable to successfully load the scikit-learn and the statsmodels modules.
#here is everything I have tried.
#using pip
! pip install 'statsmodels'
! pip install 'scikit-learn'
! pip install 'sklearn'
I don't get any errors here, and to be honest I'm kind of confused as to what this actually does, but I have seen many people online always suggest that this is a big problem when trying to import modules.
#using import
import sklearn
import statsmodels
from sklearn import datasets
import statsmodels.api as sm
all of the above give me the same error:
import statsmodels.api as sm
ImportError: No module named 'statsmodels'
ImportError: Traceback (most recent call last)
ipython-input-184-6030a6549dc0 in module()
----> 1 import statsmodels.api as sm
ImportError: No module named 'statsmodels'
I have tried to set my working directory to the Anaconda 3 file that has all of the packages and rerunning the above code with no success.
I'm thinking that the most likely problem has to do with my inexperience, and it is probably a simple fix. Is it possible that the IDE is bad or anaconda just doesn't like me?
So keeping all of the above in mind, the question is, how can I import these modules successfully so that I can access their functionality?
Option 1:
After installing packages with pip, try closing and reopening your IDE/Jupyter Notebook and try again.
This is a known bug that Jake VanderPlas outlined here
Option 2:
Don't put quotations around your pip messages.
!pip install -U statsmodels
!pip install scikit-learn
Option 3:
Also are you using Anaconda? If you are, you should already have scikit-learn. If you are trying inside Rodeo, I think you need to set your path inside Rodeo. Open Rodeo and set the Python Path to your fresh anaconda. See here

keras import fails "no module named contrib.ctc"

On OSX El CApitan 10.11.6 I've installed theano & tensorflow fine. But the keras install is not happy as seen from the trace below. I've seen this reported on github issues but with no solution there, only a suggestion to post here on SO.
>>>import theano
>>>
>>> import tensorflow
>>>
>>> import keras
File "/Users/petercotton/anaconda2/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 6, in <module>
import tensorflow.contrib.ctc as ctc
ImportError: No module named contrib.ctc`
Suggestions appreciated.
This is a problem with Keras, not TensorFlow and a known issue.
A workaround is mentioned here but that would mean that you have to modify Keras code (keras/backend/tensorflow_backend.py).
Luckily, it seems that this issue is fixed in the master branch of Keras.

Can't import GMM function from sckits.learn

I'm getting error ImportError: No module named gmm when I'm using from scikits.learn.gmm import GMM..
I installed scikits using windows installer and no error..
How I can fix it?
That link is very old, the module name was renamed to sklearn as you have installed version 0.16.1 you should be using
from sklearn.mixture import GMM
as per the docs

Resources