dgenerate-ultralytics-headless 8.3.194__py3-none-any.whl → 8.3.196__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.
- {dgenerate_ultralytics_headless-8.3.194.dist-info → dgenerate_ultralytics_headless-8.3.196.dist-info}/METADATA +1 -2
- {dgenerate_ultralytics_headless-8.3.194.dist-info → dgenerate_ultralytics_headless-8.3.196.dist-info}/RECORD +107 -106
- tests/test_python.py +1 -1
- ultralytics/__init__.py +1 -1
- ultralytics/cfg/__init__.py +9 -8
- ultralytics/cfg/default.yaml +1 -0
- ultralytics/data/annotator.py +1 -1
- ultralytics/data/augment.py +76 -76
- ultralytics/data/base.py +12 -12
- ultralytics/data/build.py +5 -1
- ultralytics/data/converter.py +4 -4
- ultralytics/data/dataset.py +7 -7
- ultralytics/data/loaders.py +15 -15
- ultralytics/data/split_dota.py +10 -10
- ultralytics/data/utils.py +12 -12
- ultralytics/engine/exporter.py +19 -31
- ultralytics/engine/model.py +13 -13
- ultralytics/engine/predictor.py +16 -14
- ultralytics/engine/results.py +21 -21
- ultralytics/engine/trainer.py +15 -4
- ultralytics/engine/validator.py +6 -2
- ultralytics/hub/google/__init__.py +2 -2
- ultralytics/hub/session.py +7 -7
- ultralytics/models/fastsam/model.py +5 -5
- ultralytics/models/fastsam/predict.py +11 -11
- ultralytics/models/nas/model.py +1 -1
- ultralytics/models/rtdetr/predict.py +2 -2
- ultralytics/models/rtdetr/val.py +4 -4
- ultralytics/models/sam/amg.py +6 -6
- ultralytics/models/sam/build.py +9 -9
- ultralytics/models/sam/model.py +7 -7
- ultralytics/models/sam/modules/blocks.py +6 -6
- ultralytics/models/sam/modules/decoders.py +1 -1
- ultralytics/models/sam/modules/encoders.py +27 -27
- ultralytics/models/sam/modules/sam.py +4 -4
- ultralytics/models/sam/modules/tiny_encoder.py +18 -18
- ultralytics/models/sam/modules/utils.py +8 -8
- ultralytics/models/sam/predict.py +63 -63
- ultralytics/models/utils/loss.py +22 -22
- ultralytics/models/utils/ops.py +8 -8
- ultralytics/models/yolo/classify/predict.py +2 -2
- ultralytics/models/yolo/classify/train.py +9 -19
- ultralytics/models/yolo/classify/val.py +4 -4
- ultralytics/models/yolo/detect/predict.py +3 -3
- ultralytics/models/yolo/detect/train.py +38 -12
- ultralytics/models/yolo/detect/val.py +38 -37
- ultralytics/models/yolo/model.py +6 -6
- ultralytics/models/yolo/obb/train.py +1 -10
- ultralytics/models/yolo/obb/val.py +13 -13
- ultralytics/models/yolo/pose/train.py +1 -9
- ultralytics/models/yolo/pose/val.py +12 -12
- ultralytics/models/yolo/segment/predict.py +4 -4
- ultralytics/models/yolo/segment/train.py +2 -10
- ultralytics/models/yolo/segment/val.py +15 -15
- ultralytics/models/yolo/world/train.py +13 -13
- ultralytics/models/yolo/world/train_world.py +3 -3
- ultralytics/models/yolo/yoloe/predict.py +4 -4
- ultralytics/models/yolo/yoloe/train.py +7 -16
- ultralytics/models/yolo/yoloe/val.py +0 -7
- ultralytics/nn/autobackend.py +2 -2
- ultralytics/nn/modules/block.py +6 -6
- ultralytics/nn/modules/conv.py +2 -2
- ultralytics/nn/modules/head.py +6 -5
- ultralytics/nn/tasks.py +17 -15
- ultralytics/nn/text_model.py +3 -3
- ultralytics/solutions/ai_gym.py +2 -2
- ultralytics/solutions/analytics.py +3 -3
- ultralytics/solutions/config.py +5 -5
- ultralytics/solutions/distance_calculation.py +2 -2
- ultralytics/solutions/heatmap.py +1 -1
- ultralytics/solutions/instance_segmentation.py +4 -4
- ultralytics/solutions/object_counter.py +4 -4
- ultralytics/solutions/parking_management.py +7 -7
- ultralytics/solutions/queue_management.py +3 -3
- ultralytics/solutions/region_counter.py +4 -4
- ultralytics/solutions/similarity_search.py +2 -2
- ultralytics/solutions/solutions.py +48 -48
- ultralytics/solutions/streamlit_inference.py +1 -1
- ultralytics/solutions/trackzone.py +4 -4
- ultralytics/solutions/vision_eye.py +1 -1
- ultralytics/trackers/byte_tracker.py +11 -11
- ultralytics/trackers/utils/gmc.py +3 -3
- ultralytics/trackers/utils/matching.py +5 -5
- ultralytics/utils/__init__.py +30 -19
- ultralytics/utils/autodevice.py +2 -2
- ultralytics/utils/benchmarks.py +10 -10
- ultralytics/utils/callbacks/clearml.py +1 -1
- ultralytics/utils/callbacks/comet.py +5 -5
- ultralytics/utils/callbacks/tensorboard.py +2 -2
- ultralytics/utils/checks.py +7 -5
- ultralytics/utils/cpu.py +90 -0
- ultralytics/utils/dist.py +1 -1
- ultralytics/utils/downloads.py +2 -2
- ultralytics/utils/export.py +5 -5
- ultralytics/utils/instance.py +2 -2
- ultralytics/utils/loss.py +14 -8
- ultralytics/utils/metrics.py +35 -35
- ultralytics/utils/nms.py +4 -4
- ultralytics/utils/ops.py +1 -1
- ultralytics/utils/patches.py +2 -2
- ultralytics/utils/plotting.py +10 -9
- ultralytics/utils/torch_utils.py +113 -15
- ultralytics/utils/triton.py +5 -5
- {dgenerate_ultralytics_headless-8.3.194.dist-info → dgenerate_ultralytics_headless-8.3.196.dist-info}/WHEEL +0 -0
- {dgenerate_ultralytics_headless-8.3.194.dist-info → dgenerate_ultralytics_headless-8.3.196.dist-info}/entry_points.txt +0 -0
- {dgenerate_ultralytics_headless-8.3.194.dist-info → dgenerate_ultralytics_headless-8.3.196.dist-info}/licenses/LICENSE +0 -0
- {dgenerate_ultralytics_headless-8.3.194.dist-info → dgenerate_ultralytics_headless-8.3.196.dist-info}/top_level.txt +0 -0
ultralytics/utils/metrics.py
CHANGED
@@ -318,7 +318,7 @@ class ConfusionMatrix(DataExportMixin):
|
|
318
318
|
task (str): The type of task, either 'detect' or 'classify'.
|
319
319
|
matrix (np.ndarray): The confusion matrix, with dimensions depending on the task.
|
320
320
|
nc (int): The number of category.
|
321
|
-
names (
|
321
|
+
names (list[str]): The names of the classes, used as labels on the plot.
|
322
322
|
matches (dict): Contains the indices of ground truths and predictions categorized into TP, FP and FN.
|
323
323
|
"""
|
324
324
|
|
@@ -327,7 +327,7 @@ class ConfusionMatrix(DataExportMixin):
|
|
327
327
|
Initialize a ConfusionMatrix instance.
|
328
328
|
|
329
329
|
Args:
|
330
|
-
names (
|
330
|
+
names (dict[int, str], optional): Names of classes, used as labels on the plot.
|
331
331
|
task (str, optional): Type of task, either 'detect' or 'classify'.
|
332
332
|
save_matches (bool, optional): Save the indices of GTs, TPs, FPs, FNs for visualization.
|
333
333
|
"""
|
@@ -346,7 +346,7 @@ class ConfusionMatrix(DataExportMixin):
|
|
346
346
|
|
347
347
|
Args:
|
348
348
|
mtype (str): Match type identifier ('TP', 'FP', 'FN' or 'GT').
|
349
|
-
batch (
|
349
|
+
batch (dict[str, Any]): Batch data containing detection results with keys
|
350
350
|
like 'bboxes', 'cls', 'conf', 'keypoints', 'masks'.
|
351
351
|
idx (int): Index of the specific detection to append from the batch.
|
352
352
|
|
@@ -368,8 +368,8 @@ class ConfusionMatrix(DataExportMixin):
|
|
368
368
|
Update confusion matrix for classification task.
|
369
369
|
|
370
370
|
Args:
|
371
|
-
preds (
|
372
|
-
targets (
|
371
|
+
preds (list[N, min(nc,5)]): Predicted class labels.
|
372
|
+
targets (list[N, 1]): Ground truth class labels.
|
373
373
|
"""
|
374
374
|
preds, targets = torch.cat(preds)[:, 0], torch.cat(targets)
|
375
375
|
for p, t in zip(preds.cpu().numpy(), targets.cpu().numpy()):
|
@@ -386,10 +386,10 @@ class ConfusionMatrix(DataExportMixin):
|
|
386
386
|
Update confusion matrix for object detection task.
|
387
387
|
|
388
388
|
Args:
|
389
|
-
detections (
|
389
|
+
detections (dict[str, torch.Tensor]): Dictionary containing detected bounding boxes and their associated information.
|
390
390
|
Should contain 'cls', 'conf', and 'bboxes' keys, where 'bboxes' can be
|
391
391
|
Array[N, 4] for regular boxes or Array[N, 5] for OBB with angle.
|
392
|
-
batch (
|
392
|
+
batch (dict[str, Any]): Batch dictionary containing ground truth data with 'bboxes' (Array[M, 4]| Array[M, 5]) and
|
393
393
|
'cls' (Array[M]) keys, where M is the number of ground truth objects.
|
394
394
|
conf (float, optional): Confidence threshold for detections.
|
395
395
|
iou_thres (float, optional): IoU threshold for matching detections to ground truth.
|
@@ -599,7 +599,7 @@ class ConfusionMatrix(DataExportMixin):
|
|
599
599
|
decimals (int): Number of decimal places to round the output values to.
|
600
600
|
|
601
601
|
Returns:
|
602
|
-
(
|
602
|
+
(list[dict[str, float]]): A list of dictionaries, each representing one predicted class with corresponding values for all actual classes.
|
603
603
|
|
604
604
|
Examples:
|
605
605
|
>>> results = model.val(data="coco8.yaml", plots=True)
|
@@ -651,7 +651,7 @@ def plot_pr_curve(
|
|
651
651
|
py (np.ndarray): Y values for the PR curve.
|
652
652
|
ap (np.ndarray): Average precision values.
|
653
653
|
save_dir (Path, optional): Path to save the plot.
|
654
|
-
names (
|
654
|
+
names (dict[int, str], optional): Dictionary mapping class indices to class names.
|
655
655
|
on_plot (callable, optional): Function to call after plot is saved.
|
656
656
|
"""
|
657
657
|
import matplotlib.pyplot as plt # scope for faster 'import ultralytics'
|
@@ -695,7 +695,7 @@ def plot_mc_curve(
|
|
695
695
|
px (np.ndarray): X values for the metric-confidence curve.
|
696
696
|
py (np.ndarray): Y values for the metric-confidence curve.
|
697
697
|
save_dir (Path, optional): Path to save the plot.
|
698
|
-
names (
|
698
|
+
names (dict[int, str], optional): Dictionary mapping class indices to class names.
|
699
699
|
xlabel (str, optional): X-axis label.
|
700
700
|
ylabel (str, optional): Y-axis label.
|
701
701
|
on_plot (callable, optional): Function to call after plot is saved.
|
@@ -780,7 +780,7 @@ def ap_per_class(
|
|
780
780
|
plot (bool, optional): Whether to plot PR curves or not.
|
781
781
|
on_plot (callable, optional): A callback to pass plots path and data when they are rendered.
|
782
782
|
save_dir (Path, optional): Directory to save the PR curves.
|
783
|
-
names (
|
783
|
+
names (dict[int, str], optional): Dictionary of class names to plot PR curves.
|
784
784
|
eps (float, optional): A small value to avoid division by zero.
|
785
785
|
prefix (str, optional): A prefix string for saving the plot files.
|
786
786
|
|
@@ -1034,11 +1034,11 @@ class DetMetrics(SimpleClass, DataExportMixin):
|
|
1034
1034
|
Utility class for computing detection metrics such as precision, recall, and mean average precision (mAP).
|
1035
1035
|
|
1036
1036
|
Attributes:
|
1037
|
-
names (
|
1037
|
+
names (dict[int, str]): A dictionary of class names.
|
1038
1038
|
box (Metric): An instance of the Metric class for storing detection results.
|
1039
|
-
speed (
|
1039
|
+
speed (dict[str, float]): A dictionary for storing execution times of different parts of the detection process.
|
1040
1040
|
task (str): The task type, set to 'detect'.
|
1041
|
-
stats (
|
1041
|
+
stats (dict[str, list]): A dictionary containing lists for true positives, confidence scores, predicted classes, target classes, and target images.
|
1042
1042
|
nt_per_class: Number of targets per class.
|
1043
1043
|
nt_per_image: Number of targets per image.
|
1044
1044
|
|
@@ -1063,7 +1063,7 @@ class DetMetrics(SimpleClass, DataExportMixin):
|
|
1063
1063
|
Initialize a DetMetrics instance with a save directory, plot flag, and class names.
|
1064
1064
|
|
1065
1065
|
Args:
|
1066
|
-
names (
|
1066
|
+
names (dict[int, str], optional): Dictionary of class names.
|
1067
1067
|
"""
|
1068
1068
|
self.names = names
|
1069
1069
|
self.box = Metric()
|
@@ -1078,7 +1078,7 @@ class DetMetrics(SimpleClass, DataExportMixin):
|
|
1078
1078
|
Update statistics by appending new values to existing stat collections.
|
1079
1079
|
|
1080
1080
|
Args:
|
1081
|
-
stat (
|
1081
|
+
stat (dict[str, any]): Dictionary containing new statistical values to append.
|
1082
1082
|
Keys should match existing keys in self.stats.
|
1083
1083
|
"""
|
1084
1084
|
for k in self.stats.keys():
|
@@ -1094,7 +1094,7 @@ class DetMetrics(SimpleClass, DataExportMixin):
|
|
1094
1094
|
on_plot (callable, optional): Function to call after plots are generated. Defaults to None.
|
1095
1095
|
|
1096
1096
|
Returns:
|
1097
|
-
(
|
1097
|
+
(dict[str, np.ndarray]): Dictionary containing concatenated statistics arrays.
|
1098
1098
|
"""
|
1099
1099
|
stats = {k: np.concatenate(v, 0) for k, v in self.stats.items()} # to numpy
|
1100
1100
|
if not stats:
|
@@ -1176,7 +1176,7 @@ class DetMetrics(SimpleClass, DataExportMixin):
|
|
1176
1176
|
decimals (int): Number of decimal places to round the metrics values to.
|
1177
1177
|
|
1178
1178
|
Returns:
|
1179
|
-
(
|
1179
|
+
(list[dict[str, Any]]): A list of dictionaries, each representing one class with corresponding metric values.
|
1180
1180
|
|
1181
1181
|
Examples:
|
1182
1182
|
>>> results = model.val(data="coco8.yaml")
|
@@ -1206,12 +1206,12 @@ class SegmentMetrics(DetMetrics):
|
|
1206
1206
|
Calculate and aggregate detection and segmentation metrics over a given set of classes.
|
1207
1207
|
|
1208
1208
|
Attributes:
|
1209
|
-
names (
|
1209
|
+
names (dict[int, str]): Dictionary of class names.
|
1210
1210
|
box (Metric): An instance of the Metric class for storing detection results.
|
1211
1211
|
seg (Metric): An instance of the Metric class to calculate mask segmentation metrics.
|
1212
|
-
speed (
|
1212
|
+
speed (dict[str, float]): A dictionary for storing execution times of different parts of the detection process.
|
1213
1213
|
task (str): The task type, set to 'segment'.
|
1214
|
-
stats (
|
1214
|
+
stats (dict[str, list]): A dictionary containing lists for true positives, confidence scores, predicted classes, target classes, and target images.
|
1215
1215
|
nt_per_class: Number of targets per class.
|
1216
1216
|
nt_per_image: Number of targets per image.
|
1217
1217
|
|
@@ -1232,7 +1232,7 @@ class SegmentMetrics(DetMetrics):
|
|
1232
1232
|
Initialize a SegmentMetrics instance with a save directory, plot flag, and class names.
|
1233
1233
|
|
1234
1234
|
Args:
|
1235
|
-
names (
|
1235
|
+
names (dict[int, str], optional): Dictionary of class names.
|
1236
1236
|
"""
|
1237
1237
|
DetMetrics.__init__(self, names)
|
1238
1238
|
self.seg = Metric()
|
@@ -1249,7 +1249,7 @@ class SegmentMetrics(DetMetrics):
|
|
1249
1249
|
on_plot (callable, optional): Function to call after plots are generated. Defaults to None.
|
1250
1250
|
|
1251
1251
|
Returns:
|
1252
|
-
(
|
1252
|
+
(dict[str, np.ndarray]): Dictionary containing concatenated statistics arrays.
|
1253
1253
|
"""
|
1254
1254
|
stats = DetMetrics.process(self, save_dir, plot, on_plot=on_plot) # process box stats
|
1255
1255
|
results_mask = ap_per_class(
|
@@ -1320,7 +1320,7 @@ class SegmentMetrics(DetMetrics):
|
|
1320
1320
|
decimals (int): Number of decimal places to round the metrics values to.
|
1321
1321
|
|
1322
1322
|
Returns:
|
1323
|
-
(
|
1323
|
+
(list[dict[str, Any]]): A list of dictionaries, each representing one class with corresponding metric values.
|
1324
1324
|
|
1325
1325
|
Examples:
|
1326
1326
|
>>> results = model.val(data="coco8-seg.yaml")
|
@@ -1343,12 +1343,12 @@ class PoseMetrics(DetMetrics):
|
|
1343
1343
|
Calculate and aggregate detection and pose metrics over a given set of classes.
|
1344
1344
|
|
1345
1345
|
Attributes:
|
1346
|
-
names (
|
1346
|
+
names (dict[int, str]): Dictionary of class names.
|
1347
1347
|
pose (Metric): An instance of the Metric class to calculate pose metrics.
|
1348
1348
|
box (Metric): An instance of the Metric class for storing detection results.
|
1349
|
-
speed (
|
1349
|
+
speed (dict[str, float]): A dictionary for storing execution times of different parts of the detection process.
|
1350
1350
|
task (str): The task type, set to 'pose'.
|
1351
|
-
stats (
|
1351
|
+
stats (dict[str, list]): A dictionary containing lists for true positives, confidence scores, predicted classes, target classes, and target images.
|
1352
1352
|
nt_per_class: Number of targets per class.
|
1353
1353
|
nt_per_image: Number of targets per image.
|
1354
1354
|
|
@@ -1369,7 +1369,7 @@ class PoseMetrics(DetMetrics):
|
|
1369
1369
|
Initialize the PoseMetrics class with directory path, class names, and plotting options.
|
1370
1370
|
|
1371
1371
|
Args:
|
1372
|
-
names (
|
1372
|
+
names (dict[int, str], optional): Dictionary of class names.
|
1373
1373
|
"""
|
1374
1374
|
super().__init__(names)
|
1375
1375
|
self.pose = Metric()
|
@@ -1386,7 +1386,7 @@ class PoseMetrics(DetMetrics):
|
|
1386
1386
|
on_plot (callable, optional): Function to call after plots are generated.
|
1387
1387
|
|
1388
1388
|
Returns:
|
1389
|
-
(
|
1389
|
+
(dict[str, np.ndarray]): Dictionary containing concatenated statistics arrays.
|
1390
1390
|
"""
|
1391
1391
|
stats = DetMetrics.process(self, save_dir, plot, on_plot=on_plot) # process box stats
|
1392
1392
|
results_pose = ap_per_class(
|
@@ -1461,7 +1461,7 @@ class PoseMetrics(DetMetrics):
|
|
1461
1461
|
decimals (int): Number of decimal places to round the metrics values to.
|
1462
1462
|
|
1463
1463
|
Returns:
|
1464
|
-
(
|
1464
|
+
(list[dict[str, Any]]): A list of dictionaries, each representing one class with corresponding metric values.
|
1465
1465
|
|
1466
1466
|
Examples:
|
1467
1467
|
>>> results = model.val(data="coco8-pose.yaml")
|
@@ -1553,7 +1553,7 @@ class ClassifyMetrics(SimpleClass, DataExportMixin):
|
|
1553
1553
|
decimals (int): Number of decimal places to round the metrics values to.
|
1554
1554
|
|
1555
1555
|
Returns:
|
1556
|
-
(
|
1556
|
+
(list[dict[str, float]]): A list with one dictionary containing Top-1 and Top-5 classification accuracy.
|
1557
1557
|
|
1558
1558
|
Examples:
|
1559
1559
|
>>> results = model.val(data="imagenet10")
|
@@ -1568,11 +1568,11 @@ class OBBMetrics(DetMetrics):
|
|
1568
1568
|
Metrics for evaluating oriented bounding box (OBB) detection.
|
1569
1569
|
|
1570
1570
|
Attributes:
|
1571
|
-
names (
|
1571
|
+
names (dict[int, str]): Dictionary of class names.
|
1572
1572
|
box (Metric): An instance of the Metric class for storing detection results.
|
1573
|
-
speed (
|
1573
|
+
speed (dict[str, float]): A dictionary for storing execution times of different parts of the detection process.
|
1574
1574
|
task (str): The task type, set to 'obb'.
|
1575
|
-
stats (
|
1575
|
+
stats (dict[str, list]): A dictionary containing lists for true positives, confidence scores, predicted classes, target classes, and target images.
|
1576
1576
|
nt_per_class: Number of targets per class.
|
1577
1577
|
nt_per_image: Number of targets per image.
|
1578
1578
|
|
@@ -1585,7 +1585,7 @@ class OBBMetrics(DetMetrics):
|
|
1585
1585
|
Initialize an OBBMetrics instance with directory, plotting, and class names.
|
1586
1586
|
|
1587
1587
|
Args:
|
1588
|
-
names (
|
1588
|
+
names (dict[int, str], optional): Dictionary of class names.
|
1589
1589
|
"""
|
1590
1590
|
DetMetrics.__init__(self, names)
|
1591
1591
|
# TODO: probably remove task as well
|
ultralytics/utils/nms.py
CHANGED
@@ -38,10 +38,10 @@ def non_max_suppression(
|
|
38
38
|
containing boxes, classes, and optional masks.
|
39
39
|
conf_thres (float): Confidence threshold for filtering detections. Valid values are between 0.0 and 1.0.
|
40
40
|
iou_thres (float): IoU threshold for NMS filtering. Valid values are between 0.0 and 1.0.
|
41
|
-
classes (
|
41
|
+
classes (list[int], optional): List of class indices to consider. If None, all classes are considered.
|
42
42
|
agnostic (bool): Whether to perform class-agnostic NMS.
|
43
43
|
multi_label (bool): Whether each box can have multiple labels.
|
44
|
-
labels (
|
44
|
+
labels (list[list[Union[int, float, torch.Tensor]]]): A priori labels for each image.
|
45
45
|
max_det (int): Maximum number of detections to keep per image.
|
46
46
|
nc (int): Number of classes. Indices after this are considered masks.
|
47
47
|
max_time_img (float): Maximum time in seconds for processing one image.
|
@@ -52,9 +52,9 @@ def non_max_suppression(
|
|
52
52
|
return_idxs (bool): Whether to return the indices of kept detections.
|
53
53
|
|
54
54
|
Returns:
|
55
|
-
output (
|
55
|
+
output (list[torch.Tensor]): List of detections per image with shape (num_boxes, 6 + num_masks)
|
56
56
|
containing (x1, y1, x2, y2, confidence, class, mask1, mask2, ...).
|
57
|
-
keepi (
|
57
|
+
keepi (list[torch.Tensor]): Indices of kept detections if return_idxs=True.
|
58
58
|
"""
|
59
59
|
# Checks
|
60
60
|
assert 0 <= conf_thres <= 1, f"Invalid Confidence threshold {conf_thres}, valid values are between 0.0 and 1.0"
|
ultralytics/utils/ops.py
CHANGED
@@ -135,7 +135,7 @@ def scale_boxes(img1_shape, boxes, img0_shape, ratio_pad=None, padding: bool = T
|
|
135
135
|
boxes[..., 2] -= pad_x # x padding
|
136
136
|
boxes[..., 3] -= pad_y # y padding
|
137
137
|
boxes[..., :4] /= gain
|
138
|
-
return clip_boxes(boxes, img0_shape)
|
138
|
+
return boxes if xywh else clip_boxes(boxes, img0_shape)
|
139
139
|
|
140
140
|
|
141
141
|
def make_divisible(x: int, divisor):
|
ultralytics/utils/patches.py
CHANGED
@@ -51,7 +51,7 @@ def imwrite(filename: str, img: np.ndarray, params: list[int] | None = None) ->
|
|
51
51
|
Args:
|
52
52
|
filename (str): Path to the file to write.
|
53
53
|
img (np.ndarray): Image to write.
|
54
|
-
params (
|
54
|
+
params (list[int], optional): Additional parameters for image encoding.
|
55
55
|
|
56
56
|
Returns:
|
57
57
|
(bool): True if the file was written successfully, False otherwise.
|
@@ -172,7 +172,7 @@ def override_configs(args, overrides: dict[str, Any] | None = None):
|
|
172
172
|
|
173
173
|
Args:
|
174
174
|
args (IterableSimpleNamespace): Original configuration arguments.
|
175
|
-
overrides (
|
175
|
+
overrides (dict[str, Any]): Dictionary of overrides to apply.
|
176
176
|
|
177
177
|
Yields:
|
178
178
|
(IterableSimpleNamespace): Configuration arguments with overrides applied.
|
ultralytics/utils/plotting.py
CHANGED
@@ -26,7 +26,7 @@ class Colors:
|
|
26
26
|
RGB values and accessing predefined color schemes for object detection and pose estimation.
|
27
27
|
|
28
28
|
Attributes:
|
29
|
-
palette (
|
29
|
+
palette (list[tuple]): List of RGB color tuples for general use.
|
30
30
|
n (int): The number of colors in the palette.
|
31
31
|
pose_palette (np.ndarray): A specific color palette array for pose estimation with dtype np.uint8.
|
32
32
|
|
@@ -176,9 +176,9 @@ class Annotator:
|
|
176
176
|
pil (bool): Whether to use PIL or cv2 for drawing annotations.
|
177
177
|
font (ImageFont.truetype | ImageFont.load_default): Font used for text annotations.
|
178
178
|
lw (float): Line width for drawing.
|
179
|
-
skeleton (
|
180
|
-
limb_color (
|
181
|
-
kpt_color (
|
179
|
+
skeleton (list[list[int]]): Skeleton structure for keypoints.
|
180
|
+
limb_color (list[int]): Color palette for limbs.
|
181
|
+
kpt_color (list[int]): Color palette for keypoints.
|
182
182
|
dark_colors (set): Set of colors considered dark for text contrast.
|
183
183
|
light_colors (set): Set of colors considered light for text contrast.
|
184
184
|
|
@@ -369,7 +369,7 @@ class Annotator:
|
|
369
369
|
|
370
370
|
Args:
|
371
371
|
masks (torch.Tensor | np.ndarray): Predicted masks with shape: [n, h, w]
|
372
|
-
colors (
|
372
|
+
colors (list[list[int]]): Colors for predicted masks, [[r, g, b] * n]
|
373
373
|
im_gpu (torch.Tensor | None): Image is in cuda, shape: [3, h, w], range: [0, 1]
|
374
374
|
alpha (float, optional): Mask transparency: 0.0 fully transparent, 1.0 opaque.
|
375
375
|
retina_masks (bool, optional): Whether to use high resolution masks or not.
|
@@ -484,7 +484,7 @@ class Annotator:
|
|
484
484
|
Add text to an image using PIL or cv2.
|
485
485
|
|
486
486
|
Args:
|
487
|
-
xy (
|
487
|
+
xy (list[int]): Top-left coordinates for text placement.
|
488
488
|
text (str): Text to be drawn.
|
489
489
|
txt_color (tuple, optional): Text color (R, G, B).
|
490
490
|
anchor (str, optional): Text anchor position ('top' or 'bottom').
|
@@ -695,11 +695,11 @@ def plot_images(
|
|
695
695
|
Plot image grid with labels, bounding boxes, masks, and keypoints.
|
696
696
|
|
697
697
|
Args:
|
698
|
-
labels (
|
698
|
+
labels (dict[str, Any]): Dictionary containing detection data with keys like 'cls', 'bboxes', 'conf', 'masks', 'keypoints', 'batch_idx', 'img'.
|
699
699
|
images (torch.Tensor | np.ndarray]): Batch of images to plot. Shape: (batch_size, channels, height, width).
|
700
|
-
paths (Optional[
|
700
|
+
paths (Optional[list[str]]): List of file paths for each image in the batch.
|
701
701
|
fname (str): Output filename for the plotted image grid.
|
702
|
-
names (Optional[
|
702
|
+
names (Optional[dict[int, str]]): Dictionary mapping class indices to class names.
|
703
703
|
on_plot (Optional[Callable]): Optional callback function to be called after saving the plot.
|
704
704
|
max_size (int): Maximum size of the output image grid.
|
705
705
|
max_subplots (int): Maximum number of subplots in the image grid.
|
@@ -1004,6 +1004,7 @@ def plot_tune_results(csv_file: str = "tune_results.csv"):
|
|
1004
1004
|
_save_one_file(csv_file.with_name("tune_fitness.png"))
|
1005
1005
|
|
1006
1006
|
|
1007
|
+
@plt_settings()
|
1007
1008
|
def feature_visualization(x, module_type: str, stage: int, n: int = 32, save_dir: Path = Path("runs/detect/exp")):
|
1008
1009
|
"""
|
1009
1010
|
Visualize feature maps of a given model module during inference.
|
ultralytics/utils/torch_utils.py
CHANGED
@@ -33,6 +33,7 @@ from ultralytics.utils import (
|
|
33
33
|
colorstr,
|
34
34
|
)
|
35
35
|
from ultralytics.utils.checks import check_version
|
36
|
+
from ultralytics.utils.cpu import CPUInfo
|
36
37
|
from ultralytics.utils.patches import torch_load
|
37
38
|
|
38
39
|
# Version checks (all default to version>=min_version)
|
@@ -113,12 +114,7 @@ def get_cpu_info():
|
|
113
114
|
|
114
115
|
if "cpu_info" not in PERSISTENT_CACHE:
|
115
116
|
try:
|
116
|
-
|
117
|
-
|
118
|
-
k = "brand_raw", "hardware_raw", "arch_string_raw" # keys sorted by preference
|
119
|
-
info = cpuinfo.get_cpu_info() # info dict
|
120
|
-
string = info.get(k[0] if k[0] in info else k[1] if k[1] in info else k[2], "unknown")
|
121
|
-
PERSISTENT_CACHE["cpu_info"] = string.replace("(R)", "").replace("CPU ", "").replace("@ ", "")
|
117
|
+
PERSISTENT_CACHE["cpu_info"] = CPUInfo.name()
|
122
118
|
except Exception:
|
123
119
|
pass
|
124
120
|
return PERSISTENT_CACHE.get("cpu_info", "unknown")
|
@@ -433,7 +429,7 @@ def get_flops(model, imgsz=640):
|
|
433
429
|
return 0.0 # if not installed return 0.0 GFLOPs
|
434
430
|
|
435
431
|
try:
|
436
|
-
model =
|
432
|
+
model = unwrap_model(model)
|
437
433
|
p = next(model.parameters())
|
438
434
|
if not isinstance(imgsz, list):
|
439
435
|
imgsz = [imgsz, imgsz] # expand if int/float
|
@@ -464,7 +460,7 @@ def get_flops_with_torch_profiler(model, imgsz=640):
|
|
464
460
|
"""
|
465
461
|
if not TORCH_2_0: # torch profiler implemented in torch>=2.0
|
466
462
|
return 0.0
|
467
|
-
model =
|
463
|
+
model = unwrap_model(model)
|
468
464
|
p = next(model.parameters())
|
469
465
|
if not isinstance(imgsz, list):
|
470
466
|
imgsz = [imgsz, imgsz] # expand if int/float
|
@@ -581,17 +577,24 @@ def is_parallel(model):
|
|
581
577
|
return isinstance(model, (nn.parallel.DataParallel, nn.parallel.DistributedDataParallel))
|
582
578
|
|
583
579
|
|
584
|
-
def
|
580
|
+
def unwrap_model(m: nn.Module) -> nn.Module:
|
585
581
|
"""
|
586
|
-
|
582
|
+
Unwrap compiled and parallel models to get the base model.
|
587
583
|
|
588
584
|
Args:
|
589
|
-
|
585
|
+
m (nn.Module): A model that may be wrapped by torch.compile (._orig_mod) or parallel wrappers such as
|
586
|
+
DataParallel/DistributedDataParallel (.module).
|
590
587
|
|
591
588
|
Returns:
|
592
|
-
(nn.Module):
|
589
|
+
m (nn.Module): The unwrapped base model without compile or parallel wrappers.
|
593
590
|
"""
|
594
|
-
|
591
|
+
while True:
|
592
|
+
if hasattr(m, "_orig_mod") and isinstance(m._orig_mod, nn.Module):
|
593
|
+
m = m._orig_mod
|
594
|
+
elif hasattr(m, "module") and isinstance(m.module, nn.Module):
|
595
|
+
m = m.module
|
596
|
+
else:
|
597
|
+
return m
|
595
598
|
|
596
599
|
|
597
600
|
def one_cycle(y1=0.0, y2=1.0, steps=100):
|
@@ -673,7 +676,7 @@ class ModelEMA:
|
|
673
676
|
tau (int, optional): EMA decay time constant.
|
674
677
|
updates (int, optional): Initial number of updates.
|
675
678
|
"""
|
676
|
-
self.ema = deepcopy(
|
679
|
+
self.ema = deepcopy(unwrap_model(model)).eval() # FP32 EMA
|
677
680
|
self.updates = updates # number of EMA updates
|
678
681
|
self.decay = lambda x: decay * (1 - math.exp(-x / tau)) # decay exponential ramp (to help early epochs)
|
679
682
|
for p in self.ema.parameters():
|
@@ -691,7 +694,7 @@ class ModelEMA:
|
|
691
694
|
self.updates += 1
|
692
695
|
d = self.decay(self.updates)
|
693
696
|
|
694
|
-
msd =
|
697
|
+
msd = unwrap_model(model).state_dict() # model state_dict
|
695
698
|
for k, v in self.ema.state_dict().items():
|
696
699
|
if v.dtype.is_floating_point: # true for FP16 and FP32
|
697
700
|
v *= d
|
@@ -1001,3 +1004,98 @@ class FXModel(nn.Module):
|
|
1001
1004
|
x = m(x) # run
|
1002
1005
|
y.append(x) # save output
|
1003
1006
|
return x
|
1007
|
+
|
1008
|
+
|
1009
|
+
def disable_dynamo(func: Any) -> Any:
|
1010
|
+
"""
|
1011
|
+
Disable torch.compile/dynamo for a callable when available.
|
1012
|
+
|
1013
|
+
Args:
|
1014
|
+
func (Any): Callable object to wrap. Could be a function, method, or class.
|
1015
|
+
|
1016
|
+
Returns:
|
1017
|
+
func (Any): Same callable, wrapped by torch._dynamo.disable when available, otherwise unchanged.
|
1018
|
+
|
1019
|
+
Examples:
|
1020
|
+
>>> @disable_dynamo
|
1021
|
+
... def fn(x):
|
1022
|
+
... return x + 1
|
1023
|
+
>>> # Works even if torch._dynamo is not available
|
1024
|
+
>>> _ = fn(1)
|
1025
|
+
"""
|
1026
|
+
if hasattr(torch, "_dynamo"):
|
1027
|
+
return torch._dynamo.disable(func)
|
1028
|
+
return func
|
1029
|
+
|
1030
|
+
|
1031
|
+
def attempt_compile(
|
1032
|
+
model: torch.nn.Module,
|
1033
|
+
device: torch.device,
|
1034
|
+
imgsz: int = 640,
|
1035
|
+
use_autocast: bool = False,
|
1036
|
+
warmup: bool = False,
|
1037
|
+
prefix: str = colorstr("compile:"),
|
1038
|
+
) -> torch.nn.Module:
|
1039
|
+
"""
|
1040
|
+
Compile a model with torch.compile and optionally warm up the graph to reduce first-iteration latency.
|
1041
|
+
|
1042
|
+
This utility attempts to compile the provided model using the inductor backend with dynamic shapes enabled and an
|
1043
|
+
autotuning mode. If compilation is unavailable or fails, the original model is returned unchanged. An optional
|
1044
|
+
warmup performs a single forward pass on a dummy input to prime the compiled graph and measure compile/warmup time.
|
1045
|
+
|
1046
|
+
Args:
|
1047
|
+
model (torch.nn.Module): Model to compile.
|
1048
|
+
device (torch.device): Inference device used for warmup and autocast decisions.
|
1049
|
+
imgsz (int, optional): Square input size to create a dummy tensor with shape (1, 3, imgsz, imgsz) for warmup.
|
1050
|
+
use_autocast (bool, optional): Whether to run warmup under autocast on CUDA or MPS devices.
|
1051
|
+
warmup (bool, optional): Whether to execute a single dummy forward pass to warm up the compiled model.
|
1052
|
+
prefix (str, optional): Message prefix for logger output.
|
1053
|
+
|
1054
|
+
Returns:
|
1055
|
+
model (torch.nn.Module): Compiled model if compilation succeeds, otherwise the original unmodified model.
|
1056
|
+
|
1057
|
+
Notes:
|
1058
|
+
- If the current PyTorch build does not provide torch.compile, the function returns the input model immediately.
|
1059
|
+
- Warmup runs under torch.inference_mode and may use torch.autocast for CUDA/MPS to align compute precision.
|
1060
|
+
- CUDA devices are synchronized after warmup to account for asynchronous kernel execution.
|
1061
|
+
|
1062
|
+
Examples:
|
1063
|
+
>>> device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
1064
|
+
>>> # Try to compile and warm up a model with a 640x640 input
|
1065
|
+
>>> model = attempt_compile(model, device=device, imgsz=640, use_autocast=True, warmup=True)
|
1066
|
+
"""
|
1067
|
+
if not hasattr(torch, "compile"):
|
1068
|
+
return model
|
1069
|
+
|
1070
|
+
LOGGER.info(f"{prefix} starting torch.compile...")
|
1071
|
+
t0 = time.perf_counter()
|
1072
|
+
try:
|
1073
|
+
model = torch.compile(model, mode="max-autotune", backend="inductor")
|
1074
|
+
except Exception as e:
|
1075
|
+
LOGGER.warning(f"{prefix} torch.compile failed, continuing uncompiled: {e}")
|
1076
|
+
return model
|
1077
|
+
t_compile = time.perf_counter() - t0
|
1078
|
+
|
1079
|
+
t_warm = 0.0
|
1080
|
+
if warmup:
|
1081
|
+
# Use a single dummy tensor to build the graph shape state and reduce first-iteration latency
|
1082
|
+
dummy = torch.zeros(1, 3, imgsz, imgsz, device=device)
|
1083
|
+
if use_autocast and device.type == "cuda":
|
1084
|
+
dummy = dummy.half()
|
1085
|
+
t1 = time.perf_counter()
|
1086
|
+
with torch.inference_mode():
|
1087
|
+
if use_autocast and device.type in {"cuda", "mps"}:
|
1088
|
+
with torch.autocast(device.type):
|
1089
|
+
_ = model(dummy)
|
1090
|
+
else:
|
1091
|
+
_ = model(dummy)
|
1092
|
+
if device.type == "cuda":
|
1093
|
+
torch.cuda.synchronize(device)
|
1094
|
+
t_warm = time.perf_counter() - t1
|
1095
|
+
|
1096
|
+
total = t_compile + t_warm
|
1097
|
+
if warmup:
|
1098
|
+
LOGGER.info(f"{prefix} complete in {total:.1f}s (compile {t_compile:.1f}s + warmup {t_warm:.1f}s)")
|
1099
|
+
else:
|
1100
|
+
LOGGER.info(f"{prefix} compile complete in {t_compile:.1f}s (no warmup)")
|
1101
|
+
return model
|
ultralytics/utils/triton.py
CHANGED
@@ -20,10 +20,10 @@ class TritonRemoteModel:
|
|
20
20
|
triton_client: The Triton client (either HTTP or gRPC).
|
21
21
|
InferInput: The input class for the Triton client.
|
22
22
|
InferRequestedOutput: The output request class for the Triton client.
|
23
|
-
input_formats (
|
24
|
-
np_input_formats (
|
25
|
-
input_names (
|
26
|
-
output_names (
|
23
|
+
input_formats (list[str]): The data types of the model inputs.
|
24
|
+
np_input_formats (list[type]): The numpy data types of the model inputs.
|
25
|
+
input_names (list[str]): The names of the model inputs.
|
26
|
+
output_names (list[str]): The names of the model outputs.
|
27
27
|
metadata: The metadata associated with the model.
|
28
28
|
|
29
29
|
Methods:
|
@@ -96,7 +96,7 @@ class TritonRemoteModel:
|
|
96
96
|
for the corresponding model input.
|
97
97
|
|
98
98
|
Returns:
|
99
|
-
(
|
99
|
+
(list[np.ndarray]): Model outputs with the same dtype as the input. Each element in the list
|
100
100
|
corresponds to one of the model's output tensors.
|
101
101
|
|
102
102
|
Examples:
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|