pythontensorflowkerastf.kerasadam

How to solve the problem with tf.keras.optimizers.Adam(lr=0.001) command not working?


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>


Solution

  • 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())