-
Notifications
You must be signed in to change notification settings - Fork 45.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: module tensorflow has no attribute contrib #7767
Comments
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 These discussion maybe helpful? |
Hello there, |
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 |
@EduardoABarrera parts of tensorflow/models latest code base are still using the TF 1.x API. For instance:
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 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 unwinding path is just this line : |
For the usage in LSTM, it has been changed to the following.
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.
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,I checked file where in tensorflow\contrib. |
I would add: create a specific environment for this and use it for TF1 stuff. You can do that in conda like:
Then you can happily:
|
I have a similar problem with this line: self.optimizer = tf.compat.v1.contrib.opt.ScipyOptimizerInterface(self.loss,
method = 'L-BFGS-B',
options = {'maxiter': 50000,
'maxfun': 50000,
'maxcor': 50,
'maxls': 50,
'ftol' : 1.0 * np.finfo(float).eps})
init = tf.global_variables_initializer()
self.sess.run(init) It throws: Any suggestion is appreciated. Thanks! |
Please check if your PYTHONPATH is set. If it is not set, you can get this error of 'has no attribute 'contrib''. |
export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim |
@engsbk Hello, AttributeError: module 'tensorflow._api.v2.compat.v1' has no attribute 'contrib' |
You can solve this in one of two ways:
Unless the code you are trying to run is totally uncompatible with Tensorflow v.2.x, in which case just switch back to Tensorflow v1.x. |
Thanks you.
Le mar. 16 mars 2021 à 20:01, Shaikha Alkhuder ***@***.***> a
écrit :
… @engsbk <https://github.com/engsbk> Hello,
Please how do you solved your issue??
AttributeError: module 'tensorflow._api.v2.compat.v1' has no attribute
'contrib'
You can solve this in one of two ways:
- you can entirely remove Tensorflow v1.x and install Tensorflow v2.x
- Or Install Tensorflow v2.x and make sure it in the PATH directory.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#7767 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATHS5ZRTTFXCQ2HYUG4VDJ3TD5CAVANCNFSM4JJYRFUA>
.
|
@engsbk I tried your suggestion, but still have problems. Any help?? TensorFlow 2.0.0 + Keras 2.3.1 on Python 3.6. Problem1: config = tf.ConfigProto() Problem2: self.optimizer = tf.contrib.opt.ScipyOptimizerInterface(self.loss, |
On Linux only:
As mentioned above this wont work on python 3.7 or later. useful links are: https://www.tensorflow.org/guide/migrate Python alternative install on Linux: https://hackersandslackers.com/multiple-versions-python-ubuntu/ python source download urls: https://www.python.org/ftp/python/3.7.0/ managing virtual environments Linux: https://www.liquidweb.com/kb/creating-virtual-environment-ubuntu-16-04/ https://docs.python.org/3/library/venv.html haveing tried most of the above- including migrating code and I was sucesfull able to run code with the above method without issue. Hope this helps :-) |
Replace TF V1 line |
The "attributeerror: module tensorflow has no attribute contrib" error occurs in Python when we try to import or use tf.contrib in TensorFlow 2.0 or later versions. This is because tf.contrib has been removed from TensorFlow 2.0. To fix this error we need to downgrade the tensorflow to the version that supports the tf.contrib or upgrade the code from 1.x version to 2.x version. You can check this guide to resolve this error, I have found it very helpful. |
THANKSSSSS IT WORKSSSS |
AttributeError: module 'tensorflow' has no attribute 'contrib' I am facing this error please help |
Thank you so muchhhhh :) |
Hello Everyone! File "F:\Anaconda\envs\pothole\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\data_decoders\tf_example_decoder.py", line 332, in Thanks! |
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'
The text was updated successfully, but these errors were encountered: