dgenerate-ultralytics-headless 8.3.196__py3-none-any.whl → 8.3.248__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 (243) hide show
  1. {dgenerate_ultralytics_headless-8.3.196.dist-info → dgenerate_ultralytics_headless-8.3.248.dist-info}/METADATA +33 -34
  2. dgenerate_ultralytics_headless-8.3.248.dist-info/RECORD +298 -0
  3. tests/__init__.py +5 -7
  4. tests/conftest.py +8 -15
  5. tests/test_cli.py +8 -10
  6. tests/test_cuda.py +9 -10
  7. tests/test_engine.py +29 -2
  8. tests/test_exports.py +69 -21
  9. tests/test_integrations.py +8 -11
  10. tests/test_python.py +109 -71
  11. tests/test_solutions.py +170 -159
  12. ultralytics/__init__.py +27 -9
  13. ultralytics/cfg/__init__.py +57 -64
  14. ultralytics/cfg/datasets/Argoverse.yaml +7 -6
  15. ultralytics/cfg/datasets/DOTAv1.5.yaml +1 -1
  16. ultralytics/cfg/datasets/DOTAv1.yaml +1 -1
  17. ultralytics/cfg/datasets/ImageNet.yaml +1 -1
  18. ultralytics/cfg/datasets/Objects365.yaml +19 -15
  19. ultralytics/cfg/datasets/SKU-110K.yaml +1 -1
  20. ultralytics/cfg/datasets/VOC.yaml +19 -21
  21. ultralytics/cfg/datasets/VisDrone.yaml +5 -5
  22. ultralytics/cfg/datasets/african-wildlife.yaml +1 -1
  23. ultralytics/cfg/datasets/coco-pose.yaml +24 -2
  24. ultralytics/cfg/datasets/coco.yaml +2 -2
  25. ultralytics/cfg/datasets/coco128-seg.yaml +1 -1
  26. ultralytics/cfg/datasets/coco8-pose.yaml +21 -0
  27. ultralytics/cfg/datasets/construction-ppe.yaml +32 -0
  28. ultralytics/cfg/datasets/dog-pose.yaml +28 -0
  29. ultralytics/cfg/datasets/dota8-multispectral.yaml +1 -1
  30. ultralytics/cfg/datasets/dota8.yaml +2 -2
  31. ultralytics/cfg/datasets/hand-keypoints.yaml +26 -2
  32. ultralytics/cfg/datasets/kitti.yaml +27 -0
  33. ultralytics/cfg/datasets/lvis.yaml +7 -7
  34. ultralytics/cfg/datasets/open-images-v7.yaml +1 -1
  35. ultralytics/cfg/datasets/tiger-pose.yaml +16 -0
  36. ultralytics/cfg/datasets/xView.yaml +16 -16
  37. ultralytics/cfg/default.yaml +96 -94
  38. ultralytics/cfg/models/11/yolo11-pose.yaml +1 -1
  39. ultralytics/cfg/models/11/yoloe-11-seg.yaml +2 -2
  40. ultralytics/cfg/models/11/yoloe-11.yaml +2 -2
  41. ultralytics/cfg/models/rt-detr/rtdetr-l.yaml +1 -1
  42. ultralytics/cfg/models/rt-detr/rtdetr-resnet101.yaml +1 -1
  43. ultralytics/cfg/models/rt-detr/rtdetr-resnet50.yaml +1 -1
  44. ultralytics/cfg/models/rt-detr/rtdetr-x.yaml +1 -1
  45. ultralytics/cfg/models/v10/yolov10b.yaml +2 -2
  46. ultralytics/cfg/models/v10/yolov10l.yaml +2 -2
  47. ultralytics/cfg/models/v10/yolov10m.yaml +2 -2
  48. ultralytics/cfg/models/v10/yolov10n.yaml +2 -2
  49. ultralytics/cfg/models/v10/yolov10s.yaml +2 -2
  50. ultralytics/cfg/models/v10/yolov10x.yaml +2 -2
  51. ultralytics/cfg/models/v3/yolov3-tiny.yaml +1 -1
  52. ultralytics/cfg/models/v6/yolov6.yaml +1 -1
  53. ultralytics/cfg/models/v8/yoloe-v8-seg.yaml +9 -6
  54. ultralytics/cfg/models/v8/yoloe-v8.yaml +9 -6
  55. ultralytics/cfg/models/v8/yolov8-cls-resnet101.yaml +1 -1
  56. ultralytics/cfg/models/v8/yolov8-cls-resnet50.yaml +1 -1
  57. ultralytics/cfg/models/v8/yolov8-ghost-p2.yaml +2 -2
  58. ultralytics/cfg/models/v8/yolov8-ghost-p6.yaml +2 -2
  59. ultralytics/cfg/models/v8/yolov8-ghost.yaml +2 -2
  60. ultralytics/cfg/models/v8/yolov8-obb.yaml +1 -1
  61. ultralytics/cfg/models/v8/yolov8-p2.yaml +1 -1
  62. ultralytics/cfg/models/v8/yolov8-pose-p6.yaml +1 -1
  63. ultralytics/cfg/models/v8/yolov8-rtdetr.yaml +1 -1
  64. ultralytics/cfg/models/v8/yolov8-seg-p6.yaml +1 -1
  65. ultralytics/cfg/models/v8/yolov8-world.yaml +1 -1
  66. ultralytics/cfg/models/v8/yolov8-worldv2.yaml +6 -6
  67. ultralytics/cfg/models/v9/yolov9s.yaml +1 -1
  68. ultralytics/cfg/trackers/botsort.yaml +16 -17
  69. ultralytics/cfg/trackers/bytetrack.yaml +9 -11
  70. ultralytics/data/__init__.py +4 -4
  71. ultralytics/data/annotator.py +3 -4
  72. ultralytics/data/augment.py +286 -476
  73. ultralytics/data/base.py +18 -26
  74. ultralytics/data/build.py +151 -26
  75. ultralytics/data/converter.py +38 -50
  76. ultralytics/data/dataset.py +47 -75
  77. ultralytics/data/loaders.py +42 -49
  78. ultralytics/data/split.py +5 -6
  79. ultralytics/data/split_dota.py +8 -15
  80. ultralytics/data/utils.py +41 -45
  81. ultralytics/engine/exporter.py +462 -462
  82. ultralytics/engine/model.py +150 -191
  83. ultralytics/engine/predictor.py +30 -40
  84. ultralytics/engine/results.py +177 -311
  85. ultralytics/engine/trainer.py +193 -120
  86. ultralytics/engine/tuner.py +77 -63
  87. ultralytics/engine/validator.py +39 -22
  88. ultralytics/hub/__init__.py +16 -19
  89. ultralytics/hub/auth.py +6 -12
  90. ultralytics/hub/google/__init__.py +7 -10
  91. ultralytics/hub/session.py +15 -25
  92. ultralytics/hub/utils.py +5 -8
  93. ultralytics/models/__init__.py +1 -1
  94. ultralytics/models/fastsam/__init__.py +1 -1
  95. ultralytics/models/fastsam/model.py +8 -10
  96. ultralytics/models/fastsam/predict.py +19 -30
  97. ultralytics/models/fastsam/utils.py +1 -2
  98. ultralytics/models/fastsam/val.py +5 -7
  99. ultralytics/models/nas/__init__.py +1 -1
  100. ultralytics/models/nas/model.py +5 -8
  101. ultralytics/models/nas/predict.py +7 -9
  102. ultralytics/models/nas/val.py +1 -2
  103. ultralytics/models/rtdetr/__init__.py +1 -1
  104. ultralytics/models/rtdetr/model.py +7 -8
  105. ultralytics/models/rtdetr/predict.py +15 -19
  106. ultralytics/models/rtdetr/train.py +10 -13
  107. ultralytics/models/rtdetr/val.py +21 -23
  108. ultralytics/models/sam/__init__.py +15 -2
  109. ultralytics/models/sam/amg.py +14 -20
  110. ultralytics/models/sam/build.py +26 -19
  111. ultralytics/models/sam/build_sam3.py +377 -0
  112. ultralytics/models/sam/model.py +29 -32
  113. ultralytics/models/sam/modules/blocks.py +83 -144
  114. ultralytics/models/sam/modules/decoders.py +22 -40
  115. ultralytics/models/sam/modules/encoders.py +44 -101
  116. ultralytics/models/sam/modules/memory_attention.py +16 -30
  117. ultralytics/models/sam/modules/sam.py +206 -79
  118. ultralytics/models/sam/modules/tiny_encoder.py +64 -83
  119. ultralytics/models/sam/modules/transformer.py +18 -28
  120. ultralytics/models/sam/modules/utils.py +174 -50
  121. ultralytics/models/sam/predict.py +2268 -366
  122. ultralytics/models/sam/sam3/__init__.py +3 -0
  123. ultralytics/models/sam/sam3/decoder.py +546 -0
  124. ultralytics/models/sam/sam3/encoder.py +529 -0
  125. ultralytics/models/sam/sam3/geometry_encoders.py +415 -0
  126. ultralytics/models/sam/sam3/maskformer_segmentation.py +286 -0
  127. ultralytics/models/sam/sam3/model_misc.py +199 -0
  128. ultralytics/models/sam/sam3/necks.py +129 -0
  129. ultralytics/models/sam/sam3/sam3_image.py +339 -0
  130. ultralytics/models/sam/sam3/text_encoder_ve.py +307 -0
  131. ultralytics/models/sam/sam3/vitdet.py +547 -0
  132. ultralytics/models/sam/sam3/vl_combiner.py +160 -0
  133. ultralytics/models/utils/loss.py +14 -26
  134. ultralytics/models/utils/ops.py +13 -17
  135. ultralytics/models/yolo/__init__.py +1 -1
  136. ultralytics/models/yolo/classify/predict.py +9 -12
  137. ultralytics/models/yolo/classify/train.py +15 -41
  138. ultralytics/models/yolo/classify/val.py +34 -32
  139. ultralytics/models/yolo/detect/predict.py +8 -11
  140. ultralytics/models/yolo/detect/train.py +13 -32
  141. ultralytics/models/yolo/detect/val.py +75 -63
  142. ultralytics/models/yolo/model.py +37 -53
  143. ultralytics/models/yolo/obb/predict.py +5 -14
  144. ultralytics/models/yolo/obb/train.py +11 -14
  145. ultralytics/models/yolo/obb/val.py +42 -39
  146. ultralytics/models/yolo/pose/__init__.py +1 -1
  147. ultralytics/models/yolo/pose/predict.py +7 -22
  148. ultralytics/models/yolo/pose/train.py +10 -22
  149. ultralytics/models/yolo/pose/val.py +40 -59
  150. ultralytics/models/yolo/segment/predict.py +16 -20
  151. ultralytics/models/yolo/segment/train.py +3 -12
  152. ultralytics/models/yolo/segment/val.py +106 -56
  153. ultralytics/models/yolo/world/train.py +12 -16
  154. ultralytics/models/yolo/world/train_world.py +11 -34
  155. ultralytics/models/yolo/yoloe/__init__.py +7 -7
  156. ultralytics/models/yolo/yoloe/predict.py +16 -23
  157. ultralytics/models/yolo/yoloe/train.py +31 -56
  158. ultralytics/models/yolo/yoloe/train_seg.py +5 -10
  159. ultralytics/models/yolo/yoloe/val.py +16 -21
  160. ultralytics/nn/__init__.py +7 -7
  161. ultralytics/nn/autobackend.py +152 -80
  162. ultralytics/nn/modules/__init__.py +60 -60
  163. ultralytics/nn/modules/activation.py +4 -6
  164. ultralytics/nn/modules/block.py +133 -217
  165. ultralytics/nn/modules/conv.py +52 -97
  166. ultralytics/nn/modules/head.py +64 -116
  167. ultralytics/nn/modules/transformer.py +79 -89
  168. ultralytics/nn/modules/utils.py +16 -21
  169. ultralytics/nn/tasks.py +111 -156
  170. ultralytics/nn/text_model.py +40 -67
  171. ultralytics/solutions/__init__.py +12 -12
  172. ultralytics/solutions/ai_gym.py +11 -17
  173. ultralytics/solutions/analytics.py +15 -16
  174. ultralytics/solutions/config.py +5 -6
  175. ultralytics/solutions/distance_calculation.py +10 -13
  176. ultralytics/solutions/heatmap.py +7 -13
  177. ultralytics/solutions/instance_segmentation.py +5 -8
  178. ultralytics/solutions/object_blurrer.py +7 -10
  179. ultralytics/solutions/object_counter.py +12 -19
  180. ultralytics/solutions/object_cropper.py +8 -14
  181. ultralytics/solutions/parking_management.py +33 -31
  182. ultralytics/solutions/queue_management.py +10 -12
  183. ultralytics/solutions/region_counter.py +9 -12
  184. ultralytics/solutions/security_alarm.py +15 -20
  185. ultralytics/solutions/similarity_search.py +13 -17
  186. ultralytics/solutions/solutions.py +75 -74
  187. ultralytics/solutions/speed_estimation.py +7 -10
  188. ultralytics/solutions/streamlit_inference.py +4 -7
  189. ultralytics/solutions/templates/similarity-search.html +7 -18
  190. ultralytics/solutions/trackzone.py +7 -10
  191. ultralytics/solutions/vision_eye.py +5 -8
  192. ultralytics/trackers/__init__.py +1 -1
  193. ultralytics/trackers/basetrack.py +3 -5
  194. ultralytics/trackers/bot_sort.py +10 -27
  195. ultralytics/trackers/byte_tracker.py +14 -30
  196. ultralytics/trackers/track.py +3 -6
  197. ultralytics/trackers/utils/gmc.py +11 -22
  198. ultralytics/trackers/utils/kalman_filter.py +37 -48
  199. ultralytics/trackers/utils/matching.py +12 -15
  200. ultralytics/utils/__init__.py +116 -116
  201. ultralytics/utils/autobatch.py +2 -4
  202. ultralytics/utils/autodevice.py +17 -18
  203. ultralytics/utils/benchmarks.py +70 -70
  204. ultralytics/utils/callbacks/base.py +8 -10
  205. ultralytics/utils/callbacks/clearml.py +5 -13
  206. ultralytics/utils/callbacks/comet.py +32 -46
  207. ultralytics/utils/callbacks/dvc.py +13 -18
  208. ultralytics/utils/callbacks/mlflow.py +4 -5
  209. ultralytics/utils/callbacks/neptune.py +7 -15
  210. ultralytics/utils/callbacks/platform.py +314 -38
  211. ultralytics/utils/callbacks/raytune.py +3 -4
  212. ultralytics/utils/callbacks/tensorboard.py +23 -31
  213. ultralytics/utils/callbacks/wb.py +10 -13
  214. ultralytics/utils/checks.py +151 -87
  215. ultralytics/utils/cpu.py +3 -8
  216. ultralytics/utils/dist.py +19 -15
  217. ultralytics/utils/downloads.py +29 -41
  218. ultralytics/utils/errors.py +6 -14
  219. ultralytics/utils/events.py +2 -4
  220. ultralytics/utils/export/__init__.py +7 -0
  221. ultralytics/utils/{export.py → export/engine.py} +16 -16
  222. ultralytics/utils/export/imx.py +325 -0
  223. ultralytics/utils/export/tensorflow.py +231 -0
  224. ultralytics/utils/files.py +24 -28
  225. ultralytics/utils/git.py +9 -11
  226. ultralytics/utils/instance.py +30 -51
  227. ultralytics/utils/logger.py +212 -114
  228. ultralytics/utils/loss.py +15 -24
  229. ultralytics/utils/metrics.py +131 -160
  230. ultralytics/utils/nms.py +21 -30
  231. ultralytics/utils/ops.py +107 -165
  232. ultralytics/utils/patches.py +33 -21
  233. ultralytics/utils/plotting.py +122 -119
  234. ultralytics/utils/tal.py +28 -44
  235. ultralytics/utils/torch_utils.py +70 -187
  236. ultralytics/utils/tqdm.py +20 -20
  237. ultralytics/utils/triton.py +13 -19
  238. ultralytics/utils/tuner.py +17 -5
  239. dgenerate_ultralytics_headless-8.3.196.dist-info/RECORD +0 -281
  240. {dgenerate_ultralytics_headless-8.3.196.dist-info → dgenerate_ultralytics_headless-8.3.248.dist-info}/WHEEL +0 -0
  241. {dgenerate_ultralytics_headless-8.3.196.dist-info → dgenerate_ultralytics_headless-8.3.248.dist-info}/entry_points.txt +0 -0
  242. {dgenerate_ultralytics_headless-8.3.196.dist-info → dgenerate_ultralytics_headless-8.3.248.dist-info}/licenses/LICENSE +0 -0
  243. {dgenerate_ultralytics_headless-8.3.196.dist-info → dgenerate_ultralytics_headless-8.3.248.dist-info}/top_level.txt +0 -0
@@ -18,8 +18,7 @@ from ultralytics.utils.plotting import Annotator
18
18
 
19
19
 
20
20
  class BaseSolution:
21
- """
22
- A base class for managing Ultralytics Solutions.
21
+ """A base class for managing Ultralytics Solutions.
23
22
 
24
23
  This class provides core functionality for various Ultralytics Solutions, including model loading, object tracking,
25
24
  and region initialization. It serves as the foundation for implementing specific computer vision solutions such as
@@ -73,8 +72,7 @@ class BaseSolution:
73
72
  """
74
73
 
75
74
  def __init__(self, is_cli: bool = False, **kwargs: Any) -> None:
76
- """
77
- Initialize the BaseSolution class with configuration settings and YOLO model.
75
+ """Initialize the BaseSolution class with configuration settings and YOLO model.
78
76
 
79
77
  Args:
80
78
  is_cli (bool): Enable CLI mode if set to True.
@@ -138,12 +136,11 @@ class BaseSolution:
138
136
  )
139
137
 
140
138
  def adjust_box_label(self, cls: int, conf: float, track_id: int | None = None) -> str | None:
141
- """
142
- Generate a formatted label for a bounding box.
139
+ """Generate a formatted label for a bounding box.
143
140
 
144
- This method constructs a label string for a bounding box using the class index and confidence score.
145
- Optionally includes the track ID if provided. The label format adapts based on the display settings
146
- defined in `self.show_conf` and `self.show_labels`.
141
+ This method constructs a label string for a bounding box using the class index and confidence score. Optionally
142
+ includes the track ID if provided. The label format adapts based on the display settings defined in
143
+ `self.show_conf` and `self.show_labels`.
147
144
 
148
145
  Args:
149
146
  cls (int): The class index of the detected object.
@@ -157,8 +154,7 @@ class BaseSolution:
157
154
  return (f"{name} {conf:.2f}" if self.show_conf else name) if self.show_labels else None
158
155
 
159
156
  def extract_tracks(self, im0: np.ndarray) -> None:
160
- """
161
- Apply object tracking and extract tracks from an input image or frame.
157
+ """Apply object tracking and extract tracks from an input image or frame.
162
158
 
163
159
  Args:
164
160
  im0 (np.ndarray): The input image or frame.
@@ -181,15 +177,14 @@ class BaseSolution:
181
177
  self.track_ids = self.track_data.id.int().cpu().tolist()
182
178
  self.confs = self.track_data.conf.cpu().tolist()
183
179
  else:
184
- self.LOGGER.warning("no tracks found!")
180
+ self.LOGGER.warning("No tracks found.")
185
181
  self.boxes, self.clss, self.track_ids, self.confs = [], [], [], []
186
182
 
187
183
  def store_tracking_history(self, track_id: int, box) -> None:
188
- """
189
- Store the tracking history of an object.
184
+ """Store the tracking history of an object.
190
185
 
191
- This method updates the tracking history for a given object by appending the center point of its
192
- bounding box to the track line. It maintains a maximum of 30 points in the tracking history.
186
+ This method updates the tracking history for a given object by appending the center point of its bounding box to
187
+ the track line. It maintains a maximum of 30 points in the tracking history.
193
188
 
194
189
  Args:
195
190
  track_id (int): The unique identifier for the tracked object.
@@ -214,8 +209,8 @@ class BaseSolution:
214
209
  ) # region or line
215
210
 
216
211
  def display_output(self, plot_im: np.ndarray) -> None:
217
- """
218
- Display the results of the processing, which could involve showing frames, printing counts, or saving results.
212
+ """Display the results of the processing, which could involve showing frames, printing counts, or saving
213
+ results.
219
214
 
220
215
  This method is responsible for visualizing the output of the object detection and tracking process. It displays
221
216
  the processed frame with annotations, and allows for user interaction to close the display.
@@ -264,8 +259,7 @@ class BaseSolution:
264
259
 
265
260
 
266
261
  class SolutionAnnotator(Annotator):
267
- """
268
- A specialized annotator class for visualizing and analyzing computer vision tasks.
262
+ """A specialized annotator class for visualizing and analyzing computer vision tasks.
269
263
 
270
264
  This class extends the base Annotator class, providing additional methods for drawing regions, centroids, tracking
271
265
  trails, and visual annotations for Ultralytics Solutions. It offers comprehensive visualization capabilities for
@@ -277,7 +271,7 @@ class SolutionAnnotator(Annotator):
277
271
  font_size (int): Size of the font used for text annotations.
278
272
  font (str): Path to the font file used for text rendering.
279
273
  pil (bool): Whether to use PIL for text rendering.
280
- example (str): An example attribute for demonstration purposes.
274
+ example (str): Example text used to detect non-ASCII labels for PIL rendering.
281
275
 
282
276
  Methods:
283
277
  draw_region: Draw a region using specified points, colors, and thickness.
@@ -310,8 +304,7 @@ class SolutionAnnotator(Annotator):
310
304
  pil: bool = False,
311
305
  example: str = "abc",
312
306
  ):
313
- """
314
- Initialize the SolutionAnnotator class with an image for annotation.
307
+ """Initialize the SolutionAnnotator class with an image for annotation.
315
308
 
316
309
  Args:
317
310
  im (np.ndarray): The image to be annotated.
@@ -319,7 +312,7 @@ class SolutionAnnotator(Annotator):
319
312
  font_size (int, optional): Font size for text annotations.
320
313
  font (str): Path to the font file.
321
314
  pil (bool): Indicates whether to use PIL for rendering text.
322
- example (str): An example parameter for demonstration purposes.
315
+ example (str): Example text used to detect non-ASCII labels for PIL rendering.
323
316
  """
324
317
  super().__init__(im, line_width, font_size, font, pil, example)
325
318
 
@@ -329,12 +322,11 @@ class SolutionAnnotator(Annotator):
329
322
  color: tuple[int, int, int] = (0, 255, 0),
330
323
  thickness: int = 5,
331
324
  ):
332
- """
333
- Draw a region or line on the image.
325
+ """Draw a region or line on the image.
334
326
 
335
327
  Args:
336
328
  reg_pts (list[tuple[int, int]], optional): Region points (for line 2 points, for region 4+ points).
337
- color (tuple[int, int, int]): RGB color value for the region.
329
+ color (tuple[int, int, int]): BGR color value for the region (OpenCV format).
338
330
  thickness (int): Line thickness for drawing the region.
339
331
  """
340
332
  cv2.polylines(self.im, [np.array(reg_pts, dtype=np.int32)], isClosed=True, color=color, thickness=thickness)
@@ -350,14 +342,13 @@ class SolutionAnnotator(Annotator):
350
342
  region_color: tuple[int, int, int] = (255, 255, 255),
351
343
  txt_color: tuple[int, int, int] = (0, 0, 0),
352
344
  ):
353
- """
354
- Display queue counts on an image centered at the points with customizable font size and colors.
345
+ """Display queue counts on an image centered at the points with customizable font size and colors.
355
346
 
356
347
  Args:
357
348
  label (str): Queue counts label.
358
349
  points (list[tuple[int, int]], optional): Region points for center point calculation to display text.
359
- region_color (tuple[int, int, int]): RGB queue region color.
360
- txt_color (tuple[int, int, int]): RGB text display color.
350
+ region_color (tuple[int, int, int]): BGR queue region color (OpenCV format).
351
+ txt_color (tuple[int, int, int]): BGR text color (OpenCV format).
361
352
  """
362
353
  x_values = [point[0] for point in points]
363
354
  y_values = [point[1] for point in points]
@@ -397,14 +388,13 @@ class SolutionAnnotator(Annotator):
397
388
  bg_color: tuple[int, int, int],
398
389
  margin: int,
399
390
  ):
400
- """
401
- Display the overall statistics for parking lots, object counter etc.
391
+ """Display overall statistics for Solutions (e.g., parking management and object counting).
402
392
 
403
393
  Args:
404
394
  im0 (np.ndarray): Inference image.
405
395
  text (dict[str, Any]): Labels dictionary.
406
- txt_color (tuple[int, int, int]): Display color for text foreground.
407
- bg_color (tuple[int, int, int]): Display color for text background.
396
+ txt_color (tuple[int, int, int]): Text color (BGR, OpenCV format).
397
+ bg_color (tuple[int, int, int]): Background color (BGR, OpenCV format).
408
398
  margin (int): Gap between text and rectangle for better display.
409
399
  """
410
400
  horizontal_gap = int(im0.shape[1] * 0.02)
@@ -425,23 +415,45 @@ class SolutionAnnotator(Annotator):
425
415
  cv2.putText(im0, txt, (text_x, text_y), 0, self.sf, txt_color, self.tf, lineType=cv2.LINE_AA)
426
416
  text_y_offset = rect_y2
427
417
 
418
+ @staticmethod
419
+ def _point_xy(point: Any) -> tuple[float, float]:
420
+ """Convert a keypoint-like object to an (x, y) tuple of floats."""
421
+ if hasattr(point, "detach"): # torch.Tensor
422
+ point = point.detach()
423
+ if hasattr(point, "cpu"): # torch.Tensor
424
+ point = point.cpu()
425
+ if hasattr(point, "numpy"): # torch.Tensor
426
+ point = point.numpy()
427
+ if hasattr(point, "tolist"): # numpy / torch
428
+ point = point.tolist()
429
+ return float(point[0]), float(point[1])
430
+
428
431
  @staticmethod
429
432
  @lru_cache(maxsize=256)
430
- def estimate_pose_angle(a: list[float], b: list[float], c: list[float]) -> float:
431
- """
432
- Calculate the angle between three points for workout monitoring.
433
+ def _estimate_pose_angle_cached(a: tuple[float, float], b: tuple[float, float], c: tuple[float, float]) -> float:
434
+ """Calculate the angle between three points for workout monitoring (cached)."""
435
+ radians = math.atan2(c[1] - b[1], c[0] - b[0]) - math.atan2(a[1] - b[1], a[0] - b[0])
436
+ angle = abs(radians * 180.0 / math.pi)
437
+ return angle if angle <= 180.0 else (360 - angle)
438
+
439
+ @staticmethod
440
+ def estimate_pose_angle(a: Any, b: Any, c: Any) -> float:
441
+ """Calculate the angle between three points for workout monitoring.
433
442
 
434
443
  Args:
435
- a (list[float]): The coordinates of the first point.
436
- b (list[float]): The coordinates of the second point (vertex).
437
- c (list[float]): The coordinates of the third point.
444
+ a (Any): The coordinates of the first point (e.g. list/tuple/NumPy array/torch tensor).
445
+ b (Any): The coordinates of the second point (vertex).
446
+ c (Any): The coordinates of the third point.
438
447
 
439
448
  Returns:
440
449
  (float): The angle in degrees between the three points.
441
450
  """
442
- radians = math.atan2(c[1] - b[1], c[0] - b[0]) - math.atan2(a[1] - b[1], a[0] - b[0])
443
- angle = abs(radians * 180.0 / math.pi)
444
- return angle if angle <= 180.0 else (360 - angle)
451
+ a_xy, b_xy, c_xy = (
452
+ SolutionAnnotator._point_xy(a),
453
+ SolutionAnnotator._point_xy(b),
454
+ SolutionAnnotator._point_xy(c),
455
+ )
456
+ return SolutionAnnotator._estimate_pose_angle_cached(a_xy, b_xy, c_xy)
445
457
 
446
458
  def draw_specific_kpts(
447
459
  self,
@@ -450,8 +462,7 @@ class SolutionAnnotator(Annotator):
450
462
  radius: int = 2,
451
463
  conf_thresh: float = 0.25,
452
464
  ) -> np.ndarray:
453
- """
454
- Draw specific keypoints for gym steps counting.
465
+ """Draw specific keypoints for gym steps counting.
455
466
 
456
467
  Args:
457
468
  keypoints (list[list[float]]): Keypoints data to be plotted, each in format [x, y, confidence].
@@ -486,8 +497,7 @@ class SolutionAnnotator(Annotator):
486
497
  color: tuple[int, int, int] = (104, 31, 17),
487
498
  txt_color: tuple[int, int, int] = (255, 255, 255),
488
499
  ) -> int:
489
- """
490
- Draw workout text with a background on the image.
500
+ """Draw workout text with a background on the image.
491
501
 
492
502
  Args:
493
503
  display_text (str): The text to be displayed.
@@ -522,8 +532,7 @@ class SolutionAnnotator(Annotator):
522
532
  color: tuple[int, int, int] = (104, 31, 17),
523
533
  txt_color: tuple[int, int, int] = (255, 255, 255),
524
534
  ):
525
- """
526
- Plot the pose angle, count value, and step stage for workout monitoring.
535
+ """Plot the pose angle, count value, and step stage for workout monitoring.
527
536
 
528
537
  Args:
529
538
  angle_text (str): Angle value for workout monitoring.
@@ -554,11 +563,10 @@ class SolutionAnnotator(Annotator):
554
563
  line_color: tuple[int, int, int] = (104, 31, 17),
555
564
  centroid_color: tuple[int, int, int] = (255, 0, 255),
556
565
  ):
557
- """
558
- Plot the distance and line between two centroids on the frame.
566
+ """Plot the distance and line between two centroids on the frame.
559
567
 
560
568
  Args:
561
- pixels_distance (float): Pixels distance between two bbox centroids.
569
+ pixels_distance (float): Pixel distance between two bounding-box centroids.
562
570
  centroids (list[tuple[int, int]]): Bounding box centroids data.
563
571
  line_color (tuple[int, int, int]): Distance line color.
564
572
  centroid_color (tuple[int, int, int]): Bounding box centroid color.
@@ -597,8 +605,7 @@ class SolutionAnnotator(Annotator):
597
605
  y_center: float,
598
606
  margin: int,
599
607
  ):
600
- """
601
- Display the bounding boxes labels in parking management app.
608
+ """Display the bounding boxes labels in parking management app.
602
609
 
603
610
  Args:
604
611
  im0 (np.ndarray): Inference image.
@@ -644,15 +651,14 @@ class SolutionAnnotator(Annotator):
644
651
  color: tuple[int, int, int] = (221, 0, 186),
645
652
  txt_color: tuple[int, int, int] = (255, 255, 255),
646
653
  ):
647
- """
648
- Draw a sweep annotation line and an optional label.
654
+ """Draw a sweep annotation line and an optional label.
649
655
 
650
656
  Args:
651
657
  line_x (int): The x-coordinate of the sweep line.
652
658
  line_y (int): The y-coordinate limit of the sweep line.
653
659
  label (str, optional): Text label to be drawn in center of sweep line. If None, no label is drawn.
654
- color (tuple[int, int, int]): RGB color for the line and label background.
655
- txt_color (tuple[int, int, int]): RGB color for the label text.
660
+ color (tuple[int, int, int]): BGR color for the line and label background (OpenCV format).
661
+ txt_color (tuple[int, int, int]): BGR color for the label text (OpenCV format).
656
662
  """
657
663
  # Draw the sweep line
658
664
  cv2.line(self.im, (line_x, 0), (line_x, line_y), color, self.tf * 2)
@@ -684,8 +690,7 @@ class SolutionAnnotator(Annotator):
684
690
  color: tuple[int, int, int] = (235, 219, 11),
685
691
  pin_color: tuple[int, int, int] = (255, 0, 255),
686
692
  ):
687
- """
688
- Perform pinpoint human-vision eye mapping and plotting.
693
+ """Perform pinpoint human-vision eye mapping and plotting.
689
694
 
690
695
  Args:
691
696
  box (list[float]): Bounding box coordinates in format [x1, y1, x2, y2].
@@ -707,22 +712,21 @@ class SolutionAnnotator(Annotator):
707
712
  shape: str = "rect",
708
713
  margin: int = 5,
709
714
  ):
710
- """
711
- Draw a label with a background rectangle or circle centered within a given bounding box.
715
+ """Draw a label with a background rectangle or circle centered within a given bounding box.
712
716
 
713
717
  Args:
714
718
  box (tuple[float, float, float, float]): The bounding box coordinates (x1, y1, x2, y2).
715
719
  label (str): The text label to be displayed.
716
720
  color (tuple[int, int, int]): The background color of the rectangle (B, G, R).
717
- txt_color (tuple[int, int, int]): The color of the text (R, G, B).
718
- shape (str): The shape of the label i.e "circle" or "rect"
721
+ txt_color (tuple[int, int, int]): The color of the text (B, G, R).
722
+ shape (str): Label shape. Options: "circle" or "rect".
719
723
  margin (int): The margin between the text and the rectangle border.
720
724
  """
721
725
  if shape == "circle" and len(label) > 3:
722
726
  LOGGER.warning(f"Length of label is {len(label)}, only first 3 letters will be used for circle annotation.")
723
727
  label = label[:3]
724
728
 
725
- x_center, y_center = int((box[0] + box[2]) / 2), int((box[1] + box[3]) / 2) # Calculate center of the bbox
729
+ x_center, y_center = int((box[0] + box[2]) / 2), int((box[1] + box[3]) / 2) # Bounding-box center
726
730
  text_size = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, self.sf - 0.15, self.tf)[0] # Get size of the text
727
731
  text_x, text_y = x_center - text_size[0] // 2, y_center + text_size[1] // 2 # Calculate top-left corner of text
728
732
 
@@ -757,12 +761,11 @@ class SolutionAnnotator(Annotator):
757
761
 
758
762
 
759
763
  class SolutionResults:
760
- """
761
- A class to encapsulate the results of Ultralytics Solutions.
764
+ """A class to encapsulate the results of Ultralytics Solutions.
762
765
 
763
766
  This class is designed to store and manage various outputs generated by the solution pipeline, including counts,
764
- angles, workout stages, and other analytics data. It provides a structured way to access and manipulate results
765
- from different computer vision solutions such as object counting, pose estimation, and tracking analytics.
767
+ angles, workout stages, and other analytics data. It provides a structured way to access and manipulate results from
768
+ different computer vision solutions such as object counting, pose estimation, and tracking analytics.
766
769
 
767
770
  Attributes:
768
771
  plot_im (np.ndarray): Processed image with counts, blurred, or other effects from solutions.
@@ -785,8 +788,7 @@ class SolutionResults:
785
788
  """
786
789
 
787
790
  def __init__(self, **kwargs):
788
- """
789
- Initialize a SolutionResults object with default or user-specified values.
791
+ """Initialize a SolutionResults object with default or user-specified values.
790
792
 
791
793
  Args:
792
794
  **kwargs (Any): Optional arguments to override default attribute values.
@@ -813,8 +815,7 @@ class SolutionResults:
813
815
  self.__dict__.update(kwargs)
814
816
 
815
817
  def __str__(self) -> str:
816
- """
817
- Return a formatted string representation of the SolutionResults object.
818
+ """Return a formatted string representation of the SolutionResults object.
818
819
 
819
820
  Returns:
820
821
  (str): A string representation listing non-null attributes.
@@ -9,12 +9,11 @@ from ultralytics.utils.plotting import colors
9
9
 
10
10
 
11
11
  class SpeedEstimator(BaseSolution):
12
- """
13
- A class to estimate the speed of objects in a real-time video stream based on their tracks.
12
+ """A class to estimate the speed of objects in a real-time video stream based on their tracks.
14
13
 
15
- This class extends the BaseSolution class and provides functionality for estimating object speeds using
16
- tracking data in video streams. Speed is calculated based on pixel displacement over time and converted
17
- to real-world units using a configurable meters-per-pixel scale factor.
14
+ This class extends the BaseSolution class and provides functionality for estimating object speeds using tracking
15
+ data in video streams. Speed is calculated based on pixel displacement over time and converted to real-world units
16
+ using a configurable meters-per-pixel scale factor.
18
17
 
19
18
  Attributes:
20
19
  fps (float): Video frame rate for time calculations.
@@ -42,8 +41,7 @@ class SpeedEstimator(BaseSolution):
42
41
  """
43
42
 
44
43
  def __init__(self, **kwargs: Any) -> None:
45
- """
46
- Initialize the SpeedEstimator object with speed estimation parameters and data structures.
44
+ """Initialize the SpeedEstimator object with speed estimation parameters and data structures.
47
45
 
48
46
  Args:
49
47
  **kwargs (Any): Additional keyword arguments passed to the parent class.
@@ -61,11 +59,10 @@ class SpeedEstimator(BaseSolution):
61
59
  self.max_speed = self.CFG["max_speed"] # Maximum speed adjustment
62
60
 
63
61
  def process(self, im0) -> SolutionResults:
64
- """
65
- Process an input frame to estimate object speeds based on tracking data.
62
+ """Process an input frame to estimate object speeds based on tracking data.
66
63
 
67
64
  Args:
68
- im0 (np.ndarray): Input image for processing with shape (H, W, C) for RGB images.
65
+ im0 (np.ndarray): Input image for processing with shape (H, W, C) in OpenCV BGR format.
69
66
 
70
67
  Returns:
71
68
  (SolutionResults): Contains processed image `plot_im` and `total_tracks` (number of tracked objects).
@@ -16,8 +16,7 @@ torch.classes.__path__ = [] # Torch module __path__._path issue: https://github
16
16
 
17
17
 
18
18
  class Inference:
19
- """
20
- A class to perform object detection, image classification, image segmentation and pose estimation inference.
19
+ """A class to perform object detection, image classification, image segmentation and pose estimation inference.
21
20
 
22
21
  This class provides functionalities for loading models, configuring settings, uploading video files, and performing
23
22
  real-time inference using Streamlit and Ultralytics YOLO models.
@@ -54,8 +53,7 @@ class Inference:
54
53
  """
55
54
 
56
55
  def __init__(self, **kwargs: Any) -> None:
57
- """
58
- Initialize the Inference class, checking Streamlit requirements and setting up the model path.
56
+ """Initialize the Inference class, checking Streamlit requirements and setting up the model path.
59
57
 
60
58
  Args:
61
59
  **kwargs (Any): Additional keyword arguments for model configuration.
@@ -166,9 +164,8 @@ class Inference:
166
164
  selected_model = self.st.sidebar.selectbox("Model", available_models)
167
165
 
168
166
  with self.st.spinner("Model is downloading..."):
169
- if (
170
- selected_model.endswith((".pt", ".onnx", ".torchscript", ".mlpackage", ".engine"))
171
- or "openvino_model" in selected_model
167
+ if selected_model.endswith((".pt", ".onnx", ".torchscript", ".mlpackage", ".engine")) or any(
168
+ fmt in selected_model for fmt in ("openvino_model", "rknn_model")
172
169
  ):
173
170
  model_path = selected_model
174
171
  else:
@@ -7,10 +7,7 @@
7
7
  <meta charset="UTF-8" />
8
8
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
9
9
  <title>Semantic Image Search</title>
10
- <link
11
- href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap"
12
- rel="stylesheet"
13
- />
10
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet" />
14
11
  <style>
15
12
  body {
16
13
  background: linear-gradient(135deg, #f0f4ff, #f9fbff);
@@ -109,7 +106,9 @@
109
106
  card.style.display = idx < k ? "block" : "none";
110
107
  });
111
108
  const buttons = document.querySelectorAll(".topk-btn");
112
- buttons.forEach((btn) => btn.classList.remove("active"));
109
+ buttons.forEach((btn) => {
110
+ btn.classList.remove("active");
111
+ });
113
112
  event.target.classList.add("active");
114
113
  }
115
114
  document.addEventListener("DOMContentLoaded", () => {
@@ -138,19 +137,9 @@
138
137
  <button type="submit">Search</button>
139
138
  {% if results %}
140
139
  <div class="top-k-buttons">
141
- <button type="button" class="topk-btn" onclick="filterResults(5)">
142
- Top 5
143
- </button>
144
- <button
145
- type="button"
146
- class="topk-btn active"
147
- onclick="filterResults(10)"
148
- >
149
- Top 10
150
- </button>
151
- <button type="button" class="topk-btn" onclick="filterResults(30)">
152
- Top 30
153
- </button>
140
+ <button type="button" class="topk-btn" onclick="filterResults(5)">Top 5</button>
141
+ <button type="button" class="topk-btn active" onclick="filterResults(10)">Top 10</button>
142
+ <button type="button" class="topk-btn" onclick="filterResults(30)">Top 30</button>
154
143
  </div>
155
144
  {% endif %}
156
145
  </form>
@@ -10,8 +10,7 @@ from ultralytics.utils.plotting import colors
10
10
 
11
11
 
12
12
  class TrackZone(BaseSolution):
13
- """
14
- A class to manage region-based object tracking in a video stream.
13
+ """A class to manage region-based object tracking in a video stream.
15
14
 
16
15
  This class extends the BaseSolution class and provides functionality for tracking objects within a specific region
17
16
  defined by a polygonal area. Objects outside the region are excluded from tracking.
@@ -37,8 +36,7 @@ class TrackZone(BaseSolution):
37
36
  """
38
37
 
39
38
  def __init__(self, **kwargs: Any) -> None:
40
- """
41
- Initialize the TrackZone class for tracking objects within a defined region in video streams.
39
+ """Initialize the TrackZone class for tracking objects within a defined region in video streams.
42
40
 
43
41
  Args:
44
42
  **kwargs (Any): Additional keyword arguments passed to the parent class.
@@ -49,18 +47,17 @@ class TrackZone(BaseSolution):
49
47
  self.mask = None
50
48
 
51
49
  def process(self, im0: np.ndarray) -> SolutionResults:
52
- """
53
- Process the input frame to track objects within a defined region.
50
+ """Process the input frame to track objects within a defined region.
54
51
 
55
- This method initializes the annotator, creates a mask for the specified region, extracts tracks
56
- only from the masked area, and updates tracking information. Objects outside the region are ignored.
52
+ This method initializes the annotator, creates a mask for the specified region, extracts tracks only from the
53
+ masked area, and updates tracking information. Objects outside the region are ignored.
57
54
 
58
55
  Args:
59
56
  im0 (np.ndarray): The input image or frame to be processed.
60
57
 
61
58
  Returns:
62
- (SolutionResults): Contains processed image `plot_im` and `total_tracks` (int) representing the
63
- total number of tracked objects within the defined region.
59
+ (SolutionResults): Contains processed image `plot_im` and `total_tracks` (int) representing the total number
60
+ of tracked objects within the defined region.
64
61
 
65
62
  Examples:
66
63
  >>> tracker = TrackZone()
@@ -7,11 +7,10 @@ from ultralytics.utils.plotting import colors
7
7
 
8
8
 
9
9
  class VisionEye(BaseSolution):
10
- """
11
- A class to manage object detection and vision mapping in images or video streams.
10
+ """A class to manage object detection and vision mapping in images or video streams.
12
11
 
13
- This class extends the BaseSolution class and provides functionality for detecting objects,
14
- mapping vision points, and annotating results with bounding boxes and labels.
12
+ This class extends the BaseSolution class and provides functionality for detecting objects, mapping vision points,
13
+ and annotating results with bounding boxes and labels.
15
14
 
16
15
  Attributes:
17
16
  vision_point (tuple[int, int]): Coordinates (x, y) where vision will view objects and draw tracks.
@@ -27,8 +26,7 @@ class VisionEye(BaseSolution):
27
26
  """
28
27
 
29
28
  def __init__(self, **kwargs: Any) -> None:
30
- """
31
- Initialize the VisionEye class for detecting objects and applying vision mapping.
29
+ """Initialize the VisionEye class for detecting objects and applying vision mapping.
32
30
 
33
31
  Args:
34
32
  **kwargs (Any): Keyword arguments passed to the parent class and for configuring vision_point.
@@ -38,8 +36,7 @@ class VisionEye(BaseSolution):
38
36
  self.vision_point = self.CFG["vision_point"]
39
37
 
40
38
  def process(self, im0) -> SolutionResults:
41
- """
42
- Perform object detection, vision mapping, and annotation on the input image.
39
+ """Perform object detection, vision mapping, and annotation on the input image.
43
40
 
44
41
  Args:
45
42
  im0 (np.ndarray): The input image for detection and annotation.
@@ -4,4 +4,4 @@ from .bot_sort import BOTSORT
4
4
  from .byte_tracker import BYTETracker
5
5
  from .track import register_tracker
6
6
 
7
- __all__ = "register_tracker", "BOTSORT", "BYTETracker" # allow simpler import
7
+ __all__ = "BOTSORT", "BYTETracker", "register_tracker" # allow simpler import
@@ -8,8 +8,7 @@ import numpy as np
8
8
 
9
9
 
10
10
  class TrackState:
11
- """
12
- Enumeration class representing the possible states of an object being tracked.
11
+ """Enumeration class representing the possible states of an object being tracked.
13
12
 
14
13
  Attributes:
15
14
  New (int): State when the object is newly detected.
@@ -20,7 +19,7 @@ class TrackState:
20
19
  Examples:
21
20
  >>> state = TrackState.New
22
21
  >>> if state == TrackState.New:
23
- >>> print("Object is newly detected.")
22
+ ... print("Object is newly detected.")
24
23
  """
25
24
 
26
25
  New = 0
@@ -30,8 +29,7 @@ class TrackState:
30
29
 
31
30
 
32
31
  class BaseTrack:
33
- """
34
- Base class for object tracking, providing foundational attributes and methods.
32
+ """Base class for object tracking, providing foundational attributes and methods.
35
33
 
36
34
  Attributes:
37
35
  _count (int): Class-level counter for unique track IDs.