ultralytics 8.3.86__py3-none-any.whl → 8.3.88__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 (42) hide show
  1. tests/test_solutions.py +47 -39
  2. ultralytics/__init__.py +1 -1
  3. ultralytics/cfg/__init__.py +58 -55
  4. ultralytics/cfg/models/11/yolo11-cls-resnet18.yaml +1 -1
  5. ultralytics/cfg/models/11/yolo11-cls.yaml +6 -6
  6. ultralytics/data/augment.py +2 -2
  7. ultralytics/data/loaders.py +1 -1
  8. ultralytics/engine/exporter.py +1 -1
  9. ultralytics/engine/results.py +76 -41
  10. ultralytics/engine/trainer.py +11 -5
  11. ultralytics/engine/tuner.py +3 -2
  12. ultralytics/nn/autobackend.py +1 -1
  13. ultralytics/nn/tasks.py +1 -1
  14. ultralytics/solutions/__init__.py +14 -6
  15. ultralytics/solutions/ai_gym.py +39 -28
  16. ultralytics/solutions/analytics.py +22 -18
  17. ultralytics/solutions/distance_calculation.py +25 -25
  18. ultralytics/solutions/heatmap.py +40 -38
  19. ultralytics/solutions/instance_segmentation.py +69 -0
  20. ultralytics/solutions/object_blurrer.py +89 -0
  21. ultralytics/solutions/object_counter.py +35 -33
  22. ultralytics/solutions/object_cropper.py +84 -0
  23. ultralytics/solutions/parking_management.py +40 -13
  24. ultralytics/solutions/queue_management.py +20 -39
  25. ultralytics/solutions/region_counter.py +54 -51
  26. ultralytics/solutions/security_alarm.py +40 -30
  27. ultralytics/solutions/solutions.py +594 -16
  28. ultralytics/solutions/speed_estimation.py +34 -31
  29. ultralytics/solutions/streamlit_inference.py +34 -28
  30. ultralytics/solutions/trackzone.py +29 -18
  31. ultralytics/solutions/vision_eye.py +69 -0
  32. ultralytics/trackers/utils/kalman_filter.py +23 -23
  33. ultralytics/utils/__init__.py +2 -3
  34. ultralytics/utils/callbacks/comet.py +37 -5
  35. ultralytics/utils/instance.py +3 -3
  36. ultralytics/utils/plotting.py +0 -414
  37. {ultralytics-8.3.86.dist-info → ultralytics-8.3.88.dist-info}/METADATA +8 -8
  38. {ultralytics-8.3.86.dist-info → ultralytics-8.3.88.dist-info}/RECORD +42 -38
  39. {ultralytics-8.3.86.dist-info → ultralytics-8.3.88.dist-info}/WHEEL +1 -1
  40. {ultralytics-8.3.86.dist-info → ultralytics-8.3.88.dist-info}/LICENSE +0 -0
  41. {ultralytics-8.3.86.dist-info → ultralytics-8.3.88.dist-info}/entry_points.txt +0 -0
  42. {ultralytics-8.3.86.dist-info → ultralytics-8.3.88.dist-info}/top_level.txt +0 -0
tests/test_solutions.py CHANGED
@@ -1,15 +1,20 @@
1
1
  # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
+ # This is file for Ultralytics Solutions tests: https://docs.ultralytics.com/solutions/,
3
+ # It includes every solution excluding DistanceCalculation and Security Alarm System.
2
4
 
3
5
  import cv2
4
6
  import pytest
5
7
 
6
8
  from tests import TMP
7
- from ultralytics import YOLO, solutions
8
- from ultralytics.utils import ASSETS_URL, WEIGHTS_DIR
9
+ from ultralytics import solutions
10
+ from ultralytics.utils import ASSETS_URL
9
11
  from ultralytics.utils.downloads import safe_download
10
12
 
11
- DEMO_VIDEO = "solutions_ci_demo.mp4"
12
- POSE_VIDEO = "solution_ci_pose_demo.mp4"
13
+ DEMO_VIDEO = "solutions_ci_demo.mp4" # for all the solutions, except workout and parking
14
+ POSE_VIDEO = "solution_ci_pose_demo.mp4" # only for workouts monitoring solution
15
+ PARKING_VIDEO = "solution_ci_parking_demo.mp4" # only for parking management solution
16
+ PARKING_AREAS_JSON = "solution_ci_parking_areas.json" # only for parking management solution
17
+ PARKING_MODEL = "solutions_ci_parking_model.pt" # only for parking management solution
13
18
 
14
19
 
15
20
  @pytest.mark.slow
@@ -21,16 +26,23 @@ def test_major_solutions():
21
26
  region_points = [(20, 400), (1080, 400), (1080, 360), (20, 360)]
22
27
  counter = solutions.ObjectCounter(region=region_points, model="yolo11n.pt", show=False) # Test object counter
23
28
  heatmap = solutions.Heatmap(colormap=cv2.COLORMAP_PARULA, model="yolo11n.pt", show=False) # Test heatmaps
24
- heatmap_count = solutions.Heatmap(
29
+ heatmapcounter = solutions.Heatmap(
25
30
  colormap=cv2.COLORMAP_PARULA, model="yolo11n.pt", show=False, region=region_points
26
31
  ) # Test heatmaps with object counting
27
32
  speed = solutions.SpeedEstimator(region=region_points, model="yolo11n.pt", show=False) # Test queue manager
28
33
  queue = solutions.QueueManager(region=region_points, model="yolo11n.pt", show=False) # Test speed estimation
29
- line_analytics = solutions.Analytics(analytics_type="line", model="yolo11n.pt", show=False) # line analytics
30
- pie_analytics = solutions.Analytics(analytics_type="pie", model="yolo11n.pt", show=False) # line analytics
31
- bar_analytics = solutions.Analytics(analytics_type="bar", model="yolo11n.pt", show=False) # line analytics
32
- area_analytics = solutions.Analytics(analytics_type="area", model="yolo11n.pt", show=False) # line analytics
33
- trackzone = solutions.TrackZone(region=region_points, model="yolo11n.pt", show=False) # Test trackzone
34
+ lineanalytics = solutions.Analytics(analytics_type="line", model="yolo11n.pt", show=False) # line analytics
35
+ pieanalytics = solutions.Analytics(analytics_type="pie", model="yolo11n.pt", show=False) # line analytics
36
+ baranalytics = solutions.Analytics(analytics_type="bar", model="yolo11n.pt", show=False) # line analytics
37
+ areaanalytics = solutions.Analytics(analytics_type="area", model="yolo11n.pt", show=False) # line analytics
38
+ trackzone = solutions.TrackZone(region=region_points, model="yolo11n.pt", show=False) # trackzone
39
+ objectcropper = solutions.ObjectCropper(
40
+ model="yolo11n.pt", show=False, crop_dir=str(TMP / "cropped-detections")
41
+ ) # object cropping
42
+ objectblurrer = solutions.ObjectBlurrer(blur_ratio=0.5, model="yolo11n.pt", show=False) # Object blurring
43
+ isegment = solutions.InstanceSegmentation(model="yolo11n-seg.pt", show=False) # Instance segmentation
44
+ visioneye = solutions.VisionEye(model="yolo11n.pt", show=False) # Visioneye
45
+ regioncounter = solutions.RegionCounter(region=region_points, model="yolo11n.pt", show=False) # Region counter
34
46
  frame_count = 0 # Required for analytics
35
47
  while cap.isOpened():
36
48
  success, im0 = cap.read()
@@ -38,16 +50,21 @@ def test_major_solutions():
38
50
  break
39
51
  frame_count += 1
40
52
  original_im0 = im0.copy()
41
- _ = counter.count(original_im0.copy())
42
- _ = heatmap.generate_heatmap(original_im0.copy())
43
- _ = heatmap_count.generate_heatmap(original_im0.copy())
44
- _ = speed.estimate_speed(original_im0.copy())
45
- _ = queue.process_queue(original_im0.copy())
46
- _ = line_analytics.process_data(original_im0.copy(), frame_count)
47
- _ = pie_analytics.process_data(original_im0.copy(), frame_count)
48
- _ = bar_analytics.process_data(original_im0.copy(), frame_count)
49
- _ = area_analytics.process_data(original_im0.copy(), frame_count)
50
- _ = trackzone.trackzone(original_im0.copy())
53
+ _ = counter(original_im0.copy())
54
+ _ = heatmap(original_im0.copy())
55
+ _ = heatmapcounter(original_im0.copy())
56
+ _ = speed(original_im0.copy())
57
+ _ = queue(original_im0.copy())
58
+ _ = lineanalytics(original_im0.copy(), frame_count)
59
+ _ = pieanalytics(original_im0.copy(), frame_count)
60
+ _ = baranalytics(original_im0.copy(), frame_count)
61
+ _ = areaanalytics(original_im0.copy(), frame_count)
62
+ _ = trackzone(original_im0.copy())
63
+ _ = objectcropper(original_im0.copy())
64
+ _ = isegment(original_im0.copy())
65
+ _ = objectblurrer(original_im0.copy())
66
+ _ = visioneye(original_im0.copy())
67
+ _ = regioncounter(original_im0.copy())
51
68
  cap.release()
52
69
 
53
70
  # Test workouts monitoring
@@ -59,33 +76,24 @@ def test_major_solutions():
59
76
  success, im0 = cap.read()
60
77
  if not success:
61
78
  break
62
- _ = gym.monitor(im0)
79
+ _ = gym(im0)
63
80
  cap.release()
64
81
 
65
-
66
- @pytest.mark.slow
67
- def test_instance_segmentation():
68
- """Test the instance segmentation solution."""
69
- from ultralytics.utils.plotting import Annotator, colors
70
-
71
- model = YOLO(WEIGHTS_DIR / "yolo11n-seg.pt")
72
- names = model.names
73
- cap = cv2.VideoCapture(TMP / DEMO_VIDEO)
82
+ # Test parking management
83
+ safe_download(url=f"{ASSETS_URL}/{PARKING_VIDEO}", dir=TMP)
84
+ safe_download(url=f"{ASSETS_URL}/{PARKING_AREAS_JSON}", dir=TMP)
85
+ safe_download(url=f"{ASSETS_URL}/{PARKING_MODEL}", dir=TMP)
86
+ cap = cv2.VideoCapture(str(TMP / PARKING_VIDEO))
74
87
  assert cap.isOpened(), "Error reading video file"
88
+ parkingmanager = solutions.ParkingManagement(
89
+ json_file=str(TMP / PARKING_AREAS_JSON), model=str(TMP / PARKING_MODEL), show=False
90
+ )
75
91
  while cap.isOpened():
76
92
  success, im0 = cap.read()
77
93
  if not success:
78
94
  break
79
- results = model.predict(im0)
80
- annotator = Annotator(im0, line_width=2)
81
- if results[0].masks is not None:
82
- clss = results[0].boxes.cls.cpu().tolist()
83
- masks = results[0].masks.xy
84
- for mask, cls in zip(masks, clss):
85
- color = colors(int(cls), True)
86
- annotator.seg_bbox(mask=mask, mask_color=color, label=names[int(cls)])
95
+ _ = parkingmanager(im0)
87
96
  cap.release()
88
- cv2.destroyAllWindows()
89
97
 
90
98
 
91
99
  @pytest.mark.slow
ultralytics/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
2
 
3
- __version__ = "8.3.86"
3
+ __version__ = "8.3.88"
4
4
 
5
5
  import os
6
6
 
@@ -5,7 +5,7 @@ import subprocess
5
5
  import sys
6
6
  from pathlib import Path
7
7
  from types import SimpleNamespace
8
- from typing import Dict, List, Union
8
+ from typing import Any, Dict, List, Union
9
9
 
10
10
  import cv2
11
11
 
@@ -35,14 +35,18 @@ from ultralytics.utils import (
35
35
 
36
36
  # Define valid solutions
37
37
  SOLUTION_MAP = {
38
- "count": ("ObjectCounter", "count"),
39
- "heatmap": ("Heatmap", "generate_heatmap"),
40
- "queue": ("QueueManager", "process_queue"),
41
- "speed": ("SpeedEstimator", "estimate_speed"),
42
- "workout": ("AIGym", "monitor"),
43
- "analytics": ("Analytics", "process_data"),
44
- "trackzone": ("TrackZone", "trackzone"),
45
- "inference": ("Inference", "inference"),
38
+ "count": "ObjectCounter",
39
+ "crop": "ObjectCropper",
40
+ "blur": "ObjectBlurrer",
41
+ "workout": "AIGym",
42
+ "heatmap": "Heatmap",
43
+ "isegment": "InstanceSegmentation",
44
+ "visioneye": "VisionEye",
45
+ "speed": "SpeedEstimator",
46
+ "queue": "QueueManager",
47
+ "analytics": "Analytics",
48
+ "inference": "Inference",
49
+ "trackzone": "TrackZone",
46
50
  "help": None,
47
51
  }
48
52
 
@@ -238,7 +242,7 @@ CFG_BOOL_KEYS = frozenset(
238
242
  )
239
243
 
240
244
 
241
- def cfg2dict(cfg):
245
+ def cfg2dict(cfg: Union[str, Path, Dict, SimpleNamespace]) -> Dict:
242
246
  """
243
247
  Converts a configuration object to a dictionary.
244
248
 
@@ -273,7 +277,7 @@ def cfg2dict(cfg):
273
277
  return cfg
274
278
 
275
279
 
276
- def get_cfg(cfg: Union[str, Path, Dict, SimpleNamespace] = DEFAULT_CFG_DICT, overrides: Dict = None):
280
+ def get_cfg(cfg: Union[str, Path, Dict, SimpleNamespace] = DEFAULT_CFG_DICT, overrides: Dict = None) -> SimpleNamespace:
277
281
  """
278
282
  Load and merge configuration data from a file or dictionary, with optional overrides.
279
283
 
@@ -321,7 +325,7 @@ def get_cfg(cfg: Union[str, Path, Dict, SimpleNamespace] = DEFAULT_CFG_DICT, ove
321
325
  return IterableSimpleNamespace(**cfg)
322
326
 
323
327
 
324
- def check_cfg(cfg, hard=True):
328
+ def check_cfg(cfg: Dict, hard: bool = True) -> None:
325
329
  """
326
330
  Checks configuration argument types and values for the Ultralytics library.
327
331
 
@@ -383,7 +387,7 @@ def check_cfg(cfg, hard=True):
383
387
  cfg[k] = bool(v)
384
388
 
385
389
 
386
- def get_save_dir(args, name=None):
390
+ def get_save_dir(args: SimpleNamespace, name: str = None) -> Path:
387
391
  """
388
392
  Returns the directory path for saving outputs, derived from arguments or default settings.
389
393
 
@@ -415,7 +419,7 @@ def get_save_dir(args, name=None):
415
419
  return Path(save_dir)
416
420
 
417
421
 
418
- def _handle_deprecation(custom):
422
+ def _handle_deprecation(custom: Dict) -> Dict:
419
423
  """
420
424
  Handles deprecated configuration keys by mapping them to current equivalents with deprecation warnings.
421
425
 
@@ -453,7 +457,7 @@ def _handle_deprecation(custom):
453
457
  return custom
454
458
 
455
459
 
456
- def check_dict_alignment(base: Dict, custom: Dict, e=None):
460
+ def check_dict_alignment(base: Dict, custom: Dict, e: Exception = None) -> None:
457
461
  """
458
462
  Checks alignment between custom and base configuration dictionaries, handling deprecated keys and providing error
459
463
  messages for mismatched keys.
@@ -507,7 +511,7 @@ def merge_equals_args(args: List[str]) -> List[str]:
507
511
  args (List[str]): A list of strings where each element represents an argument or fragment.
508
512
 
509
513
  Returns:
510
- List[str]: A list of strings where the arguments around isolated '=' are merged and fragments with brackets are joined.
514
+ (List[str]): A list of strings where the arguments around isolated '=' are merged and fragments with brackets are joined.
511
515
 
512
516
  Examples:
513
517
  >>> args = ["arg1", "=", "value", "arg2=", "value2", "arg3", "=value3", "imgsz=[3,", "640,", "640]"]
@@ -634,9 +638,6 @@ def handle_yolo_solutions(args: List[str]) -> None:
634
638
  solutions: https://docs.ultralytics.com/solutions/, It can include solution name, source,
635
639
  and other configuration parameters.
636
640
 
637
- Returns:
638
- None: The function processes video frames and saves the output but doesn't return any value.
639
-
640
641
  Examples:
641
642
  Run people counting solution with default settings:
642
643
  >>> handle_yolo_solutions(["count"])
@@ -656,14 +657,17 @@ def handle_yolo_solutions(args: List[str]) -> None:
656
657
  - For 'analytics' solution, frame numbers are tracked for generating analytical graphs
657
658
  - Video processing can be interrupted by pressing 'q'
658
659
  - Processes video frames sequentially and saves output in .avi format
659
- - If no source is specified, downloads and uses a default sample video\
660
+ - If no source is specified, downloads and uses a default sample video
660
661
  - The inference solution will be launched using the 'streamlit run' command.
661
662
  - The Streamlit app file is located in the Ultralytics package directory.
662
663
  """
663
- from ultralytics import solutions
664
- from ultralytics.utils.files import increment_path
665
-
666
- full_args_dict = {**DEFAULT_SOL_DICT, **DEFAULT_CFG_DICT} # arguments dictionary
664
+ full_args_dict = {
665
+ **DEFAULT_SOL_DICT,
666
+ **DEFAULT_CFG_DICT,
667
+ "blur_ratio": 0.5,
668
+ "vision_point": (20, 20),
669
+ "crop_dir": "cropped-detections",
670
+ } # arguments dictionary
667
671
  overrides = {}
668
672
 
669
673
  # check dictionary alignment
@@ -680,21 +684,19 @@ def handle_yolo_solutions(args: List[str]) -> None:
680
684
  check_dict_alignment(full_args_dict, overrides) # dict alignment
681
685
 
682
686
  # Get solution name
683
- if args and args[0] in SOLUTION_MAP:
684
- if args[0] != "help":
685
- s_n = args.pop(0) # Extract the solution name directly
686
- else:
687
- LOGGER.info(SOLUTIONS_HELP_MSG)
687
+ if args[0] == "help":
688
+ LOGGER.info(SOLUTIONS_HELP_MSG)
689
+ return # Early return for 'help' case
690
+ elif args[0] in SOLUTION_MAP:
691
+ solution_name = args.pop(0) # Extract the solution name directly
688
692
  else:
689
693
  LOGGER.warning(
690
- f"⚠️ No valid solution provided. Using default 'count'. Available: {', '.join(SOLUTION_MAP.keys())}"
694
+ f" '{args[0]}' is not a valid solution. 💡 Defaulting to 'count'.\n"
695
+ f"🚀 Available solutions: {', '.join(list(SOLUTION_MAP.keys())[:-1])}\n"
691
696
  )
692
- s_n = "count" # Default solution if none provided
693
-
694
- if args and args[0] == "help": # Add check for return if user call `yolo solutions help`
695
- return
697
+ solution_name = "count" # Default for invalid solution
696
698
 
697
- if s_n == "inference":
699
+ if solution_name == "inference":
698
700
  checks.check_requirements("streamlit>=1.29.0")
699
701
  LOGGER.info("💡 Loading Ultralytics live inference app...")
700
702
  subprocess.run(
@@ -708,22 +710,21 @@ def handle_yolo_solutions(args: List[str]) -> None:
708
710
  ]
709
711
  )
710
712
  else:
711
- cls, method = SOLUTION_MAP[s_n] # solution class name, method name and default source
712
- solution = getattr(solutions, cls)(IS_CLI=True, **overrides) # get solution class i.e ObjectCounter
713
- process = getattr(
714
- solution, method
715
- ) # get specific function of class for processing i.e, count from ObjectCounter
716
-
717
- cap = cv2.VideoCapture(solution.CFG["source"]) # read the video file
713
+ from ultralytics import solutions
718
714
 
719
- # extract width, height and fps of the video file, create save directory and initialize video writer
715
+ solution = getattr(solutions, SOLUTION_MAP[solution_name])(is_cli=True, **overrides) # class i.e ObjectCounter
720
716
 
721
- w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
722
- if s_n == "analytics": # analytical graphs follow fixed shape for output i.e w=1920, h=1080
723
- w, h = 1920, 1080
724
- save_dir = increment_path(Path("runs") / "solutions" / "exp", exist_ok=False)
725
- save_dir.mkdir(parents=True, exist_ok=True) # create the output directory
726
- vw = cv2.VideoWriter(str(save_dir / "solution.avi"), cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
717
+ cap = cv2.VideoCapture(solution.CFG["source"]) # read the video file
718
+ if solution_name != "crop":
719
+ # extract width, height and fps of the video file, create save directory and initialize video writer
720
+ w, h, fps = (
721
+ int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS)
722
+ )
723
+ if solution_name == "analytics": # analytical graphs follow fixed shape for output i.e w=1920, h=1080
724
+ w, h = 1280, 720
725
+ save_dir = get_save_dir(SimpleNamespace(project="runs/solutions", name="exp", exist_ok=False))
726
+ save_dir.mkdir(parents=True) # create the output directory i.e. runs/solutions/exp
727
+ vw = cv2.VideoWriter(str(save_dir / f"{solution_name}.avi"), cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
727
728
 
728
729
  try: # Process video frames
729
730
  f_n = 0 # frame number, required for analytical graphs
@@ -731,15 +732,17 @@ def handle_yolo_solutions(args: List[str]) -> None:
731
732
  success, frame = cap.read()
732
733
  if not success:
733
734
  break
734
- frame = process(frame, f_n := f_n + 1) if s_n == "analytics" else process(frame)
735
- vw.write(frame)
735
+ results = solution(frame, f_n := f_n + 1) if solution_name == "analytics" else solution(frame)
736
+ LOGGER.info(f"🚀 Results: {results}")
737
+ if solution_name != "crop":
738
+ vw.write(results.plot_im)
736
739
  if cv2.waitKey(1) & 0xFF == ord("q"):
737
740
  break
738
741
  finally:
739
742
  cap.release()
740
743
 
741
744
 
742
- def parse_key_value_pair(pair: str = "key=value"):
745
+ def parse_key_value_pair(pair: str = "key=value") -> tuple:
743
746
  """
744
747
  Parses a key-value pair string into separate key and value components.
745
748
 
@@ -773,7 +776,7 @@ def parse_key_value_pair(pair: str = "key=value"):
773
776
  return k, smart_value(v)
774
777
 
775
778
 
776
- def smart_value(v):
779
+ def smart_value(v: str) -> Any:
777
780
  """
778
781
  Converts a string representation of a value to its appropriate Python type.
779
782
 
@@ -818,7 +821,7 @@ def smart_value(v):
818
821
  return v
819
822
 
820
823
 
821
- def entrypoint(debug=""):
824
+ def entrypoint(debug: str = "") -> None:
822
825
  """
823
826
  Ultralytics entrypoint function for parsing and executing command-line arguments.
824
827
 
@@ -990,7 +993,7 @@ def entrypoint(debug=""):
990
993
 
991
994
 
992
995
  # Special modes --------------------------------------------------------------------------------------------------------
993
- def copy_default_cfg():
996
+ def copy_default_cfg() -> None:
994
997
  """
995
998
  Copies the default configuration file and creates a new one with '_copy' appended to its name.
996
999
 
@@ -5,7 +5,7 @@
5
5
  # Task docs: https://docs.ultralytics.com/tasks/classify
6
6
 
7
7
  # Parameters
8
- nc: 10 # number of classes
8
+ nc: 1000 # number of classes
9
9
 
10
10
  # ResNet18 backbone
11
11
  backbone:
@@ -5,14 +5,14 @@
5
5
  # Task docs: https://docs.ultralytics.com/tasks/classify
6
6
 
7
7
  # Parameters
8
- nc: 80 # number of classes
8
+ nc: 1000 # number of classes
9
9
  scales: # model compound scaling constants, i.e. 'model=yolo11n-cls.yaml' will call yolo11-cls.yaml with scale 'n'
10
10
  # [depth, width, max_channels]
11
- n: [0.50, 0.25, 1024] # summary: 151 layers, 1633584 parameters, 1633584 gradients, 3.3 GFLOPs
12
- s: [0.50, 0.50, 1024] # summary: 151 layers, 5545488 parameters, 5545488 gradients, 12.2 GFLOPs
13
- m: [0.50, 1.00, 512] # summary: 187 layers, 10455696 parameters, 10455696 gradients, 39.7 GFLOPs
14
- l: [1.00, 1.00, 512] # summary: 309 layers, 12937104 parameters, 12937104 gradients, 49.9 GFLOPs
15
- x: [1.00, 1.50, 512] # summary: 309 layers, 28458544 parameters, 28458544 gradients, 111.1 GFLOPs
11
+ n: [0.50, 0.25, 1024] # summary: 151 layers, 1633584 parameters, 1633584 gradients, 0.5 GFLOPs
12
+ s: [0.50, 0.50, 1024] # summary: 151 layers, 5545488 parameters, 5545488 gradients, 1.6 GFLOPs
13
+ m: [0.50, 1.00, 512] # summary: 187 layers, 10455696 parameters, 10455696 gradients, 5.0 GFLOPs
14
+ l: [1.00, 1.00, 512] # summary: 309 layers, 12937104 parameters, 12937104 gradients, 6.2 GFLOPs
15
+ x: [1.00, 1.50, 512] # summary: 309 layers, 28458544 parameters, 28458544 gradients, 13.7 GFLOPs
16
16
 
17
17
  # YOLO11n backbone
18
18
  backbone:
@@ -1193,8 +1193,8 @@ class RandomPerspective:
1193
1193
  Args:
1194
1194
  labels (Dict): A dictionary containing image data and annotations.
1195
1195
  Must include:
1196
- 'img' (ndarray): The input image.
1197
- 'cls' (ndarray): Class labels.
1196
+ 'img' (np.ndarray): The input image.
1197
+ 'cls' (np.ndarray): Class labels.
1198
1198
  'instances' (Instances): Object instances with bounding boxes, segments, and keypoints.
1199
1199
  May include:
1200
1200
  'mosaic_border' (Tuple[int, int]): Border size for mosaic augmentation.
@@ -106,7 +106,7 @@ class LoadStreams:
106
106
  self.caps = [None] * n # video capture objects
107
107
  self.imgs = [[] for _ in range(n)] # images
108
108
  self.shape = [[] for _ in range(n)] # image shapes
109
- self.sources = [ops.clean_str(x) for x in sources] # clean source names for later
109
+ self.sources = [ops.clean_str(x).replace(os.sep, "_") for x in sources] # clean source names for later
110
110
  for i, s in enumerate(sources): # index, source
111
111
  # Start thread to read frames from video stream
112
112
  st = f"{i + 1}/{n}: {s}... "
@@ -590,7 +590,7 @@ class Exporter:
590
590
  @try_export
591
591
  def export_openvino(self, prefix=colorstr("OpenVINO:")):
592
592
  """YOLO OpenVINO export."""
593
- check_requirements("openvino>=2024.0.0,<2025.0.0")
593
+ check_requirements("openvino>=2024.0.0,!=2025.0.0")
594
594
  import openvino as ov
595
595
 
596
596
  LOGGER.info(f"\n{prefix} starting export with openvino {ov.__version__}...")
@@ -188,43 +188,50 @@ class Results(SimpleClass):
188
188
  """
189
189
  A class for storing and manipulating inference results.
190
190
 
191
- This class encapsulates the functionality for handling detection, segmentation, pose estimation,
192
- and classification results from YOLO models.
191
+ This class provides methods for accessing, manipulating, and visualizing inference results from various
192
+ Ultralytics models, including detection, segmentation, classification, and pose estimation.
193
193
 
194
194
  Attributes:
195
- orig_img (numpy.ndarray): Original image as a numpy array.
195
+ orig_img (numpy.ndarray): The original image as a numpy array.
196
196
  orig_shape (Tuple[int, int]): Original image shape in (height, width) format.
197
- boxes (Boxes | None): Object containing detection bounding boxes.
198
- masks (Masks | None): Object containing detection masks.
199
- probs (Probs | None): Object containing class probabilities for classification tasks.
200
- keypoints (Keypoints | None): Object containing detected keypoints for each object.
201
- obb (OBB | None): Object containing oriented bounding boxes.
202
- speed (Dict[str, float | None]): Dictionary of preprocess, inference, and postprocess speeds.
203
- names (Dict[int, str]): Dictionary mapping class IDs to class names.
204
- path (str): Path to the image file.
205
- _keys (Tuple[str, ...]): Tuple of attribute names for internal use.
197
+ boxes (Boxes | None): Detected bounding boxes.
198
+ masks (Masks | None): Segmentation masks.
199
+ probs (Probs | None): Classification probabilities.
200
+ keypoints (Keypoints | None): Detected keypoints.
201
+ obb (OBB | None): Oriented bounding boxes.
202
+ speed (Dict): Dictionary containing inference speed information.
203
+ names (Dict): Dictionary mapping class indices to class names.
204
+ path (str): Path to the input image file.
205
+ save_dir (str | None): Directory to save results.
206
206
 
207
207
  Methods:
208
- update: Updates object attributes with new detection results.
209
- cpu: Returns a copy of the Results object with all tensors on CPU memory.
210
- numpy: Returns a copy of the Results object with all tensors as numpy arrays.
211
- cuda: Returns a copy of the Results object with all tensors on GPU memory.
212
- to: Returns a copy of the Results object with tensors on a specified device and dtype.
213
- new: Returns a new Results object with the same image, path, and names.
214
- plot: Plots detection results on an input image, returning an annotated image.
215
- show: Shows annotated results on screen.
216
- save: Saves annotated results to file.
217
- verbose: Returns a log string for each task, detailing detections and classifications.
208
+ update: Updates the Results object with new detection data.
209
+ cpu: Returns a copy of the Results object with all tensors moved to CPU memory.
210
+ numpy: Converts all tensors in the Results object to numpy arrays.
211
+ cuda: Moves all tensors in the Results object to GPU memory.
212
+ to: Moves all tensors to the specified device and dtype.
213
+ new: Creates a new Results object with the same image, path, names, and speed attributes.
214
+ plot: Plots detection results on an input RGB image.
215
+ show: Displays the image with annotated inference results.
216
+ save: Saves annotated inference results image to file.
217
+ verbose: Returns a log string for each task in the results.
218
218
  save_txt: Saves detection results to a text file.
219
- save_crop: Saves cropped detection images.
220
- tojson: Converts detection results to JSON format.
219
+ save_crop: Saves cropped detection images to specified directory.
220
+ summary: Converts inference results to a summarized dictionary.
221
+ to_df: Converts detection results to a Pandas Dataframe.
222
+ to_json: Converts detection results to JSON format.
223
+ to_csv: Converts detection results to a CSV format.
224
+ to_xml: Converts detection results to XML format.
225
+ to_html: Converts detection results to HTML format.
226
+ to_sql: Converts detection results to an SQL-compatible format.
221
227
 
222
228
  Examples:
223
229
  >>> results = model("path/to/image.jpg")
230
+ >>> result = results[0] # Get the first result
231
+ >>> boxes = result.boxes # Get the boxes for the first result
232
+ >>> masks = result.masks # Get the masks for the first result
224
233
  >>> for result in results:
225
- ... print(result.boxes) # Print detection boxes
226
- ... result.show() # Display the annotated image
227
- ... result.save(filename="result.jpg") # Save annotated image
234
+ >>> result.plot() # Plot detection results
228
235
  """
229
236
 
230
237
  def __init__(
@@ -766,8 +773,8 @@ class Results(SimpleClass):
766
773
  optionally mask segments and keypoints.
767
774
 
768
775
  Args:
769
- normalize (bool): Whether to normalize bounding box coordinates by image dimensions. Defaults to False.
770
- decimals (int): Number of decimal places to round the output values to. Defaults to 5.
776
+ normalize (bool): Whether to normalize bounding box coordinates by image dimensions.
777
+ decimals (int): Number of decimal places to round the output values to.
771
778
 
772
779
  Returns:
773
780
  (List[Dict]): A list of dictionaries, each containing summarized information for a single
@@ -832,8 +839,8 @@ class Results(SimpleClass):
832
839
 
833
840
  Args:
834
841
  normalize (bool): Whether to normalize the bounding box coordinates by the image dimensions.
835
- If True, coordinates will be returned as float values between 0 and 1. Defaults to False.
836
- decimals (int): Number of decimal places to round the output values to. Defaults to 5.
842
+ If True, coordinates will be returned as float values between 0 and 1.
843
+ decimals (int): Number of decimal places to round the output values to.
837
844
 
838
845
  Returns:
839
846
  (DataFrame): A Pandas Dataframe containing all the information in results in an organized way.
@@ -858,8 +865,8 @@ class Results(SimpleClass):
858
865
 
859
866
  Args:
860
867
  normalize (bool): Whether to normalize the bounding box coordinates by the image dimensions.
861
- If True, coordinates will be returned as float values between 0 and 1. Defaults to False.
862
- decimals (int): Number of decimal places to round the output values to. Defaults to 5.
868
+ If True, coordinates will be returned as float values between 0 and 1.
869
+ decimals (int): Number of decimal places to round the output values to.
863
870
  *args (Any): Variable length argument list to be passed to pandas.DataFrame.to_csv().
864
871
  **kwargs (Any): Arbitrary keyword arguments to be passed to pandas.DataFrame.to_csv().
865
872
 
@@ -885,8 +892,8 @@ class Results(SimpleClass):
885
892
 
886
893
  Args:
887
894
  normalize (bool): Whether to normalize the bounding box coordinates by the image dimensions.
888
- If True, coordinates will be returned as float values between 0 and 1. Defaults to False.
889
- decimals (int): Number of decimal places to round the output values to. Defaults to 5.
895
+ If True, coordinates will be returned as float values between 0 and 1.
896
+ decimals (int): Number of decimal places to round the output values to.
890
897
  *args (Any): Variable length argument list to be passed to pandas.DataFrame.to_xml().
891
898
  **kwargs (Any): Arbitrary keyword arguments to be passed to pandas.DataFrame.to_xml().
892
899
 
@@ -903,6 +910,34 @@ class Results(SimpleClass):
903
910
  df = self.to_df(normalize=normalize, decimals=decimals)
904
911
  return '<?xml version="1.0" encoding="utf-8"?>\n<root></root>' if df.empty else df.to_xml(*args, **kwargs)
905
912
 
913
+ def to_html(self, normalize=False, decimals=5, index=False, *args, **kwargs):
914
+ """
915
+ Converts detection results to HTML format.
916
+
917
+ This method serializes the detection results into an HTML format. It includes information
918
+ about detected objects such as bounding boxes, class names, confidence scores, and optionally
919
+ segmentation masks and keypoints.
920
+
921
+ Args:
922
+ normalize (bool): Whether to normalize the bounding box coordinates by the image dimensions.
923
+ If True, coordinates will be returned as float values between 0 and 1.
924
+ decimals (int): Number of decimal places to round the output values to.
925
+ index (bool): Whether to include the DataFrame index in the HTML output.
926
+ *args (Any): Variable length argument list to be passed to pandas.DataFrame.to_html().
927
+ **kwargs (Any): Arbitrary keyword arguments to be passed to pandas.DataFrame.to_html().
928
+
929
+ Returns:
930
+ (str): An HTML string containing all the information in results in an organized way.
931
+
932
+ Examples:
933
+ >>> results = model("path/to/image.jpg")
934
+ >>> for result in results:
935
+ >>> html_result = result.to_html()
936
+ >>> print(html_result)
937
+ """
938
+ df = self.to_df(normalize=normalize, decimals=decimals)
939
+ return "<table></table>" if df.empty else df.to_html(index=index, *args, **kwargs)
940
+
906
941
  def tojson(self, normalize=False, decimals=5):
907
942
  """Deprecated version of to_json()."""
908
943
  LOGGER.warning("WARNING ⚠️ 'result.tojson()' is deprecated, replace with 'result.to_json()'.")
@@ -918,8 +953,8 @@ class Results(SimpleClass):
918
953
 
919
954
  Args:
920
955
  normalize (bool): Whether to normalize the bounding box coordinates by the image dimensions.
921
- If True, coordinates will be returned as float values between 0 and 1. Defaults to False.
922
- decimals (int): Number of decimal places to round the output values to. Defaults to 5.
956
+ If True, coordinates will be returned as float values between 0 and 1.
957
+ decimals (int): Number of decimal places to round the output values to.
923
958
 
924
959
  Returns:
925
960
  (str): A JSON string containing the serialized detection results.
@@ -951,11 +986,11 @@ class Results(SimpleClass):
951
986
  and optionally segmentation masks, keypoints or oriented bounding boxes.
952
987
 
953
988
  Args:
954
- table_name (str): Name of the SQL table where the data will be inserted. Defaults to "detection_results".
989
+ table_name (str): Name of the SQL table where the data will be inserted.
955
990
  normalize (bool): Whether to normalize the bounding box coordinates by the image dimensions.
956
- If True, coordinates will be returned as float values between 0 and 1. Defaults to False.
957
- decimals (int): Number of decimal places to round the bounding boxes values to. Defaults to 5.
958
- db_path (str): Path to the SQLite database file. Defaults to "results.db".
991
+ If True, coordinates will be returned as float values between 0 and 1.
992
+ decimals (int): Number of decimal places to round the bounding boxes values to.
993
+ db_path (str): Path to the SQLite database file.
959
994
 
960
995
  Examples:
961
996
  >>> results = model("path/to/image.jpg")