11

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

seni
  • 659
  • 1
  • 8
  • 20

3 Answers3

10

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)
1
! pip install tensorflow --upgrade --user

--user option can help you without the permission problem

Hong Cheng
  • 318
  • 1
  • 4
  • 19
1

Add this line to the importing section (of course after import tensorflow as tf) tf.config.experimental_run_functions_eagerly(True)

Almost any tf.keras.layers.experimental.preprocessing.SomeClass in the listed classes here, should work.

But need to do sanity check with plotting results.

Ahmed
  • 111
  • 5