'I'm getting this error : 'AttributeError: module 'keras.optimizers' has no attribute 'Adam''
I'm trying to run this code in Google Colab :
from keras import optimizers from tensorflow.keras.optimizers import Adam
for i in range(5):
print(i)
model_mix = Model(inputs=[visible, visible1], outputs=x)
adam = optimizers.Adam(lr=0.01, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False)
monitor = EarlyStopping(monitor='val_loss', min_delta=1e-3, patience=6, verbose=2, mode='auto')
model_mix.compile(loss="mean_squared_error", optimizer=adam)
model_mix.fit(
[x_text_train, x_img_train], y_text_train, callbacks=[checkpointer_cnn,monitor],**strong text**
validation_data=([x_text_test, x_img_test], y_text_test),
epochs=1000)
It worked fine before but now it is giving me an error. Can someone help me to fix it?
Solution 1:[1]
Just remove optimizers., i.e. adam = Adam(lr=0.01, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False)
It should work like this.
Solution 2:[2]
Maybe it's because of diffenert editions of keras, on keras2.8.0 try:
adam = optimizers.adam_v2.Adam(lr=0.01, ......)
Solution 3:[3]
Use this
from tensorflow.keras.optimizers import Adam
Instead of
from keras import optimizers from tensorflow.keras.optimizers import Adam
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | elbe |
| Solution 2 | ouflak |
| Solution 3 | Ayush Raj |
