'Alternative to 'tensorflow.contrib' with tensorflow=2.0.0

I am using TensorFlow version=2.0.0, python version=3.7.9 and I was trying to import the following:

import tensorflow.contrib.layers as layers

I get this error:

Exception has occurred: ModuleNotFoundError
No module named 'tensorflow.contrib'

As I read in this thread, tensorflow.contrib doesn't exist in 2.0. Does anyone know an alternative to it? I am trying to upgrade my code from 1.0 to 2.0 as I don't want to use tf 1.0. I am using this package to build up a RNN cell.



Solution 1:[1]

tf.contrib is deprecated in Tensorflow 2.x.

Replace import tensorflow.contrib.layers as layers

with

from tensorflow.keras.layers import RNN

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TFer