ultralytics 8.3.88__py3-none-any.whl → 8.3.90__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/conftest.py +2 -2
- tests/test_cli.py +13 -11
- tests/test_cuda.py +10 -1
- tests/test_integrations.py +1 -5
- tests/test_python.py +16 -16
- tests/test_solutions.py +9 -9
- ultralytics/__init__.py +1 -1
- ultralytics/cfg/__init__.py +3 -1
- ultralytics/cfg/models/11/yolo11-cls.yaml +5 -5
- ultralytics/cfg/models/11/yolo11-obb.yaml +5 -5
- ultralytics/cfg/models/11/yolo11-pose.yaml +5 -5
- ultralytics/cfg/models/11/yolo11-seg.yaml +5 -5
- ultralytics/cfg/models/11/yolo11.yaml +5 -5
- ultralytics/cfg/models/v8/yolov8-ghost-p2.yaml +5 -5
- ultralytics/cfg/models/v8/yolov8-ghost-p6.yaml +5 -5
- ultralytics/cfg/models/v8/yolov8-ghost.yaml +5 -5
- ultralytics/cfg/models/v8/yolov8-obb.yaml +5 -5
- ultralytics/cfg/models/v8/yolov8-p6.yaml +5 -5
- ultralytics/cfg/models/v8/yolov8-rtdetr.yaml +5 -5
- ultralytics/cfg/models/v8/yolov8-world.yaml +5 -5
- ultralytics/cfg/models/v8/yolov8-worldv2.yaml +5 -5
- ultralytics/cfg/models/v8/yolov8.yaml +5 -5
- ultralytics/cfg/models/v9/yolov9c-seg.yaml +1 -1
- ultralytics/cfg/models/v9/yolov9c.yaml +1 -1
- ultralytics/cfg/models/v9/yolov9e-seg.yaml +1 -1
- ultralytics/cfg/models/v9/yolov9e.yaml +1 -1
- ultralytics/cfg/models/v9/yolov9m.yaml +1 -1
- ultralytics/cfg/models/v9/yolov9s.yaml +1 -1
- ultralytics/cfg/models/v9/yolov9t.yaml +1 -1
- ultralytics/data/annotator.py +9 -14
- ultralytics/data/base.py +125 -39
- ultralytics/data/build.py +63 -24
- ultralytics/data/converter.py +34 -33
- ultralytics/data/dataset.py +207 -53
- ultralytics/data/loaders.py +1 -0
- ultralytics/data/split_dota.py +39 -12
- ultralytics/data/utils.py +33 -47
- ultralytics/engine/exporter.py +19 -17
- ultralytics/engine/model.py +69 -90
- ultralytics/engine/predictor.py +106 -21
- ultralytics/engine/trainer.py +32 -23
- ultralytics/engine/tuner.py +31 -38
- ultralytics/engine/validator.py +75 -41
- ultralytics/hub/__init__.py +21 -26
- ultralytics/hub/auth.py +9 -12
- ultralytics/hub/session.py +76 -21
- ultralytics/hub/utils.py +19 -17
- ultralytics/models/fastsam/model.py +23 -17
- ultralytics/models/fastsam/predict.py +36 -16
- ultralytics/models/fastsam/utils.py +5 -5
- ultralytics/models/fastsam/val.py +6 -6
- ultralytics/models/nas/model.py +29 -24
- ultralytics/models/nas/predict.py +14 -11
- ultralytics/models/nas/val.py +11 -13
- ultralytics/models/rtdetr/model.py +20 -11
- ultralytics/models/rtdetr/predict.py +21 -21
- ultralytics/models/rtdetr/train.py +25 -24
- ultralytics/models/rtdetr/val.py +47 -14
- ultralytics/models/sam/__init__.py +1 -1
- ultralytics/models/sam/amg.py +50 -4
- ultralytics/models/sam/model.py +8 -14
- ultralytics/models/sam/modules/decoders.py +18 -21
- ultralytics/models/sam/modules/encoders.py +25 -46
- ultralytics/models/sam/modules/memory_attention.py +19 -15
- ultralytics/models/sam/modules/sam.py +18 -25
- ultralytics/models/sam/modules/tiny_encoder.py +19 -29
- ultralytics/models/sam/modules/transformer.py +35 -57
- ultralytics/models/sam/modules/utils.py +15 -15
- ultralytics/models/sam/predict.py +0 -3
- ultralytics/models/utils/loss.py +87 -36
- ultralytics/models/utils/ops.py +26 -31
- ultralytics/models/yolo/classify/predict.py +30 -12
- ultralytics/models/yolo/classify/train.py +83 -19
- ultralytics/models/yolo/classify/val.py +45 -23
- ultralytics/models/yolo/detect/predict.py +29 -19
- ultralytics/models/yolo/detect/train.py +90 -23
- ultralytics/models/yolo/detect/val.py +150 -29
- ultralytics/models/yolo/model.py +1 -2
- ultralytics/models/yolo/obb/predict.py +18 -13
- ultralytics/models/yolo/obb/train.py +12 -8
- ultralytics/models/yolo/obb/val.py +35 -22
- ultralytics/models/yolo/pose/predict.py +28 -15
- ultralytics/models/yolo/pose/train.py +21 -8
- ultralytics/models/yolo/pose/val.py +51 -31
- ultralytics/models/yolo/segment/predict.py +27 -16
- ultralytics/models/yolo/segment/train.py +11 -8
- ultralytics/models/yolo/segment/val.py +110 -29
- ultralytics/models/yolo/world/train.py +43 -16
- ultralytics/models/yolo/world/train_world.py +61 -36
- ultralytics/nn/autobackend.py +28 -14
- ultralytics/nn/modules/__init__.py +12 -12
- ultralytics/nn/modules/activation.py +12 -3
- ultralytics/nn/modules/block.py +587 -84
- ultralytics/nn/modules/conv.py +418 -54
- ultralytics/nn/modules/head.py +3 -4
- ultralytics/nn/modules/transformer.py +320 -34
- ultralytics/nn/modules/utils.py +17 -3
- ultralytics/nn/tasks.py +226 -79
- ultralytics/solutions/ai_gym.py +2 -2
- ultralytics/solutions/analytics.py +4 -4
- ultralytics/solutions/heatmap.py +4 -4
- ultralytics/solutions/instance_segmentation.py +10 -4
- ultralytics/solutions/object_blurrer.py +2 -2
- ultralytics/solutions/object_counter.py +2 -2
- ultralytics/solutions/object_cropper.py +2 -2
- ultralytics/solutions/parking_management.py +9 -9
- ultralytics/solutions/queue_management.py +1 -1
- ultralytics/solutions/region_counter.py +2 -2
- ultralytics/solutions/security_alarm.py +7 -7
- ultralytics/solutions/solutions.py +7 -4
- ultralytics/solutions/speed_estimation.py +2 -2
- ultralytics/solutions/streamlit_inference.py +6 -6
- ultralytics/solutions/trackzone.py +9 -2
- ultralytics/solutions/vision_eye.py +4 -4
- ultralytics/trackers/basetrack.py +1 -1
- ultralytics/trackers/bot_sort.py +23 -22
- ultralytics/trackers/byte_tracker.py +4 -4
- ultralytics/trackers/track.py +2 -1
- ultralytics/trackers/utils/gmc.py +26 -27
- ultralytics/trackers/utils/kalman_filter.py +31 -29
- ultralytics/trackers/utils/matching.py +7 -7
- ultralytics/utils/__init__.py +37 -35
- ultralytics/utils/autobatch.py +5 -5
- ultralytics/utils/benchmarks.py +111 -18
- ultralytics/utils/callbacks/base.py +3 -3
- ultralytics/utils/callbacks/clearml.py +11 -11
- ultralytics/utils/callbacks/comet.py +35 -22
- ultralytics/utils/callbacks/dvc.py +11 -10
- ultralytics/utils/callbacks/hub.py +8 -8
- ultralytics/utils/callbacks/mlflow.py +1 -1
- ultralytics/utils/callbacks/neptune.py +12 -10
- ultralytics/utils/callbacks/raytune.py +1 -1
- ultralytics/utils/callbacks/tensorboard.py +6 -6
- ultralytics/utils/callbacks/wb.py +16 -16
- ultralytics/utils/checks.py +139 -68
- ultralytics/utils/dist.py +15 -2
- ultralytics/utils/downloads.py +37 -56
- ultralytics/utils/files.py +12 -13
- ultralytics/utils/instance.py +117 -52
- ultralytics/utils/loss.py +28 -33
- ultralytics/utils/metrics.py +246 -181
- ultralytics/utils/ops.py +65 -61
- ultralytics/utils/patches.py +8 -6
- ultralytics/utils/plotting.py +72 -59
- ultralytics/utils/tal.py +88 -57
- ultralytics/utils/torch_utils.py +202 -64
- ultralytics/utils/triton.py +13 -3
- ultralytics/utils/tuner.py +13 -25
- {ultralytics-8.3.88.dist-info → ultralytics-8.3.90.dist-info}/METADATA +2 -2
- ultralytics-8.3.90.dist-info/RECORD +250 -0
- ultralytics-8.3.88.dist-info/RECORD +0 -250
- {ultralytics-8.3.88.dist-info → ultralytics-8.3.90.dist-info}/LICENSE +0 -0
- {ultralytics-8.3.88.dist-info → ultralytics-8.3.90.dist-info}/WHEEL +0 -0
- {ultralytics-8.3.88.dist-info → ultralytics-8.3.90.dist-info}/entry_points.txt +0 -0
- {ultralytics-8.3.88.dist-info → ultralytics-8.3.90.dist-info}/top_level.txt +0 -0
ultralytics/utils/loss.py
CHANGED
@@ -26,7 +26,7 @@ class VarifocalLoss(nn.Module):
|
|
26
26
|
|
27
27
|
@staticmethod
|
28
28
|
def forward(pred_score, gt_score, label, alpha=0.75, gamma=2.0):
|
29
|
-
"""
|
29
|
+
"""Compute varfocal loss between predictions and ground truth."""
|
30
30
|
weight = alpha * pred_score.sigmoid().pow(gamma) * (1 - label) + gt_score * label
|
31
31
|
with autocast(enabled=False):
|
32
32
|
loss = (
|
@@ -41,12 +41,12 @@ class FocalLoss(nn.Module):
|
|
41
41
|
"""Wraps focal loss around existing loss_fcn(), i.e. criteria = FocalLoss(nn.BCEWithLogitsLoss(), gamma=1.5)."""
|
42
42
|
|
43
43
|
def __init__(self):
|
44
|
-
"""
|
44
|
+
"""Initialize FocalLoss class with no parameters."""
|
45
45
|
super().__init__()
|
46
46
|
|
47
47
|
@staticmethod
|
48
48
|
def forward(pred, label, gamma=1.5, alpha=0.25):
|
49
|
-
"""
|
49
|
+
"""Calculate focal loss with modulating factors for class imbalance."""
|
50
50
|
loss = F.binary_cross_entropy_with_logits(pred, label, reduction="none")
|
51
51
|
# p_t = torch.exp(-loss)
|
52
52
|
# loss *= self.alpha * (1.000001 - p_t) ** self.gamma # non-zero power for gradient stability
|
@@ -63,20 +63,15 @@ class FocalLoss(nn.Module):
|
|
63
63
|
|
64
64
|
|
65
65
|
class DFLoss(nn.Module):
|
66
|
-
"""Criterion class for computing
|
66
|
+
"""Criterion class for computing Distribution Focal Loss (DFL)."""
|
67
67
|
|
68
68
|
def __init__(self, reg_max=16) -> None:
|
69
|
-
"""Initialize the DFL module."""
|
69
|
+
"""Initialize the DFL module with regularization maximum."""
|
70
70
|
super().__init__()
|
71
71
|
self.reg_max = reg_max
|
72
72
|
|
73
73
|
def __call__(self, pred_dist, target):
|
74
|
-
"""
|
75
|
-
Return sum of left and right DFL losses.
|
76
|
-
|
77
|
-
Distribution Focal Loss (DFL) proposed in Generalized Focal Loss
|
78
|
-
https://ieeexplore.ieee.org/document/9792391
|
79
|
-
"""
|
74
|
+
"""Return sum of left and right DFL losses from https://ieeexplore.ieee.org/document/9792391."""
|
80
75
|
target = target.clamp_(0, self.reg_max - 1 - 0.01)
|
81
76
|
tl = target.long() # target left
|
82
77
|
tr = tl + 1 # target right
|
@@ -89,7 +84,7 @@ class DFLoss(nn.Module):
|
|
89
84
|
|
90
85
|
|
91
86
|
class BboxLoss(nn.Module):
|
92
|
-
"""Criterion class for computing training losses
|
87
|
+
"""Criterion class for computing training losses for bounding boxes."""
|
93
88
|
|
94
89
|
def __init__(self, reg_max=16):
|
95
90
|
"""Initialize the BboxLoss module with regularization maximum and DFL settings."""
|
@@ -97,7 +92,7 @@ class BboxLoss(nn.Module):
|
|
97
92
|
self.dfl_loss = DFLoss(reg_max) if reg_max > 1 else None
|
98
93
|
|
99
94
|
def forward(self, pred_dist, pred_bboxes, anchor_points, target_bboxes, target_scores, target_scores_sum, fg_mask):
|
100
|
-
"""IoU
|
95
|
+
"""Compute IoU and DFL losses for bounding boxes."""
|
101
96
|
weight = target_scores.sum(-1)[fg_mask].unsqueeze(-1)
|
102
97
|
iou = bbox_iou(pred_bboxes[fg_mask], target_bboxes[fg_mask], xywh=False, CIoU=True)
|
103
98
|
loss_iou = ((1.0 - iou) * weight).sum() / target_scores_sum
|
@@ -114,14 +109,14 @@ class BboxLoss(nn.Module):
|
|
114
109
|
|
115
110
|
|
116
111
|
class RotatedBboxLoss(BboxLoss):
|
117
|
-
"""Criterion class for computing training losses
|
112
|
+
"""Criterion class for computing training losses for rotated bounding boxes."""
|
118
113
|
|
119
114
|
def __init__(self, reg_max):
|
120
115
|
"""Initialize the BboxLoss module with regularization maximum and DFL settings."""
|
121
116
|
super().__init__(reg_max)
|
122
117
|
|
123
118
|
def forward(self, pred_dist, pred_bboxes, anchor_points, target_bboxes, target_scores, target_scores_sum, fg_mask):
|
124
|
-
"""IoU
|
119
|
+
"""Compute IoU and DFL losses for rotated bounding boxes."""
|
125
120
|
weight = target_scores.sum(-1)[fg_mask].unsqueeze(-1)
|
126
121
|
iou = probiou(pred_bboxes[fg_mask], target_bboxes[fg_mask])
|
127
122
|
loss_iou = ((1.0 - iou) * weight).sum() / target_scores_sum
|
@@ -138,15 +133,15 @@ class RotatedBboxLoss(BboxLoss):
|
|
138
133
|
|
139
134
|
|
140
135
|
class KeypointLoss(nn.Module):
|
141
|
-
"""Criterion class for computing
|
136
|
+
"""Criterion class for computing keypoint losses."""
|
142
137
|
|
143
138
|
def __init__(self, sigmas) -> None:
|
144
|
-
"""Initialize the KeypointLoss class."""
|
139
|
+
"""Initialize the KeypointLoss class with keypoint sigmas."""
|
145
140
|
super().__init__()
|
146
141
|
self.sigmas = sigmas
|
147
142
|
|
148
143
|
def forward(self, pred_kpts, gt_kpts, kpt_mask, area):
|
149
|
-
"""
|
144
|
+
"""Calculate keypoint loss factor and Euclidean distance loss for keypoints."""
|
150
145
|
d = (pred_kpts[..., 0] - gt_kpts[..., 0]).pow(2) + (pred_kpts[..., 1] - gt_kpts[..., 1]).pow(2)
|
151
146
|
kpt_loss_factor = kpt_mask.shape[1] / (torch.sum(kpt_mask != 0, dim=1) + 1e-9)
|
152
147
|
# e = d / (2 * (area * self.sigmas) ** 2 + 1e-9) # from formula
|
@@ -155,10 +150,10 @@ class KeypointLoss(nn.Module):
|
|
155
150
|
|
156
151
|
|
157
152
|
class v8DetectionLoss:
|
158
|
-
"""Criterion class for computing training losses."""
|
153
|
+
"""Criterion class for computing training losses for YOLOv8 object detection."""
|
159
154
|
|
160
155
|
def __init__(self, model, tal_topk=10): # model must be de-paralleled
|
161
|
-
"""
|
156
|
+
"""Initialize v8DetectionLoss with model parameters and task-aligned assignment settings."""
|
162
157
|
device = next(model.parameters()).device # get model device
|
163
158
|
h = model.args # hyperparameters
|
164
159
|
|
@@ -178,7 +173,7 @@ class v8DetectionLoss:
|
|
178
173
|
self.proj = torch.arange(m.reg_max, dtype=torch.float, device=device)
|
179
174
|
|
180
175
|
def preprocess(self, targets, batch_size, scale_tensor):
|
181
|
-
"""
|
176
|
+
"""Preprocess targets by converting to tensor format and scaling coordinates."""
|
182
177
|
nl, ne = targets.shape
|
183
178
|
if nl == 0:
|
184
179
|
out = torch.zeros(batch_size, 0, ne - 1, device=self.device)
|
@@ -261,15 +256,15 @@ class v8DetectionLoss:
|
|
261
256
|
|
262
257
|
|
263
258
|
class v8SegmentationLoss(v8DetectionLoss):
|
264
|
-
"""Criterion class for computing training losses."""
|
259
|
+
"""Criterion class for computing training losses for YOLOv8 segmentation."""
|
265
260
|
|
266
261
|
def __init__(self, model): # model must be de-paralleled
|
267
|
-
"""
|
262
|
+
"""Initialize the v8SegmentationLoss class with model parameters and mask overlap setting."""
|
268
263
|
super().__init__(model)
|
269
264
|
self.overlap = model.args.overlap_mask
|
270
265
|
|
271
266
|
def __call__(self, preds, batch):
|
272
|
-
"""Calculate and return the loss for
|
267
|
+
"""Calculate and return the combined loss for detection and segmentation."""
|
273
268
|
loss = torch.zeros(4, device=self.device) # box, cls, dfl
|
274
269
|
feats, pred_masks, proto = preds if len(preds) == 3 else preds[1]
|
275
270
|
batch_size, _, mask_h, mask_w = proto.shape # batch size, number of masks, mask height, mask width
|
@@ -444,10 +439,10 @@ class v8SegmentationLoss(v8DetectionLoss):
|
|
444
439
|
|
445
440
|
|
446
441
|
class v8PoseLoss(v8DetectionLoss):
|
447
|
-
"""Criterion class for computing training losses."""
|
442
|
+
"""Criterion class for computing training losses for YOLOv8 pose estimation."""
|
448
443
|
|
449
444
|
def __init__(self, model): # model must be de-paralleled
|
450
|
-
"""
|
445
|
+
"""Initialize v8PoseLoss with model parameters and keypoint-specific loss functions."""
|
451
446
|
super().__init__(model)
|
452
447
|
self.kpt_shape = model.model[-1].kpt_shape
|
453
448
|
self.bce_pose = nn.BCEWithLogitsLoss()
|
@@ -457,7 +452,7 @@ class v8PoseLoss(v8DetectionLoss):
|
|
457
452
|
self.keypoint_loss = KeypointLoss(sigmas=sigmas)
|
458
453
|
|
459
454
|
def __call__(self, preds, batch):
|
460
|
-
"""Calculate the total loss and detach it."""
|
455
|
+
"""Calculate the total loss and detach it for pose estimation."""
|
461
456
|
loss = torch.zeros(5, device=self.device) # box, cls, dfl, kpt_location, kpt_visibility
|
462
457
|
feats, pred_kpts = preds if isinstance(preds[0], list) else preds[1]
|
463
458
|
pred_distri, pred_scores = torch.cat([xi.view(feats[0].shape[0], self.no, -1) for xi in feats], 2).split(
|
@@ -524,7 +519,7 @@ class v8PoseLoss(v8DetectionLoss):
|
|
524
519
|
|
525
520
|
@staticmethod
|
526
521
|
def kpts_decode(anchor_points, pred_kpts):
|
527
|
-
"""
|
522
|
+
"""Decode predicted keypoints to image coordinates."""
|
528
523
|
y = pred_kpts.clone()
|
529
524
|
y[..., :2] *= 2.0
|
530
525
|
y[..., 0] += anchor_points[:, [0]] - 0.5
|
@@ -599,7 +594,7 @@ class v8PoseLoss(v8DetectionLoss):
|
|
599
594
|
|
600
595
|
|
601
596
|
class v8ClassificationLoss:
|
602
|
-
"""Criterion class for computing training losses."""
|
597
|
+
"""Criterion class for computing training losses for classification."""
|
603
598
|
|
604
599
|
def __call__(self, preds, batch):
|
605
600
|
"""Compute the classification loss between predictions and true labels."""
|
@@ -613,13 +608,13 @@ class v8OBBLoss(v8DetectionLoss):
|
|
613
608
|
"""Calculates losses for object detection, classification, and box distribution in rotated YOLO models."""
|
614
609
|
|
615
610
|
def __init__(self, model):
|
616
|
-
"""
|
611
|
+
"""Initialize v8OBBLoss with model, assigner, and rotated bbox loss; model must be de-paralleled."""
|
617
612
|
super().__init__(model)
|
618
613
|
self.assigner = RotatedTaskAlignedAssigner(topk=10, num_classes=self.nc, alpha=0.5, beta=6.0)
|
619
614
|
self.bbox_loss = RotatedBboxLoss(self.reg_max).to(self.device)
|
620
615
|
|
621
616
|
def preprocess(self, targets, batch_size, scale_tensor):
|
622
|
-
"""
|
617
|
+
"""Preprocess targets for oriented bounding box detection."""
|
623
618
|
if targets.shape[0] == 0:
|
624
619
|
out = torch.zeros(batch_size, 0, 6, device=self.device)
|
625
620
|
else:
|
@@ -636,7 +631,7 @@ class v8OBBLoss(v8DetectionLoss):
|
|
636
631
|
return out
|
637
632
|
|
638
633
|
def __call__(self, preds, batch):
|
639
|
-
"""Calculate and return the loss for
|
634
|
+
"""Calculate and return the loss for oriented bounding box detection."""
|
640
635
|
loss = torch.zeros(3, device=self.device) # box, cls, dfl
|
641
636
|
feats, pred_angle = preds if isinstance(preds[0], list) else preds[1]
|
642
637
|
batch_size = pred_angle.shape[0] # batch size, number of masks, mask height, mask width
|
@@ -726,7 +721,7 @@ class v8OBBLoss(v8DetectionLoss):
|
|
726
721
|
|
727
722
|
|
728
723
|
class E2EDetectLoss:
|
729
|
-
"""Criterion class for computing training losses."""
|
724
|
+
"""Criterion class for computing training losses for end-to-end detection."""
|
730
725
|
|
731
726
|
def __init__(self, model):
|
732
727
|
"""Initialize E2EDetectLoss with one-to-many and one-to-one detection losses using the provided model."""
|