tensorflow: AttributeError: module 'keras.layers' has no attribute 'experimental': M1 Mac Tensorflow Metal
I am trying to run a TensorFlow model on M1 Mac with the following settings:
- MacBook Pro M1
- macOS 12.4
- tensorflow-deps & tensorflow-estimator --> 2.9.0
- tensorflow-macos --> 2.9.2
- tensorflow-metal --> 0.5.0
- keras --> 2.9.0
- keras-preprocessing --> 1.1.2
- 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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (2 by maintainers)
I solved it by limiting the versions of tf-models-official >=2.5.1, <2.16.0 and comment out keras in the research/object_detection/packages/tf2/setup.py I run the code in colab and colab’s keras is version 2.15.0. I suspect the newest keras messed up the object detection API
@Laelmukeni
Modify:
research/object_detection/packages/tf2/setup.pyFor me, this fixed the issue
import matplotlib import matplotlib.pyplot as plt
import io import os import numpy as np from six import BytesIO from PIL import Image, ImageDraw, ImageFont
import tensorflow as tf
from object_detection.utils import label_map_util from object_detection.utils import config_util from object_detection.utils import visualization_utils as viz_utils from object_detection.builders import model_builder