no module named tensorflow.contrib - python

I have this problem when I import tensorflow.contrib.slim
import tensorflow.contrib.slim as slim
i get this error message
Traceback (most recent call last):
File "/home/toshiba/PFE/DocFace-master/src/tflib.py", line 28, in <module>
import tensorflow.contrib.slim as slim
ModuleNotFoundError: No module named 'tensorflow.contrib'
tensorflow is correctly installed and i found some solutions that said that the file name is tensorflow so it causes the problem but that is not the case in here

You probably have TensorFlow version 2.* installed, but tf.contrib.slim is TensorFlow 1.15 code. You can check here how to migrate your existing code to tensorflow 2.*.
If you instead want to keep your code, you can downgrade to TensorFlow by typing pip install tensorflow==1.15 into your command-line to downgrade to TensorFlow 1.15.

tf.contrib is not supported in TensorFlow 2.x, but you can exploit TensorFlow-Slim avoiding to downgrade TensorFlow.
You have to install TensforFlow-Slim as pip install --upgrade tf_slim and then substitute import tensorflow.contrib.slim as slim in your code with import tf_slim as slim

Related

realtime object detection No module named 'tensorflow.compat.v1'

I am following a Real time object detection on https://automaticaddison.com/real-time-object-recognition-using-a-webcam-and-deep-learning/#top and I have hit a road block I followed all the instructions and checked for any errors but still got this error
(I am using windows)
Traceback (most recent call last): File "object_detection_test.py",
line 15, in <module>
from utils import label_map_util File "C:\Users\1rock\Documents\TensorFlow\models\research\object_detection\utils\label_map_util.py",
line 27, in <module>
import tensorflow.compat.v1 as tf ModuleNotFoundError: No module named 'tensorflow.compat.v1'
I used pip install --ignore-installed --upgrade tensorflow==1.9 just what the link above said and whilst running I got these packages and their versions and an error hope it would be relevant to the question
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
ipywidgets 7.6.0 requires jupyterlab-widgets>=1.0.0, which is not installed.
Successfully installed absl-py-0.11.0 astor-0.8.1 gast-0.4.0 grpcio-1.34.0 importlib-metadata-3.3.0 markdown-3.3.3 numpy-1.19.4 protobuf-3.14.0 setuptools-51.0.0.post20201207 six-1.15.0 tensorboard-1.9.0 tensorflow-1.9.0 termcolor-1.1.0 typing-extensions-3.7.4.3 werkzeug-1.0.1 wheel-0.36.2 zipp-3.4.0
I used pip install --ignore-installed --upgrade tensorflow==1.9
line 27, in
import tensorflow.compat.v1 as tf ModuleNotFoundError: No module named 'tensorflow.compat.v1'
TF 1.9 and earlier do not have compat module. To use it you need TF 1.10+. Its better to use conda install everywhere possible with conda virtual enviroment.
Also since you are using tensorflow models make sure you has corresponding version of repository, for example latest TF1.x version located here

Failed to load the native TensorFlow runtime.?

I am trying to import tensorflow but every time i do import tensorflow i get this annoying error it says
"Failed to load the native TensorFlow runtime." i have looked my error into
https://www.tensorflow.org/install/errors but i did not find my answer yet i probably missed it But....
My error:
ImportError: Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed: The specified module could not be found.
I used pip install tensorflow also if i do pip install tensorflow in my console i get "Requirement already satisfied: tensorflow in c:\programdata\anaconda3\lib\site-packages (2.3.1)"
but when i do import tensorflow i get my Import Error
also my pip version is 20.2.4
you are using Anaconda it will support
Tensorflow == 2.1.0
create a new environment for tensorflow
conda create -n tf tensorflow
activate tf
I figured how to do it for me i just needed to do:
pip install tensorflow==1.15

protobuf successfully installed but cannot import

I installed tensorflow 1.13.1 and protobuf 3.6.1. successfully. But when I tried to import protobuf 3.6.1, an error occurs. I used python 3.6.0
Error is given below:
import protobuf
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'protobuf'
because of this i cannot import tensorflow
As discussed in comments, working with pip to get tensorflow running on this particular system turned out to be complicated. Instead, we went with Anaconda installation:
conda create -n yourenvname tensorflow
To import protobuf:
import google.protobuf

“ImportError: No module named core_rnn” When I use tensorflow and use the tflearn?

the program can be downloaded from:
The error:
Traceback (most recent call last):
File "/home/imatrix/download/ chrisruk/cnn-master/train_cnn.py", line 7, in import tflearn
File "/usr/local/lib/python2.7/dist-packages/tflearn/init.py",
line 21, in from .layers import normalization File
"/usr/local/lib/python2.7/dist-packages/tflearn/layers/init.py",
line 10, in from .recurrent import lstm, gru, simple_rnn,
bidirectional_rnn, \ File
"/usr/local/lib/python2.7/dist-packages/tflearn/layers/recurrent.py",
line 8, in ImportError: No module named core_rnn
Assuming Tf 0.12 onwards these have been moved to:
tf.contrib.rnn [followed by whichever core_rnn. you need ]
Most probably the error is because of incompatible versions of tflearn and tensorflow. (Probably you have updated tflearn, but didn't update tensorflow).
Try remove tensorflow and tflearn packages and install the latest version:
pip uninstall tflearn
pip uninstall tensorflow
pip install -I tensorflow
pip install -I tflearn
Or if you don't want to use tensorflow v1.0 then install older versions of both packages:
pip uninstall tflearn
pip uninstall tensorflow
pip install -I tensorflow==0.12.1
pip install -I tflearn==0.2.1

importerror no module named tensorflow windows

import tensorflow as tf Traceback (most recent call last):
File "<ipython-input-5-41389fad42b5>", line 1, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
I am getting the following error after installation of tensorflow in anaconda using windows. I have followed the tensorflow installation steps
At first it was running properly but when i tried to uninstall and reinstall tensorflow, this error pops up. I tried uninstalling Anaconda itself and reinstalling but was of no help. Tensorflow is getting installed but when i try the import step it shows the above error.
Solved: Python 3.6 is incompatible with tensorflow and had to create tensorflow environment for python 3.5.
conda create -n tensorflow python=3.5 anaconda
Activated it in command prompt and launched spyder from it which changed my python version to 3.5. Now was able to import tensorflow properly.
If you installed tensorflow using Anaconda inside an Anaconda environment, you will need to activate this environment. Only then can you import tensorflow.

Categories