1

I'm working on Google Colab and when I type

model.compile(optimizer=tf.keras.optimizers.Adam(lr=1e-6), loss=tf.keras.losses.BinaryCrossentropy())

it doesn't work and I get the following error message

Could not interpret optimizer identifier: <keras.optimizer_v2.adam.Adam object at 0x7f21a9b34d50>

Isaac Sady
  • 17
  • 1
  • 4

2 Answers2

1

Generally, Maybe you used a different version for the layers import and the optimizer import. tensorflow.python.keras API for model and layers and keras.optimizers for SGD. They are two different Keras versions of TensorFlow and pure Keras. They could not work together. You have to change everything to one version. Then it should work.

Maybe try import:

from tensorflow.keras.optimizers import Adam
model.compile(optimizer=Adam(lr=1e-6),loss=tf.keras.losses.BinaryCrossentropy())
Niv Dudovitch
  • 1,614
  • 7
  • 15
0

Actually I am using

keras===2.7.0
tensorflow==2.8.0

and it worked for me when I used :

from keras.optimizers import adam_v2

Then

optimizer = adam_v2.Adam(lr=learning_rate)
model.compile(loss="binary_crossentropy", optimizer=optimizer)

Instead of using tf.keras.optimizers.Adam

Schopen Hacker
  • 152
  • 1
  • 4