Public Member Functions | Public Attributes | List of all members
my_callbacks.MultiGPUCheckpointCallback Class Reference
Inheritance diagram for my_callbacks.MultiGPUCheckpointCallback:

Public Member Functions

def __init__ (self, filepath, base_model, monitor='val_loss', verbose=0, save_best_only=False, save_weights_only=False, mode='auto', period=1)
 
def on_epoch_end (self, epoch, logs=None)
 

Public Attributes

 base_model
 
 monitor
 
 verbose
 
 filepath
 
 save_best_only
 
 save_weights_only
 
 period
 
 epochs_since_last_save
 
 monitor_op
 
 best
 

Detailed Description

Definition at line 7 of file my_callbacks.py.

Constructor & Destructor Documentation

def my_callbacks.MultiGPUCheckpointCallback.__init__ (   self,
  filepath,
  base_model,
  monitor = 'val_loss',
  verbose = 0,
  save_best_only = False,
  save_weights_only = False,
  mode = 'auto',
  period = 1 
)

Definition at line 11 of file my_callbacks.py.

11  mode='auto', period=1):
12  super(MultiGPUCheckpointCallback, self).__init__()
13  self.base_model = base_model
14  self.monitor = monitor
15  self.verbose = verbose
16  self.filepath = filepath
17  self.save_best_only = save_best_only
18  self.save_weights_only = save_weights_only
19  self.period = period
21 
22  if mode not in ['auto', 'min', 'max']:
23  warnings.warn('ModelCheckpoint mode %s is unknown, '
24  'fallback to auto mode.' % (mode),
25  RuntimeWarning)
26  mode = 'auto'
27 
28  if mode == 'min':
29  self.monitor_op = np.less
30  self.best = np.Inf
31  elif mode == 'max':
32  self.monitor_op = np.greater
33  self.best = -np.Inf
34  else:
35  if 'acc' in self.monitor or self.monitor.startswith('fmeasure'):
36  self.monitor_op = np.greater
37  self.best = -np.Inf
38  else:
39  self.monitor_op = np.less
40  self.best = np.Inf
41 
def __init__(self, filepath, base_model, monitor='val_loss', verbose=0, save_best_only=False, save_weights_only=False, mode='auto', period=1)
Definition: my_callbacks.py:11

Member Function Documentation

def my_callbacks.MultiGPUCheckpointCallback.on_epoch_end (   self,
  epoch,
  logs = None 
)

Definition at line 42 of file my_callbacks.py.

42  def on_epoch_end(self, epoch, logs=None):
43 
44  logs = logs or {}
45  self.epochs_since_last_save += 1
46  if self.epochs_since_last_save >= self.period:
47  self.epochs_since_last_save = 0
48  filepath = self.filepath.format(epoch=epoch + 1, **logs)
49  if self.save_best_only:
50  current = logs.get(self.monitor)
51  if current is None:
52  warnings.warn('Can save best model only with %s available, '
53  'skipping.' % (self.monitor), RuntimeWarning)
54  else:
55  if self.monitor_op(current, self.best):
56  if self.verbose > 0:
57  print('Epoch %05d: %s improved from %0.5f to %0.5f,'
58  ' saving model to %s'
59  % (epoch + 1, self.monitor, self.best,
60  current, filepath))
61  self.best = current
62  if self.save_weights_only:
63  self.base_model.save_weights(filepath, overwrite=True)
64  else:
65  self.base_model.save(filepath, overwrite=True)
66  else:
67  if self.verbose > 0:
68  print('Epoch %05d: %s did not improve' %
69  (epoch + 1, self.monitor))
70  else:
71  if self.verbose > 0:
72  print('Epoch %05d: saving model to %s' % (epoch + 1, filepath))
73  if self.save_weights_only:
74  self.base_model.save_weights(filepath, overwrite=True)
75  else:
76  self.base_model.save(filepath, overwrite=True)
77 
def on_epoch_end(self, epoch, logs=None)
Definition: my_callbacks.py:42

Member Data Documentation

my_callbacks.MultiGPUCheckpointCallback.base_model

Definition at line 13 of file my_callbacks.py.

my_callbacks.MultiGPUCheckpointCallback.best

Definition at line 30 of file my_callbacks.py.

my_callbacks.MultiGPUCheckpointCallback.epochs_since_last_save

Definition at line 20 of file my_callbacks.py.

my_callbacks.MultiGPUCheckpointCallback.filepath

Definition at line 16 of file my_callbacks.py.

my_callbacks.MultiGPUCheckpointCallback.monitor

Definition at line 14 of file my_callbacks.py.

my_callbacks.MultiGPUCheckpointCallback.monitor_op

Definition at line 29 of file my_callbacks.py.

my_callbacks.MultiGPUCheckpointCallback.period

Definition at line 19 of file my_callbacks.py.

my_callbacks.MultiGPUCheckpointCallback.save_best_only

Definition at line 17 of file my_callbacks.py.

my_callbacks.MultiGPUCheckpointCallback.save_weights_only

Definition at line 18 of file my_callbacks.py.

my_callbacks.MultiGPUCheckpointCallback.verbose

Definition at line 15 of file my_callbacks.py.


The documentation for this class was generated from the following file: