* Refactor code for speed and clarity

* Update README.zh-CN.md

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

---------

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
Glenn JocherandUltralyticsAssistant authored and GitHub committed 2024-08-26 15:46:32 +02:00
1 parent b40781b3e3
commit c5ffbbf1c3
20 files changed
+164 -73

No files matched your search

+6 -3
View File
@@ -188,7 +188,8 @@ CONFIG_DIR = user_config_dir() # Ultralytics settings dir
class Profile(contextlib.ContextDecorator):
# YOLOv5 Profile class. Usage: @Profile() decorator or 'with Profile():' context manager
"""Context manager and decorator for profiling code execution time, with optional CUDA synchronization."""
def __init__(self, t=0.0, device: torch.device = None):
"""Initializes a profiling context for YOLOv5 with optional timing threshold and device specification."""
self.t = t
@@ -213,7 +214,8 @@ class Profile(contextlib.ContextDecorator):
class Timeout(contextlib.ContextDecorator):
# YOLOv5 Timeout class. Usage: @Timeout(seconds) decorator or 'with Timeout(seconds):' context manager
"""Enforces a timeout on code execution, raising TimeoutError if the specified duration is exceeded."""
def __init__(self, seconds, *, timeout_msg="", suppress_timeout_errors=True):
"""Initializes a timeout context/decorator with defined seconds, optional message, and error suppression."""
self.seconds = int(seconds)
@@ -239,7 +241,8 @@ class Timeout(contextlib.ContextDecorator):
class WorkingDirectory(contextlib.ContextDecorator):
# Usage: @WorkingDirectory(dir) decorator or 'with WorkingDirectory(dir):' context manager
"""Context manager/decorator to temporarily change the working directory within a 'with' statement or decorator."""
def __init__(self, new_dir):
"""Initializes a context manager/decorator to temporarily change the working directory."""
self.dir = new_dir # new dir