dgenerate-ultralytics-headless 8.3.214__py3-none-any.whl → 8.4.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. {dgenerate_ultralytics_headless-8.3.214.dist-info → dgenerate_ultralytics_headless-8.4.7.dist-info}/METADATA +64 -74
  2. dgenerate_ultralytics_headless-8.4.7.dist-info/RECORD +311 -0
  3. {dgenerate_ultralytics_headless-8.3.214.dist-info → dgenerate_ultralytics_headless-8.4.7.dist-info}/WHEEL +1 -1
  4. tests/__init__.py +7 -9
  5. tests/conftest.py +8 -15
  6. tests/test_cli.py +1 -1
  7. tests/test_cuda.py +13 -10
  8. tests/test_engine.py +9 -9
  9. tests/test_exports.py +65 -13
  10. tests/test_integrations.py +13 -13
  11. tests/test_python.py +125 -69
  12. tests/test_solutions.py +161 -152
  13. ultralytics/__init__.py +1 -1
  14. ultralytics/cfg/__init__.py +86 -92
  15. ultralytics/cfg/datasets/Argoverse.yaml +7 -6
  16. ultralytics/cfg/datasets/DOTAv1.5.yaml +1 -1
  17. ultralytics/cfg/datasets/DOTAv1.yaml +1 -1
  18. ultralytics/cfg/datasets/ImageNet.yaml +1 -1
  19. ultralytics/cfg/datasets/TT100K.yaml +346 -0
  20. ultralytics/cfg/datasets/VOC.yaml +15 -16
  21. ultralytics/cfg/datasets/african-wildlife.yaml +1 -1
  22. ultralytics/cfg/datasets/coco-pose.yaml +21 -0
  23. ultralytics/cfg/datasets/coco12-formats.yaml +101 -0
  24. ultralytics/cfg/datasets/coco128-seg.yaml +1 -1
  25. ultralytics/cfg/datasets/coco8-pose.yaml +21 -0
  26. ultralytics/cfg/datasets/dog-pose.yaml +28 -0
  27. ultralytics/cfg/datasets/dota8-multispectral.yaml +1 -1
  28. ultralytics/cfg/datasets/dota8.yaml +2 -2
  29. ultralytics/cfg/datasets/hand-keypoints.yaml +26 -2
  30. ultralytics/cfg/datasets/kitti.yaml +27 -0
  31. ultralytics/cfg/datasets/lvis.yaml +5 -5
  32. ultralytics/cfg/datasets/open-images-v7.yaml +1 -1
  33. ultralytics/cfg/datasets/tiger-pose.yaml +16 -0
  34. ultralytics/cfg/datasets/xView.yaml +16 -16
  35. ultralytics/cfg/default.yaml +4 -2
  36. ultralytics/cfg/models/11/yolo11-pose.yaml +1 -1
  37. ultralytics/cfg/models/11/yoloe-11-seg.yaml +2 -2
  38. ultralytics/cfg/models/11/yoloe-11.yaml +2 -2
  39. ultralytics/cfg/models/26/yolo26-cls.yaml +33 -0
  40. ultralytics/cfg/models/26/yolo26-obb.yaml +52 -0
  41. ultralytics/cfg/models/26/yolo26-p2.yaml +60 -0
  42. ultralytics/cfg/models/26/yolo26-p6.yaml +62 -0
  43. ultralytics/cfg/models/26/yolo26-pose.yaml +53 -0
  44. ultralytics/cfg/models/26/yolo26-seg.yaml +52 -0
  45. ultralytics/cfg/models/26/yolo26.yaml +52 -0
  46. ultralytics/cfg/models/26/yoloe-26-seg.yaml +53 -0
  47. ultralytics/cfg/models/26/yoloe-26.yaml +53 -0
  48. ultralytics/cfg/models/rt-detr/rtdetr-l.yaml +1 -1
  49. ultralytics/cfg/models/rt-detr/rtdetr-resnet101.yaml +1 -1
  50. ultralytics/cfg/models/rt-detr/rtdetr-resnet50.yaml +1 -1
  51. ultralytics/cfg/models/rt-detr/rtdetr-x.yaml +1 -1
  52. ultralytics/cfg/models/v10/yolov10b.yaml +2 -2
  53. ultralytics/cfg/models/v10/yolov10l.yaml +2 -2
  54. ultralytics/cfg/models/v10/yolov10m.yaml +2 -2
  55. ultralytics/cfg/models/v10/yolov10n.yaml +2 -2
  56. ultralytics/cfg/models/v10/yolov10s.yaml +2 -2
  57. ultralytics/cfg/models/v10/yolov10x.yaml +2 -2
  58. ultralytics/cfg/models/v3/yolov3-tiny.yaml +1 -1
  59. ultralytics/cfg/models/v6/yolov6.yaml +1 -1
  60. ultralytics/cfg/models/v8/yoloe-v8-seg.yaml +9 -6
  61. ultralytics/cfg/models/v8/yoloe-v8.yaml +9 -6
  62. ultralytics/cfg/models/v8/yolov8-cls-resnet101.yaml +1 -1
  63. ultralytics/cfg/models/v8/yolov8-cls-resnet50.yaml +1 -1
  64. ultralytics/cfg/models/v8/yolov8-ghost-p2.yaml +2 -2
  65. ultralytics/cfg/models/v8/yolov8-ghost-p6.yaml +2 -2
  66. ultralytics/cfg/models/v8/yolov8-ghost.yaml +2 -2
  67. ultralytics/cfg/models/v8/yolov8-obb.yaml +1 -1
  68. ultralytics/cfg/models/v8/yolov8-p2.yaml +1 -1
  69. ultralytics/cfg/models/v8/yolov8-pose-p6.yaml +1 -1
  70. ultralytics/cfg/models/v8/yolov8-rtdetr.yaml +1 -1
  71. ultralytics/cfg/models/v8/yolov8-seg-p6.yaml +1 -1
  72. ultralytics/cfg/models/v8/yolov8-world.yaml +1 -1
  73. ultralytics/cfg/models/v8/yolov8-worldv2.yaml +6 -6
  74. ultralytics/cfg/models/v9/yolov9s.yaml +1 -1
  75. ultralytics/data/__init__.py +4 -4
  76. ultralytics/data/annotator.py +5 -6
  77. ultralytics/data/augment.py +300 -475
  78. ultralytics/data/base.py +18 -26
  79. ultralytics/data/build.py +147 -25
  80. ultralytics/data/converter.py +108 -87
  81. ultralytics/data/dataset.py +47 -75
  82. ultralytics/data/loaders.py +42 -49
  83. ultralytics/data/split.py +5 -6
  84. ultralytics/data/split_dota.py +8 -15
  85. ultralytics/data/utils.py +36 -45
  86. ultralytics/engine/exporter.py +351 -263
  87. ultralytics/engine/model.py +186 -225
  88. ultralytics/engine/predictor.py +45 -54
  89. ultralytics/engine/results.py +198 -325
  90. ultralytics/engine/trainer.py +165 -106
  91. ultralytics/engine/tuner.py +41 -43
  92. ultralytics/engine/validator.py +55 -38
  93. ultralytics/hub/__init__.py +16 -19
  94. ultralytics/hub/auth.py +6 -12
  95. ultralytics/hub/google/__init__.py +7 -10
  96. ultralytics/hub/session.py +15 -25
  97. ultralytics/hub/utils.py +5 -8
  98. ultralytics/models/__init__.py +1 -1
  99. ultralytics/models/fastsam/__init__.py +1 -1
  100. ultralytics/models/fastsam/model.py +8 -10
  101. ultralytics/models/fastsam/predict.py +18 -30
  102. ultralytics/models/fastsam/utils.py +1 -2
  103. ultralytics/models/fastsam/val.py +5 -7
  104. ultralytics/models/nas/__init__.py +1 -1
  105. ultralytics/models/nas/model.py +5 -8
  106. ultralytics/models/nas/predict.py +7 -9
  107. ultralytics/models/nas/val.py +1 -2
  108. ultralytics/models/rtdetr/__init__.py +1 -1
  109. ultralytics/models/rtdetr/model.py +5 -8
  110. ultralytics/models/rtdetr/predict.py +15 -19
  111. ultralytics/models/rtdetr/train.py +10 -13
  112. ultralytics/models/rtdetr/val.py +21 -23
  113. ultralytics/models/sam/__init__.py +15 -2
  114. ultralytics/models/sam/amg.py +14 -20
  115. ultralytics/models/sam/build.py +26 -19
  116. ultralytics/models/sam/build_sam3.py +377 -0
  117. ultralytics/models/sam/model.py +29 -32
  118. ultralytics/models/sam/modules/blocks.py +83 -144
  119. ultralytics/models/sam/modules/decoders.py +19 -37
  120. ultralytics/models/sam/modules/encoders.py +44 -101
  121. ultralytics/models/sam/modules/memory_attention.py +16 -30
  122. ultralytics/models/sam/modules/sam.py +200 -73
  123. ultralytics/models/sam/modules/tiny_encoder.py +64 -83
  124. ultralytics/models/sam/modules/transformer.py +18 -28
  125. ultralytics/models/sam/modules/utils.py +174 -50
  126. ultralytics/models/sam/predict.py +2248 -350
  127. ultralytics/models/sam/sam3/__init__.py +3 -0
  128. ultralytics/models/sam/sam3/decoder.py +546 -0
  129. ultralytics/models/sam/sam3/encoder.py +529 -0
  130. ultralytics/models/sam/sam3/geometry_encoders.py +415 -0
  131. ultralytics/models/sam/sam3/maskformer_segmentation.py +286 -0
  132. ultralytics/models/sam/sam3/model_misc.py +199 -0
  133. ultralytics/models/sam/sam3/necks.py +129 -0
  134. ultralytics/models/sam/sam3/sam3_image.py +339 -0
  135. ultralytics/models/sam/sam3/text_encoder_ve.py +307 -0
  136. ultralytics/models/sam/sam3/vitdet.py +547 -0
  137. ultralytics/models/sam/sam3/vl_combiner.py +160 -0
  138. ultralytics/models/utils/loss.py +14 -26
  139. ultralytics/models/utils/ops.py +13 -17
  140. ultralytics/models/yolo/__init__.py +1 -1
  141. ultralytics/models/yolo/classify/predict.py +10 -13
  142. ultralytics/models/yolo/classify/train.py +12 -33
  143. ultralytics/models/yolo/classify/val.py +30 -29
  144. ultralytics/models/yolo/detect/predict.py +9 -12
  145. ultralytics/models/yolo/detect/train.py +17 -23
  146. ultralytics/models/yolo/detect/val.py +77 -59
  147. ultralytics/models/yolo/model.py +43 -60
  148. ultralytics/models/yolo/obb/predict.py +7 -16
  149. ultralytics/models/yolo/obb/train.py +14 -17
  150. ultralytics/models/yolo/obb/val.py +40 -37
  151. ultralytics/models/yolo/pose/__init__.py +1 -1
  152. ultralytics/models/yolo/pose/predict.py +7 -22
  153. ultralytics/models/yolo/pose/train.py +13 -16
  154. ultralytics/models/yolo/pose/val.py +39 -58
  155. ultralytics/models/yolo/segment/predict.py +17 -21
  156. ultralytics/models/yolo/segment/train.py +7 -10
  157. ultralytics/models/yolo/segment/val.py +95 -47
  158. ultralytics/models/yolo/world/train.py +8 -14
  159. ultralytics/models/yolo/world/train_world.py +11 -34
  160. ultralytics/models/yolo/yoloe/__init__.py +7 -7
  161. ultralytics/models/yolo/yoloe/predict.py +16 -23
  162. ultralytics/models/yolo/yoloe/train.py +36 -44
  163. ultralytics/models/yolo/yoloe/train_seg.py +11 -11
  164. ultralytics/models/yolo/yoloe/val.py +15 -20
  165. ultralytics/nn/__init__.py +7 -7
  166. ultralytics/nn/autobackend.py +159 -85
  167. ultralytics/nn/modules/__init__.py +68 -60
  168. ultralytics/nn/modules/activation.py +4 -6
  169. ultralytics/nn/modules/block.py +260 -224
  170. ultralytics/nn/modules/conv.py +52 -97
  171. ultralytics/nn/modules/head.py +831 -299
  172. ultralytics/nn/modules/transformer.py +76 -88
  173. ultralytics/nn/modules/utils.py +16 -21
  174. ultralytics/nn/tasks.py +180 -195
  175. ultralytics/nn/text_model.py +45 -69
  176. ultralytics/optim/__init__.py +5 -0
  177. ultralytics/optim/muon.py +338 -0
  178. ultralytics/solutions/__init__.py +12 -12
  179. ultralytics/solutions/ai_gym.py +13 -19
  180. ultralytics/solutions/analytics.py +15 -16
  181. ultralytics/solutions/config.py +6 -7
  182. ultralytics/solutions/distance_calculation.py +10 -13
  183. ultralytics/solutions/heatmap.py +8 -14
  184. ultralytics/solutions/instance_segmentation.py +6 -9
  185. ultralytics/solutions/object_blurrer.py +7 -10
  186. ultralytics/solutions/object_counter.py +12 -19
  187. ultralytics/solutions/object_cropper.py +8 -14
  188. ultralytics/solutions/parking_management.py +34 -32
  189. ultralytics/solutions/queue_management.py +10 -12
  190. ultralytics/solutions/region_counter.py +9 -12
  191. ultralytics/solutions/security_alarm.py +15 -20
  192. ultralytics/solutions/similarity_search.py +10 -15
  193. ultralytics/solutions/solutions.py +77 -76
  194. ultralytics/solutions/speed_estimation.py +7 -10
  195. ultralytics/solutions/streamlit_inference.py +2 -4
  196. ultralytics/solutions/templates/similarity-search.html +7 -18
  197. ultralytics/solutions/trackzone.py +7 -10
  198. ultralytics/solutions/vision_eye.py +5 -8
  199. ultralytics/trackers/__init__.py +1 -1
  200. ultralytics/trackers/basetrack.py +3 -5
  201. ultralytics/trackers/bot_sort.py +10 -27
  202. ultralytics/trackers/byte_tracker.py +21 -37
  203. ultralytics/trackers/track.py +4 -7
  204. ultralytics/trackers/utils/gmc.py +11 -22
  205. ultralytics/trackers/utils/kalman_filter.py +37 -48
  206. ultralytics/trackers/utils/matching.py +12 -15
  207. ultralytics/utils/__init__.py +124 -124
  208. ultralytics/utils/autobatch.py +2 -4
  209. ultralytics/utils/autodevice.py +17 -18
  210. ultralytics/utils/benchmarks.py +57 -71
  211. ultralytics/utils/callbacks/base.py +8 -10
  212. ultralytics/utils/callbacks/clearml.py +5 -13
  213. ultralytics/utils/callbacks/comet.py +32 -46
  214. ultralytics/utils/callbacks/dvc.py +13 -18
  215. ultralytics/utils/callbacks/mlflow.py +4 -5
  216. ultralytics/utils/callbacks/neptune.py +7 -15
  217. ultralytics/utils/callbacks/platform.py +423 -38
  218. ultralytics/utils/callbacks/raytune.py +3 -4
  219. ultralytics/utils/callbacks/tensorboard.py +25 -31
  220. ultralytics/utils/callbacks/wb.py +16 -14
  221. ultralytics/utils/checks.py +127 -85
  222. ultralytics/utils/cpu.py +3 -8
  223. ultralytics/utils/dist.py +9 -12
  224. ultralytics/utils/downloads.py +25 -33
  225. ultralytics/utils/errors.py +6 -14
  226. ultralytics/utils/events.py +2 -4
  227. ultralytics/utils/export/__init__.py +4 -236
  228. ultralytics/utils/export/engine.py +246 -0
  229. ultralytics/utils/export/imx.py +117 -63
  230. ultralytics/utils/export/tensorflow.py +231 -0
  231. ultralytics/utils/files.py +26 -30
  232. ultralytics/utils/git.py +9 -11
  233. ultralytics/utils/instance.py +30 -51
  234. ultralytics/utils/logger.py +212 -114
  235. ultralytics/utils/loss.py +601 -215
  236. ultralytics/utils/metrics.py +128 -156
  237. ultralytics/utils/nms.py +13 -16
  238. ultralytics/utils/ops.py +117 -166
  239. ultralytics/utils/patches.py +75 -21
  240. ultralytics/utils/plotting.py +75 -80
  241. ultralytics/utils/tal.py +125 -59
  242. ultralytics/utils/torch_utils.py +53 -79
  243. ultralytics/utils/tqdm.py +24 -21
  244. ultralytics/utils/triton.py +13 -19
  245. ultralytics/utils/tuner.py +19 -10
  246. dgenerate_ultralytics_headless-8.3.214.dist-info/RECORD +0 -283
  247. {dgenerate_ultralytics_headless-8.3.214.dist-info → dgenerate_ultralytics_headless-8.4.7.dist-info}/entry_points.txt +0 -0
  248. {dgenerate_ultralytics_headless-8.3.214.dist-info → dgenerate_ultralytics_headless-8.4.7.dist-info}/licenses/LICENSE +0 -0
  249. {dgenerate_ultralytics_headless-8.3.214.dist-info → dgenerate_ultralytics_headless-8.4.7.dist-info}/top_level.txt +0 -0
@@ -7,14 +7,13 @@ from ultralytics.solutions.solutions import BaseSolution, SolutionAnnotator, Sol
7
7
 
8
8
 
9
9
  class AIGym(BaseSolution):
10
- """
11
- A class to manage gym steps of people in a real-time video stream based on their poses.
10
+ """A class to manage gym steps of people in a real-time video stream based on their poses.
12
11
 
13
12
  This class extends BaseSolution to monitor workouts using YOLO pose estimation models. It tracks and counts
14
13
  repetitions of exercises based on predefined angle thresholds for up and down positions.
15
14
 
16
15
  Attributes:
17
- states (dict[float, int, str]): Stores per-track angle, count, and stage for workout monitoring.
16
+ states (dict[int, dict[str, float | int | str]]): Per-track angle, rep count, and stage for workout monitoring.
18
17
  up_angle (float): Angle threshold for considering the 'up' position of an exercise.
19
18
  down_angle (float): Angle threshold for considering the 'down' position of an exercise.
20
19
  kpts (list[int]): Indices of keypoints used for angle calculation.
@@ -23,7 +22,7 @@ class AIGym(BaseSolution):
23
22
  process: Process a frame to detect poses, calculate angles, and count repetitions.
24
23
 
25
24
  Examples:
26
- >>> gym = AIGym(model="yolo11n-pose.pt")
25
+ >>> gym = AIGym(model="yolo26n-pose.pt")
27
26
  >>> image = cv2.imread("gym_scene.jpg")
28
27
  >>> results = gym.process(image)
29
28
  >>> processed_image = results.plot_im
@@ -32,14 +31,13 @@ class AIGym(BaseSolution):
32
31
  """
33
32
 
34
33
  def __init__(self, **kwargs: Any) -> None:
35
- """
36
- Initialize AIGym for workout monitoring using pose estimation and predefined angles.
34
+ """Initialize AIGym for workout monitoring using pose estimation and predefined angles.
37
35
 
38
36
  Args:
39
- **kwargs (Any): Keyword arguments passed to the parent class constructor.
40
- model (str): Model name or path, defaults to "yolo11n-pose.pt".
37
+ **kwargs (Any): Keyword arguments passed to the parent class constructor including:
38
+ - model (str): Model name or path, defaults to "yolo26n-pose.pt".
41
39
  """
42
- kwargs["model"] = kwargs.get("model", "yolo11n-pose.pt")
40
+ kwargs["model"] = kwargs.get("model", "yolo26n-pose.pt")
43
41
  super().__init__(**kwargs)
44
42
  self.states = defaultdict(lambda: {"angle": 0, "count": 0, "stage": "-"}) # Dict for count, angle and stage
45
43
 
@@ -49,22 +47,18 @@ class AIGym(BaseSolution):
49
47
  self.kpts = self.CFG["kpts"] # User selected kpts of workouts storage for further usage
50
48
 
51
49
  def process(self, im0) -> SolutionResults:
52
- """
53
- Monitor workouts using Ultralytics YOLO Pose Model.
50
+ """Monitor workouts using Ultralytics YOLO Pose Model.
54
51
 
55
- This function processes an input image to track and analyze human poses for workout monitoring. It uses
56
- the YOLO Pose model to detect keypoints, estimate angles, and count repetitions based on predefined
57
- angle thresholds.
52
+ This function processes an input image to track and analyze human poses for workout monitoring. It uses the YOLO
53
+ Pose model to detect keypoints, estimate angles, and count repetitions based on predefined angle thresholds.
58
54
 
59
55
  Args:
60
56
  im0 (np.ndarray): Input image for processing.
61
57
 
62
58
  Returns:
63
- (SolutionResults): Contains processed image `plot_im`,
64
- 'workout_count' (list of completed reps),
65
- 'workout_stage' (list of current stages),
66
- 'workout_angle' (list of angles), and
67
- 'total_tracks' (total number of tracked individuals).
59
+ (SolutionResults): Contains processed image `plot_im`, 'workout_count' (list of completed reps),
60
+ 'workout_stage' (list of current stages), 'workout_angle' (list of angles), and 'total_tracks' (total
61
+ number of tracked individuals).
68
62
 
69
63
  Examples:
70
64
  >>> gym = AIGym()
@@ -9,14 +9,14 @@ import cv2
9
9
  import numpy as np
10
10
 
11
11
  from ultralytics.solutions.solutions import BaseSolution, SolutionResults # Import a parent class
12
+ from ultralytics.utils import plt_settings
12
13
 
13
14
 
14
15
  class Analytics(BaseSolution):
15
- """
16
- A class for creating and updating various types of charts for visual analytics.
16
+ """A class for creating and updating various types of charts for visual analytics.
17
17
 
18
- This class extends BaseSolution to provide functionality for generating line, bar, pie, and area charts
19
- based on object detection and tracking data.
18
+ This class extends BaseSolution to provide functionality for generating line, bar, pie, and area charts based on
19
+ object detection and tracking data.
20
20
 
21
21
  Attributes:
22
22
  type (str): The type of analytics chart to generate ('line', 'bar', 'pie', or 'area').
@@ -47,6 +47,7 @@ class Analytics(BaseSolution):
47
47
  >>> cv2.imshow("Analytics", results.plot_im)
48
48
  """
49
49
 
50
+ @plt_settings()
50
51
  def __init__(self, **kwargs: Any) -> None:
51
52
  """Initialize Analytics class with various chart types for visual data representation."""
52
53
  super().__init__(**kwargs)
@@ -55,7 +56,7 @@ class Analytics(BaseSolution):
55
56
  from matplotlib.backends.backend_agg import FigureCanvasAgg
56
57
  from matplotlib.figure import Figure
57
58
 
58
- self.type = self.CFG["analytics_type"] # type of analytics i.e "line", "pie", "bar" or "area" charts.
59
+ self.type = self.CFG["analytics_type"] # Chart type: "line", "pie", "bar", or "area".
59
60
  self.x_label = "Classes" if self.type in {"bar", "pie"} else "Frame#"
60
61
  self.y_label = "Total Counts"
61
62
 
@@ -65,10 +66,10 @@ class Analytics(BaseSolution):
65
66
  self.title = "Ultralytics Solutions" # window name
66
67
  self.max_points = 45 # maximum points to be drawn on window
67
68
  self.fontsize = 25 # text font size for display
68
- figsize = self.CFG["figsize"] # set output image size i.e (12.8, 7.2) -> w = 1280, h = 720
69
+ figsize = self.CFG["figsize"] # Output size, e.g. (12.8, 7.2) -> 1280x720.
69
70
  self.color_cycle = cycle(["#DD00BA", "#042AFF", "#FF4447", "#7D24FF", "#BD00FF"])
70
71
 
71
- self.total_counts = 0 # count variable for storing total counts i.e. for line
72
+ self.total_counts = 0 # Stores total counts for line charts.
72
73
  self.clswise_count = {} # dictionary for class-wise counts
73
74
  self.update_every = kwargs.get("update_every", 30) # Only update graph every 30 frames by default
74
75
  self.last_plot_im = None # Cache of the last rendered chart
@@ -92,8 +93,7 @@ class Analytics(BaseSolution):
92
93
  self.ax.axis("equal")
93
94
 
94
95
  def process(self, im0: np.ndarray, frame_number: int) -> SolutionResults:
95
- """
96
- Process image data and run object tracking to update analytics charts.
96
+ """Process image data and run object tracking to update analytics charts.
97
97
 
98
98
  Args:
99
99
  im0 (np.ndarray): Input image for processing.
@@ -104,7 +104,7 @@ class Analytics(BaseSolution):
104
104
  and 'classwise_count' (dict, per-class object count).
105
105
 
106
106
  Raises:
107
- ModuleNotFoundError: If an unsupported chart type is specified.
107
+ ValueError: If an unsupported chart type is specified.
108
108
 
109
109
  Examples:
110
110
  >>> analytics = Analytics(analytics_type="line")
@@ -131,21 +131,20 @@ class Analytics(BaseSolution):
131
131
  )
132
132
  plot_im = self.last_plot_im
133
133
  else:
134
- raise ModuleNotFoundError(f"{self.type} chart is not supported ")
134
+ raise ValueError(f"Unsupported analytics_type='{self.type}'. Supported types: line, bar, pie, area.")
135
135
 
136
- # return output dictionary with summary for more usage
136
+ # Return results for downstream use.
137
137
  return SolutionResults(plot_im=plot_im, total_tracks=len(self.track_ids), classwise_count=self.clswise_count)
138
138
 
139
139
  def update_graph(
140
140
  self, frame_number: int, count_dict: dict[str, int] | None = None, plot: str = "line"
141
141
  ) -> np.ndarray:
142
- """
143
- Update the graph with new data for single or multiple classes.
142
+ """Update the graph with new data for single or multiple classes.
144
143
 
145
144
  Args:
146
145
  frame_number (int): The current frame number.
147
- count_dict (dict[str, int], optional): Dictionary with class names as keys and counts as values for
148
- multiple classes. If None, updates a single line graph.
146
+ count_dict (dict[str, int], optional): Dictionary with class names as keys and counts as values for multiple
147
+ classes. If None, updates a single line graph.
149
148
  plot (str): Type of the plot. Options are 'line', 'bar', 'pie', or 'area'.
150
149
 
151
150
  Returns:
@@ -10,12 +10,11 @@ import cv2
10
10
 
11
11
  @dataclass
12
12
  class SolutionConfig:
13
- """
14
- Manages configuration parameters for Ultralytics Vision AI solutions.
13
+ """Manages configuration parameters for Ultralytics Vision AI solutions.
15
14
 
16
- The SolutionConfig class serves as a centralized configuration container for all the
17
- Ultralytics solution modules: https://docs.ultralytics.com/solutions/#solutions.
18
- It leverages Python `dataclass` for clear, type-safe, and maintainable parameter definitions.
15
+ The SolutionConfig class serves as a centralized configuration container for all the Ultralytics solution modules:
16
+ https://docs.ultralytics.com/solutions/#solutions. It leverages Python `dataclass` for clear, type-safe, and
17
+ maintainable parameter definitions.
19
18
 
20
19
  Attributes:
21
20
  source (str, optional): Path to the input source (video, RTSP, etc.). Only usable with Solutions CLI.
@@ -36,7 +35,7 @@ class SolutionConfig:
36
35
  vision_point (tuple[int, int]): Reference point for directional tracking or perspective drawing.
37
36
  crop_dir (str): Directory path to save cropped detection images.
38
37
  json_file (str): Path to a JSON file containing data for parking areas.
39
- line_width (int): Width for visual display i.e. bounding boxes, keypoints, counts.
38
+ line_width (int): Width for visual display, e.g. bounding boxes, keypoints, and counts.
40
39
  records (int): Number of detection records to send email alerts.
41
40
  fps (float): Frame rate (Frames Per Second) for speed estimation calculation.
42
41
  max_hist (int): Maximum number of historical points or states stored per tracked object for speed estimation.
@@ -57,7 +56,7 @@ class SolutionConfig:
57
56
 
58
57
  Examples:
59
58
  >>> from ultralytics.solutions.config import SolutionConfig
60
- >>> cfg = SolutionConfig(model="yolo11n.pt", region=[(0, 0), (100, 0), (100, 100), (0, 100)])
59
+ >>> cfg = SolutionConfig(model="yolo26n.pt", region=[(0, 0), (100, 0), (100, 100), (0, 100)])
61
60
  >>> cfg.update(show=False, conf=0.3)
62
61
  >>> print(cfg.model)
63
62
  """
@@ -10,15 +10,14 @@ from ultralytics.utils.plotting import colors
10
10
 
11
11
 
12
12
  class DistanceCalculation(BaseSolution):
13
- """
14
- A class to calculate distance between two objects in a real-time video stream based on their tracks.
13
+ """A class to calculate distance between two objects in a real-time video stream based on their tracks.
15
14
 
16
- This class extends BaseSolution to provide functionality for selecting objects and calculating the distance
17
- between them in a video stream using YOLO object detection and tracking.
15
+ This class extends BaseSolution to provide functionality for selecting objects and calculating the distance between
16
+ them in a video stream using YOLO object detection and tracking.
18
17
 
19
18
  Attributes:
20
19
  left_mouse_count (int): Counter for left mouse button clicks.
21
- selected_boxes (dict[int, list[float]]): Dictionary to store selected bounding boxes and their track IDs.
20
+ selected_boxes (dict[int, Any]): Dictionary to store selected bounding boxes keyed by track ID.
22
21
  centroids (list[list[int]]): List to store centroids of selected bounding boxes.
23
22
 
24
23
  Methods:
@@ -43,8 +42,7 @@ class DistanceCalculation(BaseSolution):
43
42
  self.centroids: list[list[int]] = [] # Store centroids of selected objects
44
43
 
45
44
  def mouse_event_for_distance(self, event: int, x: int, y: int, flags: int, param: Any) -> None:
46
- """
47
- Handle mouse events to select regions in a real-time video stream for distance calculation.
45
+ """Handle mouse events to select regions in a real-time video stream for distance calculation.
48
46
 
49
47
  Args:
50
48
  event (int): Type of mouse event (e.g., cv2.EVENT_MOUSEMOVE, cv2.EVENT_LBUTTONDOWN).
@@ -69,18 +67,17 @@ class DistanceCalculation(BaseSolution):
69
67
  self.left_mouse_count = 0
70
68
 
71
69
  def process(self, im0) -> SolutionResults:
72
- """
73
- Process a video frame and calculate the distance between two selected bounding boxes.
70
+ """Process a video frame and calculate the distance between two selected bounding boxes.
74
71
 
75
- This method extracts tracks from the input frame, annotates bounding boxes, and calculates the distance
76
- between two user-selected objects if they have been chosen.
72
+ This method extracts tracks from the input frame, annotates bounding boxes, and calculates the distance between
73
+ two user-selected objects if they have been chosen.
77
74
 
78
75
  Args:
79
76
  im0 (np.ndarray): The input image frame to process.
80
77
 
81
78
  Returns:
82
- (SolutionResults): Contains processed image `plot_im`, `total_tracks` (int) representing the total number
83
- of tracked objects, and `pixels_distance` (float) representing the distance between selected objects
79
+ (SolutionResults): Contains processed image `plot_im`, `total_tracks` (int) representing the total number of
80
+ tracked objects, and `pixels_distance` (float) representing the distance between selected objects
84
81
  in pixels.
85
82
 
86
83
  Examples:
@@ -12,8 +12,7 @@ from ultralytics.solutions.solutions import SolutionAnnotator, SolutionResults
12
12
 
13
13
 
14
14
  class Heatmap(ObjectCounter):
15
- """
16
- A class to draw heatmaps in real-time video streams based on object tracks.
15
+ """A class to draw heatmaps in real-time video streams based on object tracks.
17
16
 
18
17
  This class extends the ObjectCounter class to generate and visualize heatmaps of object movements in video
19
18
  streams. It uses tracked object positions to create a cumulative heatmap effect over time.
@@ -30,14 +29,13 @@ class Heatmap(ObjectCounter):
30
29
 
31
30
  Examples:
32
31
  >>> from ultralytics.solutions import Heatmap
33
- >>> heatmap = Heatmap(model="yolo11n.pt", colormap=cv2.COLORMAP_JET)
32
+ >>> heatmap = Heatmap(model="yolo26n.pt", colormap=cv2.COLORMAP_JET)
34
33
  >>> frame = cv2.imread("frame.jpg")
35
34
  >>> processed_frame = heatmap.process(frame)
36
35
  """
37
36
 
38
37
  def __init__(self, **kwargs: Any) -> None:
39
- """
40
- Initialize the Heatmap class for real-time video stream heatmap generation based on object tracks.
38
+ """Initialize the Heatmap class for real-time video stream heatmap generation based on object tracks.
41
39
 
42
40
  Args:
43
41
  **kwargs (Any): Keyword arguments passed to the parent ObjectCounter class.
@@ -53,8 +51,7 @@ class Heatmap(ObjectCounter):
53
51
  self.heatmap = None
54
52
 
55
53
  def heatmap_effect(self, box: list[float]) -> None:
56
- """
57
- Efficiently calculate heatmap area and effect location for applying colormap.
54
+ """Efficiently calculate heatmap area and effect location for applying colormap.
58
55
 
59
56
  Args:
60
57
  box (list[float]): Bounding box coordinates [x0, y0, x1, y1].
@@ -75,18 +72,15 @@ class Heatmap(ObjectCounter):
75
72
  self.heatmap[y0:y1, x0:x1][within_radius] += 2
76
73
 
77
74
  def process(self, im0: np.ndarray) -> SolutionResults:
78
- """
79
- Generate heatmap for each frame using Ultralytics tracking.
75
+ """Generate heatmap for each frame using Ultralytics tracking.
80
76
 
81
77
  Args:
82
78
  im0 (np.ndarray): Input image array for processing.
83
79
 
84
80
  Returns:
85
- (SolutionResults): Contains processed image `plot_im`,
86
- 'in_count' (int, count of objects entering the region),
87
- 'out_count' (int, count of objects exiting the region),
88
- 'classwise_count' (dict, per-class object count), and
89
- 'total_tracks' (int, total number of tracked objects).
81
+ (SolutionResults): Contains processed image `plot_im`, 'in_count' (int, count of objects entering the
82
+ region), 'out_count' (int, count of objects exiting the region), 'classwise_count' (dict, per-class
83
+ object count), and 'total_tracks' (int, total number of tracked objects).
90
84
  """
91
85
  if not self.initialized:
92
86
  self.heatmap = np.zeros_like(im0, dtype=np.float32) * 0.99
@@ -7,8 +7,7 @@ from ultralytics.solutions.solutions import BaseSolution, SolutionResults
7
7
 
8
8
 
9
9
  class InstanceSegmentation(BaseSolution):
10
- """
11
- A class to manage instance segmentation in images or video streams.
10
+ """A class to manage instance segmentation in images or video streams.
12
11
 
13
12
  This class extends the BaseSolution class and provides functionality for performing instance segmentation, including
14
13
  drawing segmented masks with bounding boxes and labels.
@@ -36,14 +35,13 @@ class InstanceSegmentation(BaseSolution):
36
35
  """
37
36
 
38
37
  def __init__(self, **kwargs: Any) -> None:
39
- """
40
- Initialize the InstanceSegmentation class for detecting and annotating segmented instances.
38
+ """Initialize the InstanceSegmentation class for detecting and annotating segmented instances.
41
39
 
42
40
  Args:
43
- **kwargs (Any): Keyword arguments passed to the BaseSolution parent class.
44
- model (str): Model name or path, defaults to "yolo11n-seg.pt".
41
+ **kwargs (Any): Keyword arguments passed to the BaseSolution parent class including:
42
+ - model (str): Model name or path, defaults to "yolo26n-seg.pt".
45
43
  """
46
- kwargs["model"] = kwargs.get("model", "yolo11n-seg.pt")
44
+ kwargs["model"] = kwargs.get("model", "yolo26n-seg.pt")
47
45
  super().__init__(**kwargs)
48
46
 
49
47
  self.show_conf = self.CFG.get("show_conf", True)
@@ -51,8 +49,7 @@ class InstanceSegmentation(BaseSolution):
51
49
  self.show_boxes = self.CFG.get("show_boxes", True)
52
50
 
53
51
  def process(self, im0) -> SolutionResults:
54
- """
55
- Perform instance segmentation on the input image and annotate the results.
52
+ """Perform instance segmentation on the input image and annotate the results.
56
53
 
57
54
  Args:
58
55
  im0 (np.ndarray): The input image for segmentation.
@@ -10,8 +10,7 @@ from ultralytics.utils.plotting import colors
10
10
 
11
11
 
12
12
  class ObjectBlurrer(BaseSolution):
13
- """
14
- A class to manage the blurring of detected objects in a real-time video stream.
13
+ """A class to manage the blurring of detected objects in a real-time video stream.
15
14
 
16
15
  This class extends the BaseSolution class and provides functionality for blurring objects based on detected bounding
17
16
  boxes. The blurred areas are updated directly in the input image, allowing for privacy preservation or other effects.
@@ -34,12 +33,11 @@ class ObjectBlurrer(BaseSolution):
34
33
  """
35
34
 
36
35
  def __init__(self, **kwargs: Any) -> None:
37
- """
38
- Initialize the ObjectBlurrer class for applying a blur effect to objects detected in video streams or images.
36
+ """Initialize the ObjectBlurrer class for applying a blur effect to objects detected in video streams or images.
39
37
 
40
38
  Args:
41
- **kwargs (Any): Keyword arguments passed to the parent class and for configuration.
42
- blur_ratio (float): Intensity of the blur effect (0.1-1.0, default=0.5).
39
+ **kwargs (Any): Keyword arguments passed to the parent class and for configuration including:
40
+ - blur_ratio (float): Intensity of the blur effect (0.1-1.0, default=0.5).
43
41
  """
44
42
  super().__init__(**kwargs)
45
43
  blur_ratio = self.CFG["blur_ratio"]
@@ -49,11 +47,10 @@ class ObjectBlurrer(BaseSolution):
49
47
  self.blur_ratio = int(blur_ratio * 100)
50
48
 
51
49
  def process(self, im0) -> SolutionResults:
52
- """
53
- Apply a blurring effect to detected objects in the input image.
50
+ """Apply a blurring effect to detected objects in the input image.
54
51
 
55
- This method extracts tracking information, applies blur to regions corresponding to detected objects,
56
- and annotates the image with bounding boxes.
52
+ This method extracts tracking information, applies blur to regions corresponding to detected objects, and
53
+ annotates the image with bounding boxes.
57
54
 
58
55
  Args:
59
56
  im0 (np.ndarray): The input image containing detected objects.
@@ -10,8 +10,7 @@ from ultralytics.utils.plotting import colors
10
10
 
11
11
 
12
12
  class ObjectCounter(BaseSolution):
13
- """
14
- A class to manage the counting of objects in a real-time video stream based on their tracks.
13
+ """A class to manage the counting of objects in a real-time video stream based on their tracks.
15
14
 
16
15
  This class extends the BaseSolution class and provides functionality for counting objects moving in and out of a
17
16
  specified region in a video stream. It supports both polygonal and linear regions for counting.
@@ -20,7 +19,7 @@ class ObjectCounter(BaseSolution):
20
19
  in_count (int): Counter for objects moving inward.
21
20
  out_count (int): Counter for objects moving outward.
22
21
  counted_ids (list[int]): List of IDs of objects that have been counted.
23
- classwise_counts (dict[str, dict[str, int]]): Dictionary for counts, categorized by object class.
22
+ classwise_count (dict[str, dict[str, int]]): Dictionary for counts, categorized by object class.
24
23
  region_initialized (bool): Flag indicating whether the counting region has been initialized.
25
24
  show_in (bool): Flag to control display of inward count.
26
25
  show_out (bool): Flag to control display of outward count.
@@ -59,8 +58,7 @@ class ObjectCounter(BaseSolution):
59
58
  prev_position: tuple[float, float] | None,
60
59
  cls: int,
61
60
  ) -> None:
62
- """
63
- Count objects within a polygonal or linear region based on their tracks.
61
+ """Count objects within a polygonal or linear region based on their tracks.
64
62
 
65
63
  Args:
66
64
  current_centroid (tuple[float, float]): Current centroid coordinates (x, y) in the current frame.
@@ -106,11 +104,8 @@ class ObjectCounter(BaseSolution):
106
104
  region_width = max(p[0] for p in self.region) - min(p[0] for p in self.region)
107
105
  region_height = max(p[1] for p in self.region) - min(p[1] for p in self.region)
108
106
 
109
- if (
110
- region_width < region_height
111
- and current_centroid[0] > prev_position[0]
112
- or region_width >= region_height
113
- and current_centroid[1] > prev_position[1]
107
+ if (region_width < region_height and current_centroid[0] > prev_position[0]) or (
108
+ region_width >= region_height and current_centroid[1] > prev_position[1]
114
109
  ): # Moving right or downward
115
110
  self.in_count += 1
116
111
  self.classwise_count[self.names[cls]]["IN"] += 1
@@ -120,8 +115,7 @@ class ObjectCounter(BaseSolution):
120
115
  self.counted_ids.append(track_id)
121
116
 
122
117
  def display_counts(self, plot_im) -> None:
123
- """
124
- Display object counts on the input image or frame.
118
+ """Display object counts on the input image or frame.
125
119
 
126
120
  Args:
127
121
  plot_im (np.ndarray): The image or frame to display counts on.
@@ -135,25 +129,24 @@ class ObjectCounter(BaseSolution):
135
129
  str.capitalize(key): f"{'IN ' + str(value['IN']) if self.show_in else ''} "
136
130
  f"{'OUT ' + str(value['OUT']) if self.show_out else ''}".strip()
137
131
  for key, value in self.classwise_count.items()
138
- if value["IN"] != 0 or value["OUT"] != 0 and (self.show_in or self.show_out)
132
+ if (value["IN"] != 0 and self.show_in) or (value["OUT"] != 0 and self.show_out)
139
133
  }
140
134
  if labels_dict:
141
135
  self.annotator.display_analytics(plot_im, labels_dict, (104, 31, 17), (255, 255, 255), self.margin)
142
136
 
143
137
  def process(self, im0) -> SolutionResults:
144
- """
145
- Process input data (frames or object tracks) and update object counts.
138
+ """Process input data (frames or object tracks) and update object counts.
146
139
 
147
- This method initializes the counting region, extracts tracks, draws bounding boxes and regions, updates
148
- object counts, and displays the results on the input image.
140
+ This method initializes the counting region, extracts tracks, draws bounding boxes and regions, updates object
141
+ counts, and displays the results on the input image.
149
142
 
150
143
  Args:
151
144
  im0 (np.ndarray): The input image or frame to be processed.
152
145
 
153
146
  Returns:
154
147
  (SolutionResults): Contains processed image `im0`, 'in_count' (int, count of objects entering the region),
155
- 'out_count' (int, count of objects exiting the region), 'classwise_count' (dict, per-class object count),
156
- and 'total_tracks' (int, total number of tracked objects).
148
+ 'out_count' (int, count of objects exiting the region), 'classwise_count' (dict, per-class object
149
+ count), and 'total_tracks' (int, total number of tracked objects).
157
150
 
158
151
  Examples:
159
152
  >>> counter = ObjectCounter()
@@ -1,6 +1,5 @@
1
1
  # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
2
 
3
- import os
4
3
  from pathlib import Path
5
4
  from typing import Any
6
5
 
@@ -9,8 +8,7 @@ from ultralytics.utils.plotting import save_one_box
9
8
 
10
9
 
11
10
  class ObjectCropper(BaseSolution):
12
- """
13
- A class to manage the cropping of detected objects in a real-time video stream or images.
11
+ """A class to manage the cropping of detected objects in a real-time video stream or images.
14
12
 
15
13
  This class extends the BaseSolution class and provides functionality for cropping objects based on detected bounding
16
14
  boxes. The cropped images are saved to a specified directory for further analysis or usage.
@@ -32,29 +30,25 @@ class ObjectCropper(BaseSolution):
32
30
  """
33
31
 
34
32
  def __init__(self, **kwargs: Any) -> None:
35
- """
36
- Initialize the ObjectCropper class for cropping objects from detected bounding boxes.
33
+ """Initialize the ObjectCropper class for cropping objects from detected bounding boxes.
37
34
 
38
35
  Args:
39
- **kwargs (Any): Keyword arguments passed to the parent class and used for configuration.
40
- crop_dir (str): Path to the directory for saving cropped object images.
36
+ **kwargs (Any): Keyword arguments passed to the parent class and used for configuration including:
37
+ - crop_dir (str): Path to the directory for saving cropped object images.
41
38
  """
42
39
  super().__init__(**kwargs)
43
40
 
44
41
  self.crop_dir = self.CFG["crop_dir"] # Directory for storing cropped detections
45
- if not os.path.exists(self.crop_dir):
46
- os.mkdir(self.crop_dir) # Create directory if it does not exist
42
+ Path(self.crop_dir).mkdir(parents=True, exist_ok=True)
47
43
  if self.CFG["show"]:
48
- self.LOGGER.warning(
49
- f"show=True disabled for crop solution, results will be saved in the directory named: {self.crop_dir}"
50
- )
44
+ self.LOGGER.warning(f"show=True is not supported for ObjectCropper; saving crops to '{self.crop_dir}'.")
45
+ self.CFG["show"] = False
51
46
  self.crop_idx = 0 # Initialize counter for total cropped objects
52
47
  self.iou = self.CFG["iou"]
53
48
  self.conf = self.CFG["conf"]
54
49
 
55
50
  def process(self, im0) -> SolutionResults:
56
- """
57
- Crop detected objects from the input image and save them as separate images.
51
+ """Crop detected objects from the input image and save them as separate images.
58
52
 
59
53
  Args:
60
54
  im0 (np.ndarray): The input image containing detected objects.