AttributeError: module 'keras.layers' has no attribute 'experimental'

I am trying to run a TensorFlow model on M1 Mac with the following settings:

  1. MacBook Pro M1
  2. macOS 12.4
  3. tensorflow-deps & tensorflow-estimator --> 2.9.0
  4. tensorflow-macos --> 2.9.2
  5. tensorflow-metal --> 0.5.0
  6. keras --> 2.9.0
  7. keras-preprocessing --> 1.1.2
  8. Python 3.8.13

When resizing and rescaling from keras.layers, I got the following error:

resize_and_rescale = keras.Sequential([
   layers.experimental.preprocessing.Resizing(IMAGE_SIZE, IMAGE_SIZE),
   layers.experimental.preprocessing.Rescaling(1./255),
])

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [15], in <cell line: 1>()
      1 resize_and_rescale = keras.Sequential([
----> 2   layers.experimental.preprocessing.Resizing(IMAGE_SIZE, IMAGE_SIZE),
      3   layers.experimental.preprocessing.Rescaling(1./255),
      4 ])
AttributeError: module 'keras.layers' has no attribute 'experimental'

Any suggestions? Thanks

Answered by Frameworks Engineer in 721786022

Hello, thank you for raising this issue! I would suggest using the syntax keras.layers.experimental.preprocessing instead of layers.experimental.preprocessing.

Accepted Answer

Hello, thank you for raising this issue! I would suggest using the syntax keras.layers.experimental.preprocessing instead of layers.experimental.preprocessing.

AttributeError: module 'keras.layers' has no attribute 'experimental'
 
 
Q