Search code examples
pythonmachine-learningneural-networkkeras

Get learning rate of keras model


I cannot seem to get the value of learning rate. What I get is below.

I've tried the model for 200 epochs and want to see/change the learning rate. Is this not the correct way?

>>> print(ig_cnn_model.optimizer.lr)
<tf.Variable 'lr_6:0' shape=() dtype=float32_ref>

Solution

  • Use eval() from keras.backend:

    import keras.backend as K
    from keras.models import Sequential
    from keras.layers import Dense
    
    model = Sequential()
    model.add(Dense(1, input_shape=(1,)))
    model.add(Dense(1))
    model.compile(loss='mse', optimizer='adam')
    
    print(K.eval(model.optimizer.lr))
    

    Output:

    0.001