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
Related
I am trying to run a code, which was written with tensorflow version 1.4.0
I am running my code on google colab which gives in tensorflow version 2.x with it.
To run my code, I am using backward compatibility like:
replacing import tensorflow as tf with
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
which works for certain things, but at a point it comes down to this error
AttributeError: module 'tensorflow.compat.v2' has no attribute 'depth_to_space'
as you can see in this image
What I am not able to understand is this method 'depth_to_space' is in both versions of tensorflow 1.x and 2.x , then why is my version of tensorflow not getting it ?
Here's the link to the method in version 1.x: https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/depth_to_space
Please help me understand what's the cause of this error.
Thanks,
Pranay
I tried with Tensorflow 1.15.Its working fine.
Looks like your Tensorflow version bit old,
Below sample code tested with Tf 1.15 without any error.
import tensorflow as tf
print(tf.__version__)
x = [[[[1, 2, 3, 4]]]]
tf.nn.depth_to_space(x, 2, data_format='NHWC', name=None)
I had some issues about using
'''
tensorflow.reset_default_graph
'''
,so I tried to downgrade the tensorflow version to 1.4.
And I had problem about:
'''
ModuleNotFoundError: No module named 'tensorflow.compat'
'''
.
The problem about reset_default_graph was in the version of tensorflow 2.0, and the version about tensorflow.compat was 1.4.
From comments
In TF 2.x, you can use tf.compat.v1.reset_default_graph() instead of
reset_default_graph().
After disabling eager execution using
tensorflow.compat.v1.disable_eager_execution() has resolved the
issue.
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'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.
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.