tensorflow2.0学习率衰减

import tensorflow_core as tfc
from tensorflow_core.python.keras.callbacks import LearningRateScheduler
num_epochs =20
learning_rate=0.3
#定义学习率衰减函数
def scheduler(epoch):
    if epoch < num_epochs * 0.4:
        return learning_rate
    if epoch < num_epochs * 0.8:
        return learning_rate * 0.1
    return learning_rate * 0.01
change_Lr = tfc.python.keras.callbacks.LearningRateScheduler(scheduler)

history = model.fit_generator(train_generator,
                              steps_per_epoch=10,
                              epochs=epochs,
                              validation_data=valid_generator,
                              validation_steps=10
                              ,callbacks=[change_Lr])

你可能感兴趣的:(tensorflow2.0学习率衰减)