ultralytics 8.3.53__py3-none-any.whl → 8.3.55__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.
- tests/__init__.py +0 -1
- tests/conftest.py +2 -2
- tests/test_cli.py +2 -1
- tests/test_python.py +2 -2
- tests/test_solutions.py +11 -9
- ultralytics/__init__.py +1 -1
- ultralytics/cfg/__init__.py +57 -56
- ultralytics/cfg/datasets/coco-pose.yaml +4 -4
- ultralytics/cfg/datasets/lvis.yaml +1 -1
- ultralytics/cfg/datasets/medical-pills.yaml +21 -0
- ultralytics/cfg/solutions/default.yaml +1 -1
- ultralytics/data/augment.py +6 -3
- ultralytics/data/dataset.py +2 -2
- ultralytics/engine/exporter.py +11 -11
- ultralytics/engine/model.py +22 -24
- ultralytics/engine/validator.py +1 -1
- ultralytics/models/sam/modules/tiny_encoder.py +2 -1
- ultralytics/models/sam/predict.py +1 -1
- ultralytics/nn/autobackend.py +7 -10
- ultralytics/solutions/__init__.py +2 -2
- ultralytics/solutions/analytics.py +1 -1
- ultralytics/solutions/distance_calculation.py +2 -0
- ultralytics/solutions/heatmap.py +1 -0
- ultralytics/solutions/parking_management.py +25 -14
- ultralytics/solutions/region_counter.py +4 -0
- ultralytics/solutions/security_alarm.py +9 -6
- ultralytics/solutions/solutions.py +8 -0
- ultralytics/solutions/streamlit_inference.py +180 -133
- ultralytics/utils/benchmarks.py +2 -1
- ultralytics/utils/downloads.py +1 -1
- ultralytics/utils/instance.py +1 -1
- ultralytics/utils/metrics.py +3 -4
- ultralytics/utils/plotting.py +2 -1
- {ultralytics-8.3.53.dist-info → ultralytics-8.3.55.dist-info}/METADATA +2 -2
- {ultralytics-8.3.53.dist-info → ultralytics-8.3.55.dist-info}/RECORD +39 -38
- {ultralytics-8.3.53.dist-info → ultralytics-8.3.55.dist-info}/LICENSE +0 -0
- {ultralytics-8.3.53.dist-info → ultralytics-8.3.55.dist-info}/WHEEL +0 -0
- {ultralytics-8.3.53.dist-info → ultralytics-8.3.55.dist-info}/entry_points.txt +0 -0
- {ultralytics-8.3.53.dist-info → ultralytics-8.3.55.dist-info}/top_level.txt +0 -0
tests/__init__.py
CHANGED
tests/conftest.py
CHANGED
@@ -74,10 +74,10 @@ def pytest_terminal_summary(terminalreporter, exitstatus, config):
|
|
74
74
|
|
75
75
|
# Remove files
|
76
76
|
models = [path for x in ["*.onnx", "*.torchscript"] for path in WEIGHTS_DIR.rglob(x)]
|
77
|
-
for file in ["bus.jpg", "yolo11n.onnx", "yolo11n.torchscript"] + models:
|
77
|
+
for file in ["decelera_portrait_min.mov", "bus.jpg", "yolo11n.onnx", "yolo11n.torchscript"] + models:
|
78
78
|
Path(file).unlink(missing_ok=True)
|
79
79
|
|
80
80
|
# Remove directories
|
81
81
|
models = [path for x in ["*.mlpackage", "*_openvino_model"] for path in WEIGHTS_DIR.rglob(x)]
|
82
|
-
for directory in [TMP.parents[1] / ".pytest_cache", TMP] + models:
|
82
|
+
for directory in [WEIGHTS_DIR / "path with spaces", TMP.parents[1] / ".pytest_cache", TMP] + models:
|
83
83
|
shutil.rmtree(directory, ignore_errors=True)
|
tests/test_cli.py
CHANGED
@@ -59,7 +59,8 @@ def test_rtdetr(task="detect", model="yolov8n-rtdetr.yaml", data="coco8.yaml"):
|
|
59
59
|
run(f"yolo train {task} model={model} data={data} --imgsz= 160 epochs =1, cache = disk fraction=0.25")
|
60
60
|
run(f"yolo predict {task} model={model} source={ASSETS / 'bus.jpg'} imgsz=160 save save_crop save_txt")
|
61
61
|
if TORCH_1_9:
|
62
|
-
|
62
|
+
weights = WEIGHTS_DIR / "rtdetr-l.pt"
|
63
|
+
run(f"yolo predict {task} model={weights} source={ASSETS / 'bus.jpg'} imgsz=160 save save_crop save_txt")
|
63
64
|
|
64
65
|
|
65
66
|
@pytest.mark.skipif(checks.IS_PYTHON_3_12, reason="MobileSAM with CLIP is not supported in Python 3.12")
|
tests/test_python.py
CHANGED
@@ -576,11 +576,11 @@ def test_model_embeddings():
|
|
576
576
|
@pytest.mark.skipif(checks.IS_PYTHON_3_12, reason="YOLOWorld with CLIP is not supported in Python 3.12")
|
577
577
|
def test_yolo_world():
|
578
578
|
"""Tests YOLO world models with CLIP support, including detection and training scenarios."""
|
579
|
-
model = YOLO("yolov8s-world.pt") # no YOLO11n-world model yet
|
579
|
+
model = YOLO(WEIGHTS_DIR / "yolov8s-world.pt") # no YOLO11n-world model yet
|
580
580
|
model.set_classes(["tree", "window"])
|
581
581
|
model(SOURCE, conf=0.01)
|
582
582
|
|
583
|
-
model = YOLO("yolov8s-worldv2.pt") # no YOLO11n-world model yet
|
583
|
+
model = YOLO(WEIGHTS_DIR / "yolov8s-worldv2.pt") # no YOLO11n-world model yet
|
584
584
|
# Training from a pretrained model. Eval is included at the final stage of training.
|
585
585
|
# Use dota8.yaml which has fewer categories to reduce the inference time of CLIP model
|
586
586
|
model.train(
|
tests/test_solutions.py
CHANGED
@@ -3,18 +3,20 @@
|
|
3
3
|
import cv2
|
4
4
|
import pytest
|
5
5
|
|
6
|
+
from tests import TMP
|
6
7
|
from ultralytics import YOLO, solutions
|
8
|
+
from ultralytics.utils import ASSETS_URL, WEIGHTS_DIR
|
7
9
|
from ultralytics.utils.downloads import safe_download
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
DEMO_VIDEO = "solutions_ci_demo.mp4"
|
12
|
+
POSE_VIDEO = "solution_ci_pose_demo.mp4"
|
11
13
|
|
12
14
|
|
13
15
|
@pytest.mark.slow
|
14
16
|
def test_major_solutions():
|
15
17
|
"""Test the object counting, heatmap, speed estimation and queue management solution."""
|
16
|
-
safe_download(url=
|
17
|
-
cap = cv2.VideoCapture(
|
18
|
+
safe_download(url=f"{ASSETS_URL}/{DEMO_VIDEO}", dir=TMP)
|
19
|
+
cap = cv2.VideoCapture(str(TMP / DEMO_VIDEO))
|
18
20
|
assert cap.isOpened(), "Error reading video file"
|
19
21
|
region_points = [(20, 400), (1080, 400), (1080, 360), (20, 360)]
|
20
22
|
counter = solutions.ObjectCounter(region=region_points, model="yolo11n.pt", show=False) # Test object counter
|
@@ -42,8 +44,8 @@ def test_major_solutions():
|
|
42
44
|
cap.release()
|
43
45
|
|
44
46
|
# Test workouts monitoring
|
45
|
-
safe_download(url=
|
46
|
-
cap1 = cv2.VideoCapture(
|
47
|
+
safe_download(url=f"{ASSETS_URL}/{POSE_VIDEO}", dir=TMP)
|
48
|
+
cap1 = cv2.VideoCapture(str(TMP / POSE_VIDEO))
|
47
49
|
assert cap1.isOpened(), "Error reading video file"
|
48
50
|
gym = solutions.AIGym(line_width=2, kpts=[5, 11, 13], show=False)
|
49
51
|
while cap1.isOpened():
|
@@ -59,9 +61,9 @@ def test_instance_segmentation():
|
|
59
61
|
"""Test the instance segmentation solution."""
|
60
62
|
from ultralytics.utils.plotting import Annotator, colors
|
61
63
|
|
62
|
-
model = YOLO("yolo11n-seg.pt")
|
64
|
+
model = YOLO(WEIGHTS_DIR / "yolo11n-seg.pt")
|
63
65
|
names = model.names
|
64
|
-
cap = cv2.VideoCapture(
|
66
|
+
cap = cv2.VideoCapture(TMP / DEMO_VIDEO)
|
65
67
|
assert cap.isOpened(), "Error reading video file"
|
66
68
|
while cap.isOpened():
|
67
69
|
success, im0 = cap.read()
|
@@ -82,4 +84,4 @@ def test_instance_segmentation():
|
|
82
84
|
@pytest.mark.slow
|
83
85
|
def test_streamlit_predict():
|
84
86
|
"""Test streamlit predict live inference solution."""
|
85
|
-
solutions.inference()
|
87
|
+
solutions.Inference().inference()
|
ultralytics/__init__.py
CHANGED
ultralytics/cfg/__init__.py
CHANGED
@@ -42,6 +42,7 @@ SOLUTION_MAP = {
|
|
42
42
|
"workout": ("AIGym", "monitor"),
|
43
43
|
"analytics": ("Analytics", "process_data"),
|
44
44
|
"trackzone": ("TrackZone", "trackzone"),
|
45
|
+
"inference": ("Inference", "inference"),
|
45
46
|
"help": None,
|
46
47
|
}
|
47
48
|
|
@@ -85,7 +86,7 @@ SOLUTIONS_HELP_MSG = f"""
|
|
85
86
|
yolo solutions count source="path/to/video/file.mp4" region=[(20, 400), (1080, 400), (1080, 360), (20, 360)]
|
86
87
|
|
87
88
|
2. Call heatmaps solution
|
88
|
-
yolo solutions heatmap colormap=cv2.
|
89
|
+
yolo solutions heatmap colormap=cv2.COLORMAP_PARULA model=yolo11n.pt
|
89
90
|
|
90
91
|
3. Call queue management solution
|
91
92
|
yolo solutions queue region=[(20, 400), (1080, 400), (1080, 360), (20, 360)] model=yolo11n.pt
|
@@ -97,7 +98,10 @@ SOLUTIONS_HELP_MSG = f"""
|
|
97
98
|
yolo solutions analytics analytics_type="pie"
|
98
99
|
|
99
100
|
6. Track objects within specific zones
|
100
|
-
yolo solutions trackzone source="path/to/video/file.mp4" region=[(150, 150), (1130, 150), (1130, 570), (150, 570)]
|
101
|
+
yolo solutions trackzone source="path/to/video/file.mp4" region=[(150, 150), (1130, 150), (1130, 570), (150, 570)]
|
102
|
+
|
103
|
+
7. Streamlit real-time webcam inference GUI
|
104
|
+
yolo streamlit-predict
|
101
105
|
"""
|
102
106
|
CLI_HELP_MSG = f"""
|
103
107
|
Arguments received: {str(['yolo'] + ARGV[1:])}. Ultralytics 'yolo' commands use the following syntax:
|
@@ -121,13 +125,10 @@ CLI_HELP_MSG = f"""
|
|
121
125
|
4. Export a YOLO11n classification model to ONNX format at image size 224 by 128 (no TASK required)
|
122
126
|
yolo export model=yolo11n-cls.pt format=onnx imgsz=224,128
|
123
127
|
|
124
|
-
5.
|
125
|
-
yolo streamlit-predict
|
126
|
-
|
127
|
-
6. Ultralytics solutions usage
|
128
|
+
5. Ultralytics solutions usage
|
128
129
|
yolo solutions count or in {list(SOLUTION_MAP.keys())[1:-1]} source="path/to/video/file.mp4"
|
129
130
|
|
130
|
-
|
131
|
+
6. Run special commands:
|
131
132
|
yolo help
|
132
133
|
yolo checks
|
133
134
|
yolo version
|
@@ -636,6 +637,9 @@ def handle_yolo_solutions(args: List[str]) -> None:
|
|
636
637
|
Run analytics with custom configuration:
|
637
638
|
>>> handle_yolo_solutions(["analytics", "conf=0.25", "source=path/to/video/file.mp4"])
|
638
639
|
|
640
|
+
Run inference with custom configuration, requires Streamlit version 1.29.0 or higher.
|
641
|
+
>>> handle_yolo_solutions(["inference", "model=yolo11n.pt"])
|
642
|
+
|
639
643
|
Notes:
|
640
644
|
- Default configurations are merged from DEFAULT_SOL_DICT and DEFAULT_CFG_DICT
|
641
645
|
- Arguments can be provided in the format 'key=value' or as boolean flags
|
@@ -645,7 +649,9 @@ def handle_yolo_solutions(args: List[str]) -> None:
|
|
645
649
|
- For 'analytics' solution, frame numbers are tracked for generating analytical graphs
|
646
650
|
- Video processing can be interrupted by pressing 'q'
|
647
651
|
- Processes video frames sequentially and saves output in .avi format
|
648
|
-
- If no source is specified, downloads and uses a default sample video
|
652
|
+
- If no source is specified, downloads and uses a default sample video\
|
653
|
+
- The inference solution will be launched using the 'streamlit run' command.
|
654
|
+
- The Streamlit app file is located in the Ultralytics package directory.
|
649
655
|
"""
|
650
656
|
full_args_dict = {**DEFAULT_SOL_DICT, **DEFAULT_CFG_DICT} # arguments dictionary
|
651
657
|
overrides = {}
|
@@ -678,60 +684,56 @@ def handle_yolo_solutions(args: List[str]) -> None:
|
|
678
684
|
if args and args[0] == "help": # Add check for return if user call `yolo solutions help`
|
679
685
|
return
|
680
686
|
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
687
|
+
if s_n == "inference":
|
688
|
+
checks.check_requirements("streamlit>=1.29.0")
|
689
|
+
LOGGER.info("💡 Loading Ultralytics live inference app...")
|
690
|
+
subprocess.run(
|
691
|
+
[ # Run subprocess with Streamlit custom argument
|
692
|
+
"streamlit",
|
693
|
+
"run",
|
694
|
+
str(ROOT / "solutions/streamlit_inference.py"),
|
695
|
+
"--server.headless",
|
696
|
+
"true",
|
697
|
+
overrides.pop("model", "yolo11n.pt"),
|
698
|
+
]
|
699
|
+
)
|
700
|
+
else:
|
701
|
+
cls, method = SOLUTION_MAP[s_n] # solution class name, method name and default source
|
695
702
|
|
696
|
-
|
697
|
-
if s_n == "analytics": # analytical graphs follow fixed shape for output i.e w=1920, h=1080
|
698
|
-
w, h = 1920, 1080
|
699
|
-
save_dir = increment_path(Path("runs") / "solutions" / "exp", exist_ok=False)
|
700
|
-
save_dir.mkdir(parents=True, exist_ok=True) # create the output directory
|
701
|
-
vw = cv2.VideoWriter(os.path.join(save_dir, "solution.avi"), cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
|
703
|
+
from ultralytics import solutions # import ultralytics solutions
|
702
704
|
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
if not success:
|
708
|
-
break
|
709
|
-
frame = process(frame, f_n := f_n + 1) if s_n == "analytics" else process(frame)
|
710
|
-
vw.write(frame)
|
711
|
-
if cv2.waitKey(1) & 0xFF == ord("q"):
|
712
|
-
break
|
713
|
-
finally:
|
714
|
-
cap.release()
|
705
|
+
solution = getattr(solutions, cls)(IS_CLI=True, **overrides) # get solution class i.e ObjectCounter
|
706
|
+
process = getattr(
|
707
|
+
solution, method
|
708
|
+
) # get specific function of class for processing i.e, count from ObjectCounter
|
715
709
|
|
710
|
+
cap = cv2.VideoCapture(solution.CFG["source"]) # read the video file
|
716
711
|
|
717
|
-
|
718
|
-
|
719
|
-
|
712
|
+
# extract width, height and fps of the video file, create save directory and initialize video writer
|
713
|
+
import os # for directory creation
|
714
|
+
from pathlib import Path
|
720
715
|
|
721
|
-
|
722
|
-
Ultralytics models. It checks for the required Streamlit package and launches the app.
|
716
|
+
from ultralytics.utils.files import increment_path # for output directory path update
|
723
717
|
|
724
|
-
|
725
|
-
|
718
|
+
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
|
719
|
+
if s_n == "analytics": # analytical graphs follow fixed shape for output i.e w=1920, h=1080
|
720
|
+
w, h = 1920, 1080
|
721
|
+
save_dir = increment_path(Path("runs") / "solutions" / "exp", exist_ok=False)
|
722
|
+
save_dir.mkdir(parents=True, exist_ok=True) # create the output directory
|
723
|
+
vw = cv2.VideoWriter(os.path.join(save_dir, "solution.avi"), cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
|
726
724
|
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
725
|
+
try: # Process video frames
|
726
|
+
f_n = 0 # frame number, required for analytical graphs
|
727
|
+
while cap.isOpened():
|
728
|
+
success, frame = cap.read()
|
729
|
+
if not success:
|
730
|
+
break
|
731
|
+
frame = process(frame, f_n := f_n + 1) if s_n == "analytics" else process(frame)
|
732
|
+
vw.write(frame)
|
733
|
+
if cv2.waitKey(1) & 0xFF == ord("q"):
|
734
|
+
break
|
735
|
+
finally:
|
736
|
+
cap.release()
|
735
737
|
|
736
738
|
|
737
739
|
def parse_key_value_pair(pair: str = "key=value"):
|
@@ -853,7 +855,6 @@ def entrypoint(debug=""):
|
|
853
855
|
"login": lambda: handle_yolo_hub(args),
|
854
856
|
"logout": lambda: handle_yolo_hub(args),
|
855
857
|
"copy-cfg": copy_default_cfg,
|
856
|
-
"streamlit-predict": lambda: handle_streamlit_inference(),
|
857
858
|
"solutions": lambda: handle_yolo_solutions(args[1:]),
|
858
859
|
}
|
859
860
|
full_args_dict = {**DEFAULT_CFG_DICT, **{k: None for k in TASKS}, **{k: None for k in MODES}, **special}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Ultralytics YOLO 🚀, AGPL-3.0 license
|
2
|
-
# COCO 2017 dataset https://cocodataset.org by Microsoft
|
2
|
+
# COCO 2017 Keypoints dataset https://cocodataset.org by Microsoft
|
3
3
|
# Documentation: https://docs.ultralytics.com/datasets/pose/coco/
|
4
4
|
# Example usage: yolo train data=coco-pose.yaml
|
5
5
|
# parent
|
@@ -9,9 +9,9 @@
|
|
9
9
|
|
10
10
|
# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
|
11
11
|
path: ../datasets/coco-pose # dataset root dir
|
12
|
-
train: train2017.txt # train images (relative to 'path')
|
13
|
-
val: val2017.txt # val images (relative to 'path')
|
14
|
-
test: test-dev2017.txt # 20288 of 40670 images, submit to https://
|
12
|
+
train: train2017.txt # train images (relative to 'path') 56599 images
|
13
|
+
val: val2017.txt # val images (relative to 'path') 2346 images
|
14
|
+
test: test-dev2017.txt # 20288 of 40670 images, submit to https://codalab.lisn.upsaclay.fr/competitions/7403
|
15
15
|
|
16
16
|
# Keypoints
|
17
17
|
kpt_shape: [17, 3] # number of keypoints, number of dims (2 for x,y or 3 for x,y,visible)
|
@@ -11,7 +11,7 @@
|
|
11
11
|
path: ../datasets/lvis # dataset root dir
|
12
12
|
train: train.txt # train images (relative to 'path') 100170 images
|
13
13
|
val: val.txt # val images (relative to 'path') 19809 images
|
14
|
-
minival: minival.txt #
|
14
|
+
minival: minival.txt # minival images (relative to 'path') 5000 images
|
15
15
|
|
16
16
|
names:
|
17
17
|
0: aerosol can/spray can
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Ultralytics YOLO 🚀, AGPL-3.0 license
|
2
|
+
# Medical-pills dataset by Ultralytics
|
3
|
+
# Documentation: https://docs.ultralytics.com/datasets/detect/medical-pills/
|
4
|
+
# Example usage: yolo train data=medical-pills.yaml
|
5
|
+
# parent
|
6
|
+
# ├── ultralytics
|
7
|
+
# └── datasets
|
8
|
+
# └── medical-pills ← downloads here (8.19 MB)
|
9
|
+
|
10
|
+
# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
|
11
|
+
path: ../datasets/medical-pills # dataset root dir
|
12
|
+
train: train/images # train images (relative to 'path') 92 images
|
13
|
+
val: valid/images # val images (relative to 'path') 23 images
|
14
|
+
test: # test images (relative to 'path')
|
15
|
+
|
16
|
+
# Classes
|
17
|
+
names:
|
18
|
+
0: pill
|
19
|
+
|
20
|
+
# Download script/URL (optional)
|
21
|
+
download: https://github.com/ultralytics/assets/releases/download/v0.0.0/medical-pills.zip
|
@@ -12,7 +12,7 @@ colormap: # (int | str) colormap for heatmap, Only OPENCV supported colormaps c
|
|
12
12
|
# Workouts monitoring settings -----------------------------------------------------------------------------------------
|
13
13
|
up_angle: 145.0 # (float) Workouts up_angle for counts, 145.0 is default value.
|
14
14
|
down_angle: 90 # (float) Workouts down_angle for counts, 90 is default value. Y
|
15
|
-
kpts: [6, 8, 10] # (list[int]) keypoints for workouts monitoring, i.e. for
|
15
|
+
kpts: [6, 8, 10] # (list[int]) keypoints for workouts monitoring, i.e. for push-ups kpts have values of [6, 8, 10].
|
16
16
|
|
17
17
|
# Analytics settings ---------------------------------------------------------------------------------------------------
|
18
18
|
analytics_type: "line" # (str) analytics type i.e "line", "pie", "bar" or "area" charts.
|
ultralytics/data/augment.py
CHANGED
@@ -441,7 +441,8 @@ class BaseMixTransform:
|
|
441
441
|
"""
|
442
442
|
raise NotImplementedError
|
443
443
|
|
444
|
-
|
444
|
+
@staticmethod
|
445
|
+
def _update_label_text(labels):
|
445
446
|
"""
|
446
447
|
Updates label text and class IDs for mixed labels in image augmentation.
|
447
448
|
|
@@ -1259,7 +1260,8 @@ class RandomPerspective:
|
|
1259
1260
|
labels["resized_shape"] = img.shape[:2]
|
1260
1261
|
return labels
|
1261
1262
|
|
1262
|
-
|
1263
|
+
@staticmethod
|
1264
|
+
def box_candidates(box1, box2, wh_thr=2, ar_thr=100, area_thr=0.1, eps=1e-16):
|
1263
1265
|
"""
|
1264
1266
|
Compute candidate boxes for further processing based on size and aspect ratio criteria.
|
1265
1267
|
|
@@ -1598,7 +1600,8 @@ class LetterBox:
|
|
1598
1600
|
else:
|
1599
1601
|
return img
|
1600
1602
|
|
1601
|
-
|
1603
|
+
@staticmethod
|
1604
|
+
def _update_labels(labels, ratio, padw, padh):
|
1602
1605
|
"""
|
1603
1606
|
Updates labels after applying letterboxing to an image.
|
1604
1607
|
|
ultralytics/data/dataset.py
CHANGED
@@ -68,7 +68,7 @@ class YOLODataset(BaseDataset):
|
|
68
68
|
Cache dataset labels, check images and read shapes.
|
69
69
|
|
70
70
|
Args:
|
71
|
-
path (Path): Path where to save the cache file. Default is Path(
|
71
|
+
path (Path): Path where to save the cache file. Default is Path("./labels.cache").
|
72
72
|
|
73
73
|
Returns:
|
74
74
|
(dict): labels.
|
@@ -219,7 +219,7 @@ class YOLODataset(BaseDataset):
|
|
219
219
|
segment_resamples = 100 if self.use_obb else 1000
|
220
220
|
if len(segments) > 0:
|
221
221
|
# make sure segments interpolate correctly if original length is greater than segment_resamples
|
222
|
-
max_len = max(
|
222
|
+
max_len = max(len(s) for s in segments)
|
223
223
|
segment_resamples = (max_len + 1) if segment_resamples < max_len else segment_resamples
|
224
224
|
# list[np.array(segment_resamples, 2)] * num_samples
|
225
225
|
segments = np.stack(resample_segments(segments, n=segment_resamples), axis=0)
|
ultralytics/engine/exporter.py
CHANGED
@@ -102,19 +102,19 @@ def export_formats():
|
|
102
102
|
"""Ultralytics YOLO export formats."""
|
103
103
|
x = [
|
104
104
|
["PyTorch", "-", ".pt", True, True, []],
|
105
|
-
["TorchScript", "torchscript", ".torchscript", True, True, ["
|
106
|
-
["ONNX", "onnx", ".onnx", True, True, ["
|
107
|
-
["OpenVINO", "openvino", "_openvino_model", True, False, ["
|
108
|
-
["TensorRT", "engine", ".engine", False, True, ["
|
109
|
-
["CoreML", "coreml", ".mlpackage", True, False, ["
|
110
|
-
["TensorFlow SavedModel", "saved_model", "_saved_model", True, True, ["
|
105
|
+
["TorchScript", "torchscript", ".torchscript", True, True, ["batch", "optimize"]],
|
106
|
+
["ONNX", "onnx", ".onnx", True, True, ["batch", "dynamic", "half", "opset", "simplify"]],
|
107
|
+
["OpenVINO", "openvino", "_openvino_model", True, False, ["batch", "dynamic", "half", "int8"]],
|
108
|
+
["TensorRT", "engine", ".engine", False, True, ["batch", "dynamic", "half", "int8", "simplify"]],
|
109
|
+
["CoreML", "coreml", ".mlpackage", True, False, ["batch", "half", "int8", "nms"]],
|
110
|
+
["TensorFlow SavedModel", "saved_model", "_saved_model", True, True, ["batch", "int8", "keras"]],
|
111
111
|
["TensorFlow GraphDef", "pb", ".pb", True, True, ["batch"]],
|
112
|
-
["TensorFlow Lite", "tflite", ".tflite", True, False, ["
|
112
|
+
["TensorFlow Lite", "tflite", ".tflite", True, False, ["batch", "half", "int8"]],
|
113
113
|
["TensorFlow Edge TPU", "edgetpu", "_edgetpu.tflite", True, False, []],
|
114
|
-
["TensorFlow.js", "tfjs", "_web_model", True, False, ["
|
114
|
+
["TensorFlow.js", "tfjs", "_web_model", True, False, ["batch", "half", "int8"]],
|
115
115
|
["PaddlePaddle", "paddle", "_paddle_model", True, True, ["batch"]],
|
116
|
-
["MNN", "mnn", ".mnn", True, True, ["batch", "
|
117
|
-
["NCNN", "ncnn", "_ncnn_model", True, True, ["
|
116
|
+
["MNN", "mnn", ".mnn", True, True, ["batch", "half", "int8"]],
|
117
|
+
["NCNN", "ncnn", "_ncnn_model", True, True, ["batch", "half"]],
|
118
118
|
["IMX", "imx", "_imx_model", True, True, ["int8"]],
|
119
119
|
]
|
120
120
|
return dict(zip(["Format", "Argument", "Suffix", "CPU", "GPU", "Arguments"], zip(*x)))
|
@@ -813,7 +813,7 @@ class Exporter:
|
|
813
813
|
workspace = int(self.args.workspace * (1 << 30)) if self.args.workspace is not None else 0
|
814
814
|
if is_trt10 and workspace > 0:
|
815
815
|
config.set_memory_pool_limit(trt.MemoryPoolType.WORKSPACE, workspace)
|
816
|
-
elif workspace > 0
|
816
|
+
elif workspace > 0: # TensorRT versions 7, 8
|
817
817
|
config.max_workspace_size = workspace
|
818
818
|
flag = 1 << int(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH)
|
819
819
|
network = builder.create_network(flag)
|
ultralytics/engine/model.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
import inspect
|
4
4
|
from pathlib import Path
|
5
|
-
from typing import Dict, List, Union
|
5
|
+
from typing import Any, Dict, List, Union
|
6
6
|
|
7
7
|
import numpy as np
|
8
8
|
import torch
|
@@ -152,7 +152,7 @@ class Model(nn.Module):
|
|
152
152
|
self,
|
153
153
|
source: Union[str, Path, int, Image.Image, list, tuple, np.ndarray, torch.Tensor] = None,
|
154
154
|
stream: bool = False,
|
155
|
-
**kwargs,
|
155
|
+
**kwargs: Any,
|
156
156
|
) -> list:
|
157
157
|
"""
|
158
158
|
Alias for the predict method, enabling the model instance to be callable for predictions.
|
@@ -165,7 +165,7 @@ class Model(nn.Module):
|
|
165
165
|
the image(s) to make predictions on. Can be a file path, URL, PIL image, numpy array, PyTorch
|
166
166
|
tensor, or a list/tuple of these.
|
167
167
|
stream (bool): If True, treat the input source as a continuous stream for predictions.
|
168
|
-
**kwargs
|
168
|
+
**kwargs: Additional keyword arguments to configure the prediction process.
|
169
169
|
|
170
170
|
Returns:
|
171
171
|
(List[ultralytics.engine.results.Results]): A list of prediction results, each encapsulated in a
|
@@ -466,7 +466,7 @@ class Model(nn.Module):
|
|
466
466
|
self,
|
467
467
|
source: Union[str, Path, int, list, tuple, np.ndarray, torch.Tensor] = None,
|
468
468
|
stream: bool = False,
|
469
|
-
**kwargs,
|
469
|
+
**kwargs: Any,
|
470
470
|
) -> list:
|
471
471
|
"""
|
472
472
|
Generates image embeddings based on the provided source.
|
@@ -478,7 +478,7 @@ class Model(nn.Module):
|
|
478
478
|
source (str | Path | int | List | Tuple | np.ndarray | torch.Tensor): The source of the image for
|
479
479
|
generating embeddings. Can be a file path, URL, PIL image, numpy array, etc.
|
480
480
|
stream (bool): If True, predictions are streamed.
|
481
|
-
**kwargs
|
481
|
+
**kwargs: Additional keyword arguments for configuring the embedding process.
|
482
482
|
|
483
483
|
Returns:
|
484
484
|
(List[torch.Tensor]): A list containing the image embeddings.
|
@@ -501,7 +501,7 @@ class Model(nn.Module):
|
|
501
501
|
source: Union[str, Path, int, Image.Image, list, tuple, np.ndarray, torch.Tensor] = None,
|
502
502
|
stream: bool = False,
|
503
503
|
predictor=None,
|
504
|
-
**kwargs,
|
504
|
+
**kwargs: Any,
|
505
505
|
) -> List[Results]:
|
506
506
|
"""
|
507
507
|
Performs predictions on the given image source using the YOLO model.
|
@@ -517,7 +517,7 @@ class Model(nn.Module):
|
|
517
517
|
stream (bool): If True, treats the input source as a continuous stream for predictions.
|
518
518
|
predictor (BasePredictor | None): An instance of a custom predictor class for making predictions.
|
519
519
|
If None, the method uses a default predictor.
|
520
|
-
**kwargs
|
520
|
+
**kwargs: Additional keyword arguments for configuring the prediction process.
|
521
521
|
|
522
522
|
Returns:
|
523
523
|
(List[ultralytics.engine.results.Results]): A list of prediction results, each encapsulated in a
|
@@ -562,7 +562,7 @@ class Model(nn.Module):
|
|
562
562
|
source: Union[str, Path, int, list, tuple, np.ndarray, torch.Tensor] = None,
|
563
563
|
stream: bool = False,
|
564
564
|
persist: bool = False,
|
565
|
-
**kwargs,
|
565
|
+
**kwargs: Any,
|
566
566
|
) -> List[Results]:
|
567
567
|
"""
|
568
568
|
Conducts object tracking on the specified input source using the registered trackers.
|
@@ -576,7 +576,7 @@ class Model(nn.Module):
|
|
576
576
|
tracking. Can be a file path, URL, or video stream.
|
577
577
|
stream (bool): If True, treats the input source as a continuous video stream. Defaults to False.
|
578
578
|
persist (bool): If True, persists trackers between different calls to this method. Defaults to False.
|
579
|
-
**kwargs
|
579
|
+
**kwargs: Additional keyword arguments for configuring the tracking process.
|
580
580
|
|
581
581
|
Returns:
|
582
582
|
(List[ultralytics.engine.results.Results]): A list of tracking results, each a Results object.
|
@@ -607,7 +607,7 @@ class Model(nn.Module):
|
|
607
607
|
def val(
|
608
608
|
self,
|
609
609
|
validator=None,
|
610
|
-
**kwargs,
|
610
|
+
**kwargs: Any,
|
611
611
|
):
|
612
612
|
"""
|
613
613
|
Validates the model using a specified dataset and validation configuration.
|
@@ -619,7 +619,7 @@ class Model(nn.Module):
|
|
619
619
|
Args:
|
620
620
|
validator (ultralytics.engine.validator.BaseValidator | None): An instance of a custom validator class for
|
621
621
|
validating the model.
|
622
|
-
**kwargs
|
622
|
+
**kwargs: Arbitrary keyword arguments for customizing the validation process.
|
623
623
|
|
624
624
|
Returns:
|
625
625
|
(ultralytics.utils.metrics.DetMetrics): Validation metrics obtained from the validation process.
|
@@ -642,7 +642,7 @@ class Model(nn.Module):
|
|
642
642
|
|
643
643
|
def benchmark(
|
644
644
|
self,
|
645
|
-
**kwargs,
|
645
|
+
**kwargs: Any,
|
646
646
|
):
|
647
647
|
"""
|
648
648
|
Benchmarks the model across various export formats to evaluate performance.
|
@@ -653,7 +653,7 @@ class Model(nn.Module):
|
|
653
653
|
defaults, and any additional user-provided keyword arguments.
|
654
654
|
|
655
655
|
Args:
|
656
|
-
**kwargs
|
656
|
+
**kwargs: Arbitrary keyword arguments to customize the benchmarking process. These are combined with
|
657
657
|
default configurations, model-specific arguments, and method defaults. Common options include:
|
658
658
|
- data (str): Path to the dataset for benchmarking.
|
659
659
|
- imgsz (int | List[int]): Image size for benchmarking.
|
@@ -691,7 +691,7 @@ class Model(nn.Module):
|
|
691
691
|
|
692
692
|
def export(
|
693
693
|
self,
|
694
|
-
**kwargs,
|
694
|
+
**kwargs: Any,
|
695
695
|
) -> str:
|
696
696
|
"""
|
697
697
|
Exports the model to a different format suitable for deployment.
|
@@ -701,7 +701,7 @@ class Model(nn.Module):
|
|
701
701
|
defaults, and any additional arguments provided.
|
702
702
|
|
703
703
|
Args:
|
704
|
-
**kwargs
|
704
|
+
**kwargs: Arbitrary keyword arguments to customize the export process. These are combined with
|
705
705
|
the model's overrides and method defaults. Common arguments include:
|
706
706
|
format (str): Export format (e.g., 'onnx', 'engine', 'coreml').
|
707
707
|
half (bool): Export model in half-precision.
|
@@ -740,7 +740,7 @@ class Model(nn.Module):
|
|
740
740
|
def train(
|
741
741
|
self,
|
742
742
|
trainer=None,
|
743
|
-
**kwargs,
|
743
|
+
**kwargs: Any,
|
744
744
|
):
|
745
745
|
"""
|
746
746
|
Trains the model using the specified dataset and training configuration.
|
@@ -755,7 +755,7 @@ class Model(nn.Module):
|
|
755
755
|
|
756
756
|
Args:
|
757
757
|
trainer (BaseTrainer | None): Custom trainer instance for model training. If None, uses default.
|
758
|
-
**kwargs
|
758
|
+
**kwargs: Arbitrary keyword arguments for training configuration. Common options include:
|
759
759
|
data (str): Path to dataset configuration file.
|
760
760
|
epochs (int): Number of training epochs.
|
761
761
|
batch_size (int): Batch size for training.
|
@@ -816,8 +816,8 @@ class Model(nn.Module):
|
|
816
816
|
self,
|
817
817
|
use_ray=False,
|
818
818
|
iterations=10,
|
819
|
-
*args,
|
820
|
-
**kwargs,
|
819
|
+
*args: Any,
|
820
|
+
**kwargs: Any,
|
821
821
|
):
|
822
822
|
"""
|
823
823
|
Conducts hyperparameter tuning for the model, with an option to use Ray Tune.
|
@@ -830,8 +830,8 @@ class Model(nn.Module):
|
|
830
830
|
Args:
|
831
831
|
use_ray (bool): If True, uses Ray Tune for hyperparameter tuning. Defaults to False.
|
832
832
|
iterations (int): The number of tuning iterations to perform. Defaults to 10.
|
833
|
-
*args
|
834
|
-
**kwargs
|
833
|
+
*args: Variable length argument list for additional arguments.
|
834
|
+
**kwargs: Arbitrary keyword arguments. These are combined with the model's overrides and defaults.
|
835
835
|
|
836
836
|
Returns:
|
837
837
|
(Dict): A dictionary containing the results of the hyperparameter search.
|
@@ -1170,6 +1170,4 @@ class Model(nn.Module):
|
|
1170
1170
|
>>> print(model.stride)
|
1171
1171
|
>>> print(model.task)
|
1172
1172
|
"""
|
1173
|
-
if name == "model"
|
1174
|
-
return self._modules["model"]
|
1175
|
-
return getattr(self.model, name)
|
1173
|
+
return self._modules["model"] if name == "model" else getattr(self.model, name)
|
ultralytics/engine/validator.py
CHANGED
@@ -245,7 +245,7 @@ class BaseValidator:
|
|
245
245
|
|
246
246
|
cost_matrix = iou * (iou >= threshold)
|
247
247
|
if cost_matrix.any():
|
248
|
-
labels_idx, detections_idx = scipy.optimize.linear_sum_assignment(cost_matrix
|
248
|
+
labels_idx, detections_idx = scipy.optimize.linear_sum_assignment(cost_matrix)
|
249
249
|
valid = cost_matrix[labels_idx, detections_idx] > 0
|
250
250
|
if valid.any():
|
251
251
|
correct[detections_idx[valid], i] = True
|
@@ -955,7 +955,8 @@ class TinyViT(nn.Module):
|
|
955
955
|
|
956
956
|
self.apply(_check_lr_scale)
|
957
957
|
|
958
|
-
|
958
|
+
@staticmethod
|
959
|
+
def _init_weights(m):
|
959
960
|
"""Initializes weights for linear and normalization layers in the TinyViT model."""
|
960
961
|
if isinstance(m, nn.Linear):
|
961
962
|
# NOTE: This initialization is needed only for training.
|