Browse Source

Simplify callbacks.py return (#7333)

* Simplify callbacks.py return

* Indent args (pytorch convention)

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

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

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
modifyDataloader
Glenn Jocher GitHub 2 years ago
parent
commit
676e10cf1a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 11 deletions
  1. +8
    -11
      utils/callbacks.py

+ 8
- 11
utils/callbacks.py View File

Register a new action to a callback hook Register a new action to a callback hook


Args: Args:
hook The callback hook name to register the action to
name The name of the action for later reference
callback The callback to fire
hook: The callback hook name to register the action to
name: The name of the action for later reference
callback: The callback to fire
""" """
assert hook in self._callbacks, f"hook '{hook}' not found in callbacks {self._callbacks}" assert hook in self._callbacks, f"hook '{hook}' not found in callbacks {self._callbacks}"
assert callable(callback), f"callback '{callback}' is not callable" assert callable(callback), f"callback '{callback}' is not callable"
Returns all the registered actions by callback hook Returns all the registered actions by callback hook


Args: Args:
hook The name of the hook to check, defaults to all
hook: The name of the hook to check, defaults to all
""" """
if hook:
return self._callbacks[hook]
else:
return self._callbacks
return self._callbacks[hook] if hook else self._callbacks


def run(self, hook, *args, **kwargs): def run(self, hook, *args, **kwargs):
""" """
Loop through the registered actions and fire all callbacks Loop through the registered actions and fire all callbacks


Args: Args:
hook The name of the hook to check, defaults to all
args Arguments to receive from YOLOv5
kwargs Keyword Arguments to receive from YOLOv5
hook: The name of the hook to check, defaults to all
args: Arguments to receive from YOLOv5
kwargs: Keyword Arguments to receive from YOLOv5
""" """


assert hook in self._callbacks, f"hook '{hook}' not found in callbacks {self._callbacks}" assert hook in self._callbacks, f"hook '{hook}' not found in callbacks {self._callbacks}"

Loading…
Cancel
Save