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.
Arguments
- schedule
A function that takes an epoch index (integer, indexed from 0) and current learning rate (float) as inputs and returns a new learning rate as output (float).
- verbose
Integer. 0: quiet, 1: log update messages.
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)