7

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?

kriti
  • 145
  • 3
  • 4
  • 13

2 Answers2

1

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

Naor Tedgi
  • 5,204
  • 3
  • 21
  • 48
1

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

bug_spray
  • 1,445
  • 1
  • 9
  • 23
  • 1
    Using this gives error as ```AttributeError: module 'tensorflow_core._api.v2.nn' has no attribute 'rnn_cell'``` Actually I am trying to do something like this ```self.cell = tf.nn.rnn_cell.BasicLSTMCell``` – kriti Mar 27 '20 at 09:36
  • Are you unable to import keras layers? – bug_spray Mar 27 '20 at 10:13
  • https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/keras/layers/LSTMCell – bug_spray Mar 27 '20 at 10:19
  • `import tensorflow.keras.layers as layers` then... `self.cell = layers.LSTMCell(units=units, activation=activation, dropout=dropout)` – bug_spray Mar 27 '20 at 10:24