Add `stop_training=False` flag to callbacks (#6365)
Browse files* New flag 'stop_training' in util.callbacks.Callbacks class to prematurely stop training from callback handler
* Removed most of the new checks, leaving only the one after calling 'on_train_batch_end'
* Cleanup
Co-authored-by: Glenn Jocher <[email protected]>
- train.py +2 -0
- utils/callbacks.py +1 -0
train.py
CHANGED
@@ -352,6 +352,8 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
|
|
352 |
pbar.set_description(('%10s' * 2 + '%10.4g' * 5) % (
|
353 |
f'{epoch}/{epochs - 1}', mem, *mloss, targets.shape[0], imgs.shape[-1]))
|
354 |
callbacks.run('on_train_batch_end', ni, model, imgs, targets, paths, plots, opt.sync_bn)
|
|
|
|
|
355 |
# end batch ------------------------------------------------------------------------------------------------
|
356 |
|
357 |
# Scheduler
|
|
|
352 |
pbar.set_description(('%10s' * 2 + '%10.4g' * 5) % (
|
353 |
f'{epoch}/{epochs - 1}', mem, *mloss, targets.shape[0], imgs.shape[-1]))
|
354 |
callbacks.run('on_train_batch_end', ni, model, imgs, targets, paths, plots, opt.sync_bn)
|
355 |
+
if callbacks.stop_training:
|
356 |
+
return
|
357 |
# end batch ------------------------------------------------------------------------------------------------
|
358 |
|
359 |
# Scheduler
|
utils/callbacks.py
CHANGED
@@ -35,6 +35,7 @@ class Callbacks:
|
|
35 |
'on_params_update': [],
|
36 |
'teardown': [],
|
37 |
}
|
|
|
38 |
|
39 |
def register_action(self, hook, name='', callback=None):
|
40 |
"""
|
|
|
35 |
'on_params_update': [],
|
36 |
'teardown': [],
|
37 |
}
|
38 |
+
self.stop_training = False # set True to interrupt training
|
39 |
|
40 |
def register_action(self, hook, name='', callback=None):
|
41 |
"""
|