Fixing Tensorflow.contrib tf.contrib.slim Error – ModuleNotFoundError: No module named ‘tensorflow.python.saved

Tensorflow.contrib tf.contrib.slim Error – ModuleNotFoundError: No module named ‘tensorflow.python.saved is an error which occurs when you work with a Tensorflow version that does not support tf.contrib or because of another reason.

In today’s article I am going to deal with a confusing error and explain why it takes place and how to fix it, with a set of possible solutions.

Exploring the Tensorflow.contrib tf.contrib.slim Error – ModuleNotFoundError: No module named ‘tensorflow.python.saved

This is an error which occurs when you work with a Tensorflow version that does not support tf.contrib or because of another reason.

Beware of mixing between errors. Double check if the error message looks like the error message bellow, then continue.

                                                                       #
ModuleNotFoundError: No module named 'tensorflow.python.saved_model.model_utils'
                                                                       #

Solution 1 : install tensorflow_estimator again , and install tf_slim

For many people the error is caused by tensorflow_estimator. HOLD ON, if you think But I did not install this package you should know that tf.estimator is installed when you install the TensorFlow pip package.

Before we fix the issue, we should understand what tensorflow_estimator does.

TensorFlow Estimator is a high-level TensorFlow API that greatly simplifies machine learning programming. Estimators encapsulate training, evaluation, prediction, and exporting for your model.

The solution here is simple, Let us remove it.

                                                                       #
pip uninstall tensorflow_estimator
                                                                       #

And then install it again.

                                                                       #
pip install tensorflow_estimator
                                                                       #

Another option you should try after that, is to install

                                                                       #
pip install --upgrade tf_slim
                                                                       #

And use ” import tf_slim as slim ” in your code.

The error should be gone by now, if that is not true then try the method bellow.

Solution 2 : install a Tensorflow version that supports tf.contrib

In many cases, the error occurs because tf.contrib does not exist in Tensorflow 2…

You can downgrade to tensorflow==1.14

First, you should uninstall tensorflow

                                                                       #
pip uninstall tensorflow
                                                                       #

And then tensorflow==1.14 install or another version that has tf.contrib

                                                                       #
pip install tensorflow==1.14
                                                                       #

I hope the methods I provided have been helpful, I hope you solved the error already. Thank you for reading.

Summing-up : 

We arrived at the end of this quest to solve this annoying error, I hope me sharing my experience with you helped, I hope the other solutions helped, If you like this website support us on Kofi and keep browsing, thank you.

Thank you for reading, keep coding and cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/