AttributeError: module 'tensorflow.python.keras.layers' has no attribute 'RandomFlip'

I'm trying to run the example Cats and Dogs from keras, but when I try to run this:

data_augmentation = keras.Sequential(
    [
        layers.RandomFlip("horizontal"),
        layers.RandomRotation(0.1),
    ]
)

I get this error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[5], line 3
      1 data_augmentation = keras.Sequential(
      2     [
----> 3         layers.RandomFlip("horizontal"),
      4         layers.RandomRotation(0.1),
      5     ]
      6 )

AttributeError: module 'tensorflow.python.keras.layers' has no attribute 'RandomFlip'

Any ideas to solve this? Thanks in advance for your answer.

The module doesn't seem right, please check. https://www.tensorflow.org/versions/r2.10/api_docs/python/tf/keras/layers/RandomFlip

As of Mar 2023, I was advised to use tensorflow-macos 2.9.0 and tensorflow-metal 0.5

This seems to have no such error:

from tensorflow.keras.layers import RandomFlip, RandomRotation
data_augmentation = tf.keras.Sequential([
  RandomFlip("horizontal"),
  RandomRotation(0.1),
])
AttributeError: module 'tensorflow.python.keras.layers' has no attribute 'RandomFlip'
 
 
Q