At the beginning of every epoch, this callback gets the updated learning
rate value from schedule
function provided, with the current
epoch and current learning rate, and applies the updated learning rate on
the optimizer.
Value
A Callback
instance that can be passed to fit.keras.src.models.model.Model()
.
Examples
# This function keeps the initial learning rate steady for the first ten epochs
# and decreases it exponentially after that.
scheduler <- function(epoch, lr) {
if (epoch < 10)
return(lr)
else
return(lr * exp(-0.1))
}
model <- keras_model_sequential() |> layer_dense(units = 10)
model |> compile(optimizer = optimizer_sgd(), loss = 'mse')
model$optimizer$learning_rate |> as.array() |> round(5)