-
Notifications
You must be signed in to change notification settings - Fork 1
/
callbacks.py
46 lines (40 loc) · 1.51 KB
/
callbacks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from keras.callbacks import TensorBoard, CSVLogger, ModelCheckpoint, EarlyStopping, ReduceLROnPlateau
#function to get keras specific callbacks
def getCallbacks(params):
verbose = params['verbose']
val_to_monitor = params['val_to_monitor']
#Checkpoint callback
cp_params = params['checkpoint']
Checkpoint = ModelCheckpoint(
cp_params['name'],
monitor = val_to_monitor,
verbose = verbose,
mode = 'max',
save_best_only = cp_params['save_best_only'],
save_weights_only = cp_params['save_weights_only'],
period = cp_params['period'])
#Earlystopping callback
es_params = params['early_stopping']
EarlyStop = EarlyStopping(
monitor=val_to_monitor,
verbose=verbose,
baseline = None,
min_delta = es_params['min_delta'],
patience = es_params['patience'],
restore_best_weights = es_params['restore_best_weights'])
#Reduce LR callback
lr_params = params['reduce_lr']
ReduceLR = ReduceLROnPlateau(
monitor = val_to_monitor,
verbose = verbose,
factor = lr_params['factor'],
patience = lr_params['patience'],
min_lr = lr_params['min_lr'])
#CSV logger callback
log_params = params['csv_logger']
Logger = CSVLogger(
log_params['name'],
separator = log_params['separator'],
append = log_params['append'])
TenBoard = TensorBoard(params['log_dir_name'])
return Checkpoint, EarlyStop, ReduceLR, Logger, TenBoard