def init_callbacks(self, for_worker=False):
"""Prepares all keras callbacks to be used in training.
Automatically attaches a History callback to the end of the callback list.
If for_worker is True, leaves out callbacks that only make sense
with validation enabled."""
import keras.callbacks as cbks
remove_for_worker = [cbks.EarlyStopping, cbks.ModelCheckpoint]
if for_worker:
for obj in remove_for_worker:
self.callbacks_list = [ c for c in self.callbacks_list
if not isinstance(c, obj) ]
self.model.history = cbks.History()
self.callbacks = cbks.CallbackList( self.callbacks_list + [self.model.history] )
# it's possible to callback a different model than self
# (used by Sequential models)
if hasattr(self.model, 'callback_model') and self.model.callback_model:
self.callback_model = self.model.callback_model
else:
self.callback_model = self.model
self.callbacks.set_model(self.callback_model)
self.callback_model.stop_training = False
评论列表
文章目录