Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'tensorflow_core.keras.layers.experimental.preprocessing' has no attribute 'RandomFlip'

I use Tensorflow 2.1.0 In this code

data_augmentation = tf.keras.Sequential([
    tf.keras.layers.experimental.preprocessing.RandomFlip('horizontal'),
    tf.keras.layers.experimental.preprocessing.RandomRotation(0.3)
]) 

I find this error:

AttributeError: module 'tensorflow_core.keras.layers.experimental.preprocessing' has no attribute 'RandomFlip'

So how can I change it without changing version of tensorflow

like image 290
seni Avatar asked Sep 15 '20 09:09

seni


2 Answers

To work your code as expected, firstly Tensorflow has to be upgrade to the latest version

! pip install tensorflow --upgrade

If you are looking for solution in TF 2.1.0, then there are two options are available

First solution: tf.image.random_flip_left_right ( horizontal flip)

tf.image.random_flip_left_right(
    image, seed=None)

Second solution: tf.keras.preprocessing.image.ImageDataGenerator

tf.keras.preprocessing.image.ImageDataGenerator(
   rotation_range=30, horizontal_flip=True)
like image 190
TFer2 Avatar answered Oct 15 '22 11:10

TFer2


! pip install tensorflow --upgrade --user

--user option can help you without the permission problem

like image 26
Hong Cheng Avatar answered Oct 15 '22 10:10

Hong Cheng