close

[Solved] “Could not interpret optimizer identifier” error in Keras

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error “Could not interpret optimizer identifier” error in Keras in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How “Could not interpret optimizer identifier” error in Keras Error Occurs?

Today I get the following error “Could not interpret optimizer identifier” error in Keras in python.

How To Solve “Could not interpret optimizer identifier” error in Keras Error ?

  1. How To Solve “Could not interpret optimizer identifier” error in Keras Error ?

    To Solve “Could not interpret optimizer identifier” error in Keras Error

  2. “Could not interpret optimizer identifier” error in Keras

Solution 1

The reason is you are using 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.

Solution 2

I am bit late here, Your issue is you have mixed Tensorflow keras and keras API in your code. The optimizer and the model should come from same layer definition. Use Keras API for everything as below:

from keras.models import Sequential
from keras.layers import Dense, Dropout, LSTM, BatchNormalization
from keras.callbacks import TensorBoard
from keras.callbacks import ModelCheckpoint
from keras.optimizers import adam

# Set Model
model = Sequential()
model.add(LSTM(128, input_shape=(train_x.shape[1:]), return_sequences=True))
model.add(Dropout(0.2))
model.add(BatchNormalization())

# Set Optimizer
opt = adam(lr=0.001, decay=1e-6)

# Compile model
model.compile(
    loss='sparse_categorical_crossentropy',
    optimizer=opt,
    metrics=['accuracy']
)

I have used adam in this example. Please use your relevant optimizer as per above code.

Hope this helps.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read