-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallbacks.py
More file actions
20 lines (18 loc) · 780 Bytes
/
callbacks.py
File metadata and controls
20 lines (18 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from keras.callbacks import ModelCheckpoint
class SavePeriodicCheckpoint(ModelCheckpoint):
def __init__(self, filepath, monitor='val_loss', verbose=0,
n_epochs=5, save_weights_only=False,
mode='auto'):
super(SavePeriodicCheckpoint, self).__init__(
filepath=filepath, monitor=monitor, verbose=verbose,
save_weights_only=save_weights_only,
mode=mode, save_best_only=False)
self.n_epochs = n_epochs
self.current_epoch = 0
def on_epoch_end(self, epoch, logs={}):
self.current_epoch += 1
if self.current_epoch % self.n_epochs == 0:
super(SavePeriodicCheckpoint, self).on_epoch_end(
epoch=epoch, logs=logs)
else:
pass