Daemon plot_labels() for faster start (#9057)

* Daemon `plot_labels()` for faster start

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update train.py

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Glenn Jocherandpre-commit-ci[bot] authored and GitHub committed 2022-08-21 03:47:37 +02:00
1 parent 27fb6fd8fc
commit e0700cce77
5 files changed
+20 -18

No files matched your search

+9 -4
View File
@@ -3,6 +3,8 @@
Callback utils
"""
import threading
class Callbacks:
""""
@@ -55,17 +57,20 @@ class Callbacks:
"""
return self._callbacks[hook] if hook else self._callbacks
def run(self, hook, *args, **kwargs):
def run(self, hook, *args, thread=False, **kwargs):
"""
Loop through the registered actions and fire all callbacks
Loop through the registered actions and fire all callbacks on main thread
Args:
hook: The name of the hook to check, defaults to all
args: Arguments to receive from YOLOv5
thread: (boolean) Run callbacks in daemon thread
kwargs: Keyword Arguments to receive from YOLOv5
"""
assert hook in self._callbacks, f"hook '{hook}' not found in callbacks {self._callbacks}"
for logger in self._callbacks[hook]:
logger['callback'](*args, **kwargs)
if thread:
threading.Thread(target=logger['callback'], args=args, kwargs=kwargs, daemon=True).start()
else:
logger['callback'](*args, **kwargs)