ModuleNotFoundError: No module named 'tensorflow.contrib' with tensorflow=2.0.0

14.1k Views Asked by At

I am using TensorFlow version=2.0.0 python version=3.7.3 I am trying to import the below statement

from tensorflow.contrib import rnn

And it gives error as Module 'tensorflow' has no attribute 'contrib' How can I resolve this?

2

There are 2 best solutions below

3
On

from tensor flow

https://www.tensorflow.org/guide/upgrade#compatibility_modules

Because of TensorFlow 2.x module deprecations (for example, tf.flags and tf.contrib), some changes can not be worked around by switching to compat.v1. Upgrading this code may require using an additional library (for example, absl.flags) or switching to a package in tensorflow/addons.

and as describe in this thread

tensorflow.contrib doesn't exist in 2.0.

https://github.com/tensorflow/tensorflow/issues/31350#issuecomment-518749548

4
On

I haven't used older versions of tensorflow. Is this what you're looking for?

from tensorflow.keras.layers import RNN

Info on contrib:
https://www.tensorflow.org/guide/migrate#a_note_on_slim_contriblayers