module tensorflow has no attribute contrib - python

I've made a piece of code using a tutorial based on tensorflow 1.6 which uses 'contrib' and this is not compatible with my current tensorflow verison (2.1.0).
I haven't been able to run the upgrade script and downgrading my version of tf causes another host of problems.
I've also tried using other modules in tensor flow 2 such as tensorflow-addons and disabling version 2 behaviour.
What to do??

Thank you to #jdehesa
Here is the information on TensorFlow official website.
Warning: The tf.contrib module is not included in TensorFlow 2. Many
of its submodules have been integrated into TensorFlow core, or
spun-off into other projects like tensorflow_io, or tensorflow_addons.
For instructions on how to upgrade see the Migration guide.
https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib
https://www.tensorflow.org/guide/migrate
Or, you can just convert the code to an appropriate version for TF 2.x.

Related

How can I know which is the lastest Python version compatible for Tensorflow v2.x?

As title. My requirement is very simple. Since I will probably need to use the latest features of Python at my work. I wonder how to know the latest version of Python can be used with Tensorflow v2.x without any trouble regarding compatibility. I must put emphasis on that I need to use the tensorflow.keras module. I don't want to get an error message during the model training. Any advice?
I did try to follow the issue on their GitHub on supporting Python3.9. While the issue is closed, most of the comments there are NOT from the contributors/maintainers. And the last comment is on 2021/6. Is Python3.9 the lastest compatible version to run Tensorflow v2.x?
TensorFlow 2 is supported from Python 3.7 to 3.10 according to their website: https://www.tensorflow.org/install?hl=en

Python TensorFlow v2, locating contrib.training

I am using some code based on Tensorflow 1.x and I am using the latest version of TensorFlow (2.8).
I have run tf_upgrade_v2 (following these migration instructions) on the python file to generate a new compatible file.
However, this doesn't work with the line of code; from TensorFlow.contrib import training as contrib_training.
Getting the error ModuleNotFoundError: No module named 'tensorflow.contrib'
I understand that contrib has been deprecated, so the modules have been moved around. But I haven't been able to find where this training module has moved to or if it has been deleted. I have looked for information first on this document on the status of tf.contrib and after this spreadsheet on TF2.0 Symbols map and haven't found any information on the fate of this training module;
I have also tried looking around TensforFlow/tf.compat.v1 but with no success.
Of course uninstalling this version of TensorFlow and instead installing an earlier version is an option. But not an option that I am overly keen on.
I feel like I may be missing something fairly obvious here...
Thanks in advance!!
The reason behind this error - ModuleNotFoundError: No module named 'tensorflow.contrib' is, tf.contrib has been deprected to use in Tensorflow 2.x. You can use Tensorflow Addons or Tensorflow Slim in the pace of tf.contrib api.
Please check this link for more details.

Unable to train dataset for RCNN due to attribute error?

I am currently following the tutorial by EdjeElectronics: https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#1-install-anaconda-cuda-and-cudnn and I am in the step no:6. Run the Training. I had certain errors before but I cleared them so I have generated the TFrecords and I am stuck here.image
If there are any files that I need to attach for your convenience pls let me know.
The contrib attribute has moved out of Tesnsorflow version 2.
To use version 1, replace the 'import tensorflow as tf' line as follows:
#import tensorflow as tf
import tensorflow.compat.v1 as tf #using v1 of tf
Actually, when looking at this link - https://www.tensorflow.org/guide/migrate, there is a line -
It is still possible to run 1.X code, unmodified (except for contrib), in TensorFlow 2.0
The link goes to page - https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md which explains what happened to each contrib module.
You can try to migrate code to Tensorflow 2 or whatever version you are using.
Another alternative is to uninstall your Tensorflow installation and install Tensorflow with version 1.x.

The equivalent of tf.contrib.image.transform in tensorflow 2.0?

What is the equivalent of tf.contrib.image.transform in tensorflow 2.0? When I use the tf_upgrade_v2 conversion script, I get the error:
ERROR: Using member tf.contrib.image.transform in deprecated module tf.contrib. tf.contrib.image.transform cannot be converted automatically. tf.contrib will not be distributed with TensorFlow 2.0, please consider an alternative in non-contrib TensorFlow, a community-maintained repository such as tensorflow/addons, or fork the required code.
There is no equivalent. Some of the ops are implemented in the tensorflow addons though which is only available in Linux not Windows for now.
Here is the link to tensorflow addones:
https://github.com/tensorflow/addons
Here is the link to one of their image ops which is similar to tf.contrib.image.transform:
https://github.com/tensorflow/addons/blob/master/docs/tutorials/image_ops.ipynb
Hope this helped.
As said by Amir this seems to not be part of the new API.
Maybe you can look at the TensorFlow Graphics library. I did not find any equivalent of transform for the moment, but I think that such implementation can fit in this library.

Am I receiving tensorflow 2.x warnings while using version 1.14?

I have a very simple question. I recently had to format my pc and therefore I recreated my whole working environment. I'm using Anaconda (latest version) and I used conda to install tensorflow-gpu, keras..
The code, like before, is working fine but I'm seeing a lot of warnings about deprecations and I'm sure a lot of them are related to tf version 2.x but I'm using tf 1.14 (I printed it after importing tensorflow in my code and so I'm sure, moreover I never asked Anaconda to install any 2.x version)
For example:
W0813 19:25:46.491560 15288 nn_ops.py:4224] Large dropout rate: 0.75 (>0.5).
In TensorFlow 2.x, dropout() uses dropout rate instead of keep_prob.
Please ensure that this is intended.
W0813 19:36:22.136491 15288 deprecation_wrapper.py:119]
From C:\Users\-----\Anaconda3\envs\tensorflow_GPU\lib\site-packages\keras\callbacks.py:850:
The name tf.summary.merge_all is deprecated.
Please use tf.compat.v1.summary.merge_all instead.
Is this normal? Do I have to correct them or can I disable this types of warnings?
The purpose of these warning messages is to spread awareness of TensorFlow 2.0
Because in the long run TF 2.X is likely to be widely adopted.
This is normal and you can safely ignore these warnings by,
import logging, os
logging.disable(logging.WARNING)
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"

Categories

Resources