tf.keras之回调函数

2020-03-18  本文已影响0人  612twilight

tf.keras的model在进行fit时可以传入各种回调函数,介绍几种常用的回调函数。

EarlyStopping

LearningRateScheduler

LearningRateScheduler是学习率调整策略,有以下两个参数

ReduceLROnPlateau

monitor: 监听的变量

factor: 衰减因子,每次衰减都乘以这个数,factor by which the learning rate will be reduced. new_lr = lr *

factor

patience: 变量多少轮没有提升之后,减少学习率

verbose: int. 0: quiet, 1: update messages.

mode: one of {auto, min, max}. In min mode, lr will be reduced when the

quantity monitored has stopped decreasing; in max mode it will be

reduced when the quantity monitored has stopped increasing; in auto

mode, the direction is automatically inferred from the name of the

monitored quantity.

min_delta: 这是用来衡量监控值是否提升的阈值.

cooldown: 学习率衰减之后,会等几轮再重新判定是否衰减number of epochs to wait before resuming normal operation after

lr has been reduced.

min_lr:学习率的下届

LambdaCallback

接受如下六个参数,这几个参数都是匿名函数:

on_epoch_begin: called at the beginning of every epoch.
on_epoch_end: called at the end of every epoch.
on_batch_begin: called at the beginning of every batch.
on_batch_end: called at the end of every batch.
on_train_begin: called at the beginning of model training.
on_train_end: called at the end of model training.`

匿名函数的参数如下:

on_epoch_beginandon_epoch_endexpect two positional arguments:epoch,logs-on_batch_beginandon_batch_endexpect two positional arguments:batch,logs-on_train_beginandon_train_endexpect one positional argument:logs`

自定义CallBack

自定义callback继承父类即可,可以自己实现复杂的回调函数

上一篇 下一篇

猜你喜欢

热点阅读