I'm a beginner.
I'm working with python - TensorFlow '2.2.0' on python IDLE.
run_opts = tf.RunOptions(report_tensor_allocations_upon_oom = True)
I got the following error while running the previous code.:
AttributeError: module 'tensorflow' has no attribute 'RunOptions'"
however, according to example 18 from this link on the official page on Tensorflow, there's no error!
what's wrong in my case? How should I resolve this issue?
This is a compatibility issue between tensorflow 1.x and tensorflow 2.x. In other words, the syntax that you wrote works fine with tensorflow 1.x. But as you mentioned, you're using tensorflow 2.2 which is incompatible.
So, you have can solve this issue by either one of the following two options:
Uninstall tensorflow 2.2 and install tensorflow 1.15 which will save you a lot of the headache knowing that the link that you've posted is using tensorflow 1.13.1 as mentioned in the README file.
Or you can use tf.compat.v1.RunOptions instead of just tf.RunOptions.
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.
When I try to run the code in machinelearningmastery , I get
AttributeError: module 'tensorflow' has no attribute 'random_shuffle'
And it points at the following
from mrcnn.model import MaskRCNN
from mrcnn.config import Config
model = MaskRCNN(mode='training', model_dir='./', config=config)
How can one solve this ?
It's likely you have Tensorflow 2.0 installed and the code on machine learning mastery has been written on top of tf < 2.0.
You can do either of two things:
Downgrade your tf to v1.x
Change tf.random_shuffle to tf.random.shuffle
Also, consider downgrading Keras from v2.3.1 to v2.1.1 (not a must though)
TensorFlow 2.0 has a different API than TensorFlow 1.x, you cannot run software that is made for TensorFlow 1.3 in version 2.0, you need to either downgrade TensorFlow, or find a version of the software that is explicitly made compatible with TensorFlow 2.x
I have the same issue. And it is resolved by changing tf.random_shuffle to tf.random.shuffle
I am running the following code on a server with a gpu, using tensorflow-gpu version=1.2:
matrix_b = tf.matrix_inverse(matrix_a)
When running the same code on my laptop (no gpu) with tensorflow version=1.8 it works.
As I see in the documentation, this is implemented for the tensorflow version I am using, so it should be supported. yet I get the following error:
AttributeError: 'module' object has no attribute 'matrix_inverse'
so to my question - Can it be that the matrix_inverse() is not supported in tensorflow-gpu 1.2 but is supported in tensorflow 1.2?
and if so, where can I see the correct documentation?
The answer may come a little late.
Use tf.linalg.inv() instead of tf.matrix_inverse()