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.
Related
I am trying to implement https://github.com/ec-jrc/GHS-S2Net this project (in google colab). A week ago it was working by installing the requirements:
!pip install tensorflow-gpu==2.0.0
!pip install Keras==2.3.1
Unfortunately, from this week it is showing me module 'tensorflow_core.compat.v2' has no attribute '__internal__' for import keras.
Ok, I wanted to try with the latest versions of tensor and keras (both 2.5.0), but now I am getting following error:
AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'slice'
How can I handle this?
AttributeError: module 'tensorflow.python.keras.backend' has no
attribute 'slice'
It looks like an installation issue. Please try to uninstall and reinstall Keras
pip uninstall keras
pip install keras --upgrade
module 'tensorflow_core.compat.v2' has no attribute 'internal'
Due to incompatibility between Tensorflow and Keras you get this issue.
As mentioned above, if you upgrade to latest keras version and import keras or import keras from tensorflow as from tensorflow import keras will resolve this issue. For more information you can refer here.
Keras.backend doesnt have a slice operation. Instead, you can go to the location where the crf.py file is stored locally on your machine (this you can find mentioned in the error dialogue, i.e.(myenv\Lib\site-packages\keras_contrib\layers\crf.py) and do the following:
add the line --> import tensorflow as tf.
Goto line number where it is mentioned K.slice,
It is in the function: def step(self, input_energy_t, states, return_logZ=True.
You can do a search for "slice".
Then replace K.slice by tf.slice.
Restart the jupyter notebook session. This should work.
Change the line 463 in crf.py as import tensorflow as tf; tf.slice. Then save the crf.py.
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.
I just installed new tf and cuda today, but when I run the previous code that worked with tf-1.4 won't work under new tensorflow-2.1.0 and cuda-10.1
How to fix this?
Mentioning the Solution in the Answer Section (even though it is present in Comments Section), for the benefit of the Community.
Replacing the command,
import tensorflow as tf
with
import tensorflow.compat.v1 as tf
has resolved the error.
For more information about Migrating from Tensorflow 1.x to 2.x, please refer this Tensorflow Tutorial and this Upgrade Script also will be helpful.
I have been getting multiple errors which are due to conflicts in the TensorFlow version installed in my system and the version used to write the code in Tensorflow API.
I am using python 3.6.7 and Tensorflow 2.0 to get started with the code https://github.com/tensorflow/models/blob/master/research/deeplab/g3doc/installation.md
But I am getting several errors :
flags = tf.app.flags
AttributeError: module 'tensorflow' has no attribute 'app.
As I am using 2.0 , I replaced tf.app.flags with tf.compat.v1.flags.
from tensorflow.contrib import slim as contrib_slim
ModuleNotFoundError: No module named 'tensorflow.contrib'
I am not able to solve the second one.
Can I get help to know which python and tensorflow version should be used to run DeepLab v3+?
You should use the Tensorflow version 1.x to run the DeepLabV3+ model because it uses a session to run and also the slim library which is based on the TensorFlow 1.x. And so your two problems can be solved as:
Do not need to replace tf.app.flags with tf.compat.v1.flags.
To run DeepLabV3+ model, you need to put deeplab and slim folder in a folder (deeplab_slim),
and export them by running following export commands from this parent folder (deeplab_slim):
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/deeplab
following this tutorial
I am trying to run a pre-written model for TensorFlow, and because I am running TensorFlow 2, and the code I am using was meant for an older version. specifically, tf.contrib.
From original code:
from tensorflow.contrib import legacy_seq2seq
From first fix I found:
from tensorflow.python.ops.seq2seq import sequence_loss
error:
ModuleNotFoundError: No module named 'tensorflow.python.ops.seq2seq'
Where do I find the methods that were in tf.contrib, and import them and use them? Do the old functionalities still exist?
Please note that tf.contrib has been dropped in TF 2.0. Source
Removal of tf.contrib - These features have been either moved to TensorFlow Core, or to tensorflow/addons, or are no longer part of the TensorFlow build but are developed and maintained by their respective owners.
Updated and revised documentation, examples, and website, including migration docs and TF 1.x to 2.0 converter guide.
For example tf.contrib.layers.layer_norm, according to this github issue got moved to here: https://github.com/tensorflow/addons/tree/master/tensorflow_addons/layers.
TF 2.0: seq2seq is under tensorflow_addons now
You can find a github post on how to handle seq2seq for TF 2.0 under tensorflow_addons: https://github.com/tensorflow/addons/tree/master/tensorflow_addons/seq2seq. It gives you a clear example on how convert TF 1.x seq2seq into its TF 2.0
equivalent. Look under Sample code and Migration guide from TF 1.X
# TF 2.0
import tensorflow_addons as tfa
sampler = tfa.seq2seq.sampler.TrainingSampler()
TF 1.x to TF 2.0 Upgrade
I would suggest you to first try and migrate the TF 1.x code to TF 2.0. Refer to how to automatically upgrade from TF 1.x to TF 2.0?
Recommended upgrade process