Unverified 提交 8efe9771 authored 作者: Matthias's avatar Matthias 提交者: GitHub

Add `stop_training=False` flag to callbacks (#6365)

* 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: 's avatarGlenn Jocher <glenn.jocher@ultralytics.com>
上级 c43439aa
...@@ -352,6 +352,8 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary ...@@ -352,6 +352,8 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
pbar.set_description(('%10s' * 2 + '%10.4g' * 5) % ( pbar.set_description(('%10s' * 2 + '%10.4g' * 5) % (
f'{epoch}/{epochs - 1}', mem, *mloss, targets.shape[0], imgs.shape[-1])) f'{epoch}/{epochs - 1}', mem, *mloss, targets.shape[0], imgs.shape[-1]))
callbacks.run('on_train_batch_end', ni, model, imgs, targets, paths, plots, opt.sync_bn) callbacks.run('on_train_batch_end', ni, model, imgs, targets, paths, plots, opt.sync_bn)
if callbacks.stop_training:
return
# end batch ------------------------------------------------------------------------------------------------ # end batch ------------------------------------------------------------------------------------------------
# Scheduler # Scheduler
......
...@@ -35,6 +35,7 @@ class Callbacks: ...@@ -35,6 +35,7 @@ class Callbacks:
'on_params_update': [], 'on_params_update': [],
'teardown': [], 'teardown': [],
} }
self.stop_training = False # set True to interrupt training
def register_action(self, hook, name='', callback=None): def register_action(self, hook, name='', callback=None):
""" """
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论