Attributeerror: Module 'tensorflow_core.compat.v1' Has No Attribute 'contrib'
x = tf.placeholder(dtype = tf.float32, shape = [None, 28, 28]) y = tf.placeholder(dtype = tf.int32, shape = [None]) images_flat = tf.contrib.layers.flatten(x) logits = tf.contrib.l
Solution 1:
tf.contrib
was removed from TensorFlow once with TensorFlow 2.0 alpha version.
Most likely, you are already using TensorFlow 2.0.
You can find more details here: https://github.com/tensorflow/tensorflow/releases/tag/v2.0.0-alpha0
For using specific versions of tensorflow, use
pip install tensorflow==1.14
or
pip install tensorflow-gpu==1.14
Solution 2:
I think you need to add the following line in your python file which you are going to execute it.
import tensorflow.compat.v1as tf
tf.disable_v2_behavior()
Solution 3:
contrib is a headache of Google Team. We have to deal with the issue of contrib case by case. I just take two examples as follows.
1.With regard to CNN, it has the following method
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
# -initializer = tf.contrib.layers.xavier_initializer(seed=1)
initializer = tf.truncated_normal_initializer(stddev=0.1)
2.With regard to RNN/LSTM, it has the following different method.
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
# -outputs, states = tf.contrib.rnn.static_rnn(lstm_cells, _X, dtype=tf.float32)
outputs, states = tf.compat.v1.nn.static_rnn(lstm_cells, _X, dtype=tf.float32)
Post a Comment for "Attributeerror: Module 'tensorflow_core.compat.v1' Has No Attribute 'contrib'"