Daromogo
Daromogo

Reputation: 651

Why can I not import Tensorflow.contrib I get an error of No module named 'tensorflow.python.saved

Hi I just installed Tensorflow on my Mac and I want to use tf.contrib.slim but when I use it I get this

import tensorflow as tf

slim = tf.contrib.slim

Error:

File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_estimator/python/estimator/export/export_lib.py", line 25, in from tensorflow.python.saved_model.model_utils import build_all_signature_defs ModuleNotFoundError: No module named 'tensorflow.python.saved_model.model_utils'

I don't know what to do, please help me

I use Tensorflow.13.1 and python 3.7

Upvotes: 65

Views: 260986

Answers (15)

Alireza Parchami
Alireza Parchami

Reputation: 21

As suggested in the Migration Guide from TensorFlow 1.x to TensorFlow 2 page, install TF-Slim, available on Google-research Github page and then use

import tf_slim as slim

instead of tf.contrib.layers

Upvotes: 2

iso42
iso42

Reputation: 21

Contrib has been taken from tensorflow in 2.x version we have to switch to an older version.

If you are using in collab you can directly switch from 2.x version to 1.x with this command

%tensorflow_version 1.x

Doing this solved the problem.

Apart from collab you can just uninstall your current version and install 1.15.2 with the following commands.

pip uninstall tensorflow

pip install tensorflow==1.15.2

Upvotes: 1

Omri Algazi
Omri Algazi

Reputation: 11

Editing the code may be a bit tedious but if you are willing to make the effort - just add this in all tensorflow links

compat.v1

so tf.assign -> tf.compat.v1.assign

etc

Upvotes: 1

sakeesh
sakeesh

Reputation: 1039

I think majority of solution is suggesting to downgrade tensorflow version. At first place why does TF 2 does not support WALS factorization?One blog suggest its because official recommendataion is NCF Matrix Factorization in tensorflow 2.0 using WALS Method.

Upvotes: 0

Zain
Zain

Reputation: 416

As mentioned in the answers, tensorflow.contrib is not supported in tensorflow 2. I fixed the problem with creating an environment in conda with its python version set to 3.7 and setting tensorflow version to 1.14. You may face a one or two bugs related to package compatibility but eventually it'll work.

Upvotes: 1

Amit Sonawane
Amit Sonawane

Reputation: 11

I solved this using following steps:

First i do check current version of my tf using

import tensorflow
print(tensorflow.__version__)
2.5.0

Then contrib is part of older version of tensorflow as it removed from 2.X.

so we need to use tf version 1.X

that will be done using following snippet

%tensorflow_version 1.x
import tensorflow
print(tensorflow.__version__)

and you will get output

**TensorFlow 1.x selected.
1.15.2**

now you can use

from tensorflow.contrib import seq2seq
from tensorflow.contrib.rnn import DropoutWrapper

Upvotes: 1

Sudhanshu
Sudhanshu

Reputation: 239

first:

pip install --upgrade tf_slim

then:

import tf_slim as slim

Upvotes: 23

Siwei Luo
Siwei Luo

Reputation: 337

If the following command doesn't work

pip3 install tensorflow==1.14.0 

then we can try the following command

pip3 install https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.14.0-py3-none-any.whl

Upvotes: 14

zcseho
zcseho

Reputation: 11

Starting from tensorflow 13.1 there's no contrib. You can use without it slim = tf.slim or you can install pip install tensorflow==1.13 and use it

Upvotes: -5

Mayur Deshmukh
Mayur Deshmukh

Reputation: 392

tf.contrib has moved out of TF starting TF 2.0 alpha.

You can upgrade your TF 1.x code to TF 2.x using the tf_upgrade_v2 script https://www.tensorflow.org/alpha/guide/upgrade

Upvotes: 3

Ganesh Krishnan
Ganesh Krishnan

Reputation: 7395

Currently the default install of tensorflow is 2.x while your code is for 1.x. The contrib module has been removed from tf 2.x. Check the warnings:

"The TensorFlow contrib module will not be included in TensorFlow 2.0"

Uninstall tensorflow and then install the 1.x version with

pip install tensorflow==1.15

Upvotes: 7

Rich Rajah
Rich Rajah

Reputation: 2464

for running it on python3 I used pip3 to install

pip3 install tensorflow

This worked for me

Upvotes: -6

Yehdhih ANNA
Yehdhih ANNA

Reputation: 1300

For anyone who is trying some old codes from github with Tensorflow 1.x.x versions while having Tensorflow 2.0.x please note that tf.contrib no longer exist in Tensorflow 2.0.x and it's modules were moved.
Please google the name of the module without the tf.contrib part to know it's new location and thus migrating your code accordingly by correcting the import statement.

Hope this helped!

Upvotes: 83

PemaGrg
PemaGrg

Reputation: 730

first unistall tensorflow

pip uninstall tensorflow

then install 1.13.2 version

pip install tensorflow==1.13.2

it works.. had the same issue.. but installing tensorflow 1.13.2 solved it!
the newer version of tensorflow doesn't have

Upvotes: 51

Jasper Chih
Jasper Chih

Reputation: 107

I solved this by below method.

  pip uninstall tensorflow_estimator
  pip install tensorflow_estimator

the reference is : https://github.com/tensorflow/tensorflow/issues/27079

Upvotes: 7

Related Questions