I'm training a Keras model and saving it for later use using pickle.
When I unpickle I get this error:
AttributeError: 'Adam' object has no attribute 'build'
Here's the code:
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
import pickle
model = Sequential()
model.add(Dense(32, activation='relu', input_shape=(3,)))
model.add(Dense(1, activation='linear')) # Use linear activation for regression
model.compile(loss='mean_squared_error', optimizer='adam')
pickle.dump(model, open("m.pkl", 'wb'))
loadedModel = pickle.load(open("m.pkl", 'rb'))
I get this error with TensorFlow 2.11.x and 2.13.0-rc0 on MacOS M1
Actually, the same error happens using the keras save and load_model. I found this entry on the keras GitHub page:
https://github.com/keras-team/keras/issues/18278
This indicates that on M1/M2 Macs, keras reverts to the legacy optimizers, and that version of Adam does not have a build() function. I've tried other optimizers, but they appear to have this issue as well.
I have not found a solution yet...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With