version: python 3.6.9
OS: windows10
IDE: anaconda, spyder (executing locally)
also installed tensorflow by creating new environment in anaconda (without using pip)
tensorflow version 2.0.0
code shown below:
import tensorflow as tf
''''
'''''
init_kernel = tf.contrib.layers.xavier_initializer()
getting error for the above line.
AttributeError: module 'tensorflow' has no attribute 'contrib'
Since you say that you used TF 2.0, from the TF docs:
https://www.tensorflow.org/guide/upgrade#compatibility_modules
I gather (but I could be wrong) that tf.contrib is not available on TF 2.0 (At least not all of the functionality).
These discussion maybe helpful?
https://github.com/tensorflow/tensorflow/issues/26854
https://github.com/tensorflow/community/pull/18
Hello there,
When I use
initializer = tf.contrib.layers.xavier_initializer(seed = 0))
to initialize my ML layer I get the following error
AttributeError: module 'tensorflow' has no attribute 'contrib'
Any suggestion to remove this error is really appreciated.
tensorflow.contrib was removed in TF2. Tensorflow Core released a utility to convert your TF 1.x scripts to TF2.0 which can be found here: https://www.tensorflow.org/guide/upgrade
EDIT: It was brought to my attention that the utility mentioned here cannot convert the tf.contrib library, so this method does not work. I will leave the comment up to save someone's time in the future.
@EduardoABarrera parts of tensorflow/models latest code base are still using the TF 1.x API.
For instance:
...
from object_detection.utils import static_shape
// Throws: AttributeError: module 'tensorflow' has no attribute 'contrib'
slim = tf.contrib.slim
BOX_ENCODINGS = box_predictor.BOX_ENCODINGS
...
Find the complete file here
This is causing problems when doing transfer learning on object detection models. Do you have any idea or workaround for this one?
@EduardoABarrera parts of tensorflow/models latest code base are still using the TF 1.x API.
For instance:
... from object_detection.utils import static_shape // Throws: AttributeError: module 'tensorflow' has no attribute 'contrib' slim = tf.contrib.slim BOX_ENCODINGS = box_predictor.BOX_ENCODINGS ...Find the complete file here
This is causing problems when doing transfer learning on object detection models. Do you have any idea or workaround for this one?
@mrhanti I also bumped into this problem, and it turns out that the library tf.contrib is the only library that isn't converted via the utility mentioned above. If you're trying to convert a model like AlexNet that was written in TF1.X to a version of AlexNet written in TF2.0, I don't think there is a simple solution for that. I detailed this same problem (almost?) in this Stack overflow post.
The third point in my Stack overflow post is what I had to end up doing (writing out the model architecture by hand after converting it a few times), and it involved a lot of work. Sorry to bear bad news. :(
So there is no easy way out for this? @EduardoABarrera
https://www.tensorflow.org/api_docs/python/tf/compat/v1/nn/rnn_cell/BasicLSTMCell
The only workaround if you want to use Basic LSTM Cell.
The unwinding path is just this line :
!pip install tensorflow==1.14
better than getting involved in convoluted procedure
For the usage in LSTM, it has been changed to the following.
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)
And then it works. However, contrib is used widely in TensorFlow 1.x, Google does no provides an integrated solution to the contrib issue. For instance, it is another solution to the specific contrib case.
# -initializer = tf.contrib.layers.xavier_initializer(seed = 1)
initializer = tf.truncated_normal_initializer(stddev=0.1)
It is the pain of TensorFlow 2.x by the Google Team. Therefore, we need to solve the contrib problems case by case.
My Tensorflow version is 2.1.0锛孖 checked file where in tensorflow\contrib.
There's just a little bit of code here.
Like i found slim film but there's have nothion in it,
Most helpful comment
tensorflow.contrib was removed in TF2. Tensorflow Core released a utility to convert your TF 1.x scripts to TF2.0 which can be found here: https://www.tensorflow.org/guide/upgrade
EDIT: It was brought to my attention that the utility mentioned here cannot convert the
tf.contriblibrary, so this method does not work. I will leave the comment up to save someone's time in the future.