3
votes

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 ?

3
My TensorFlow version is 2.0.0 whilst in the requirements, it needs 1.3 - PolarBear10
That's why. It's renamed to random.shuffle in TF2. tensorflow.org/api_docs/python/tf/random/shuffle - David Buck

3 Answers

9
votes

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)

1
votes

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

1
votes

I have the same issue. And it is resolved by changing tf.random_shuffle to tf.random.shuffle