diff --git a/ultralytics/__init__.py b/ultralytics/__init__.py index bfa52de3..4e5c7bc5 100644 --- a/ultralytics/__init__.py +++ b/ultralytics/__init__.py @@ -1,6 +1,6 @@ # Ultralytics YOLO 🚀, AGPL-3.0 license -__version__ = "8.2.84" +__version__ = "8.2.85" import os diff --git a/ultralytics/engine/exporter.py b/ultralytics/engine/exporter.py index 891fa8bb..62f6352c 100644 --- a/ultralytics/engine/exporter.py +++ b/ultralytics/engine/exporter.py @@ -249,6 +249,7 @@ class Exporter: m.dynamic = self.args.dynamic m.export = True m.format = self.args.format + m.max_det = self.args.max_det elif isinstance(m, C2f) and not is_tf_format: # EdgeTPU does not support FlexSplitV while split provides cleaner ONNX graph m.forward = m.forward_split diff --git a/ultralytics/nn/modules/head.py b/ultralytics/nn/modules/head.py index ed0b90f8..1a02e2b2 100644 --- a/ultralytics/nn/modules/head.py +++ b/ultralytics/nn/modules/head.py @@ -144,12 +144,12 @@ class Detect(nn.Module): (torch.Tensor): Processed predictions with shape (batch_size, min(max_det, num_anchors), 6) and last dimension format [x, y, w, h, max_class_prob, class_index]. """ - batch_size, anchors, predictions = preds.shape # i.e. shape(16,8400,84) + batch_size, anchors, _ = preds.shape # i.e. shape(16,8400,84) boxes, scores = preds.split([4, nc], dim=-1) index = scores.amax(dim=-1).topk(min(max_det, anchors))[1].unsqueeze(-1) boxes = boxes.gather(dim=1, index=index.repeat(1, 1, 4)) scores = scores.gather(dim=1, index=index.repeat(1, 1, nc)) - scores, index = scores.flatten(1).topk(max_det) + scores, index = scores.flatten(1).topk(min(max_det, anchors)) i = torch.arange(batch_size)[..., None] # batch indices return torch.cat([boxes[i, index // nc], scores[..., None], (index % nc)[..., None].float()], dim=-1) diff --git a/ultralytics/utils/ops.py b/ultralytics/utils/ops.py index afe2f702..b76168f9 100644 --- a/ultralytics/utils/ops.py +++ b/ultralytics/utils/ops.py @@ -218,7 +218,7 @@ def non_max_suppression( classes = torch.tensor(classes, device=prediction.device) if prediction.shape[-1] == 6: # end-to-end model (BNC, i.e. 1,300,6) - output = [pred[pred[:, 4] > conf_thres] for pred in prediction] + output = [pred[pred[:, 4] > conf_thres][:max_det] for pred in prediction] if classes is not None: output = [pred[(pred[:, 5:6] == classes).any(1)] for pred in output] return output