Python TensorFlow v2, locating contrib.training - python

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.

Related

No module named 'tensorflow.keras'

I am trying to play around with a custom object detection model that builds of a pretrained model. All I want is for my model is to detect a specific logo in a picture. The problem is, the guide that I am following is having problems with the libraries.
import tensorflow as tf
from imageai.Detection.Custom import DetectionModelTrainer
trainer = DetectionModelTrainer()
trainer.setModelTypeAsYOLOv3()
trainer.setDataDirectory(data_directory="/content/drive/MyDrive/Logo_Model2/")
trainer.setTrainConfig(object_names_array=["logo"], batch_size=4, num_experiments=122, train_from_pretrained_model="/content/drive/MyDrive/pretrained-yolov3.h5")
trainer.trainModel()
My error is coming when I import imageai.Detection.Custom import DetectionModelTrainer. I am doing this on google colab and I checked the versions and they seem to be all up to date.
ModuleNotFoundError: No module named 'tensorflow.keras'
Any ideas? I have looked around stack for similar problems yet I haven't been able to resolve my issue. It doesn't seem to be a tensorflow problem since I am able to build my models just fine until I add imageai.
Seems to be an issue with the latest tensorflow==2.8.0. git issue
For now, you can revert back to the older version of tensorflow
pip install tensorflow==2.7
And upgrade imageAI :
pip install imageai --upgrade

module tensorflow has no attribute contrib

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.

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.

Tensorflow Object Detection API - Error running model_builder_test.py module 'tensorflow' has no attribute 'contrib'

I installed the Tensorflow Object Detection API, and ran the model_builder_test.py script to make sure everything was working. I got the following error:
AttributeError: module 'tensorflow' has no attribute 'contrib'
I'm using Python 3.7.3 and Tensorflow 2.0.0. According to this answer, it may be related to Tensorflow version 2. I'm going to use this method to upgrade the model_builder_test.py script. However, I'm worried about other issues in the Object Detection API using Tensorflow 2.
My questions are:
1) Am I correct in interpreting this error?
2) Is it safe to use Object Detection with Tensorflow 2, or should I downgrade to Tensorflow 1.x?
Thanks!
1) Yes
2) Yes, and it may in fact work better per several bug fixes in TF2 - but make sure you follow the linked guide closely to confirm model behavior doesn't change unexpectedly (i.e. compare execution in TF1 vs. TF2)
However; the "make sure" in (2) is easier said than done - we're talking about an entire API here. This is best left to the API's devs themselves, unless you're highly familiar with relevant parts of the repository. Even if you fix one bug, there may be others, even those that don't throw errors, per class/method-based functionality changes (especially in Eager vs. Graph interactions). There's not much harm to using TF 1.x, and it may even run faster.
Lastly, I'd suggest opening a TF Git issue on this; contributors/devs may respond there & not here.

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.

Categories

Resources