update: 适配昇腾
Some checks failed
Ultralytics CI / HUB (ubuntu-latest, 3.11) (push) Has been cancelled
Ultralytics CI / Benchmarks (yolo11n, macos-15, 3.11) (push) Has been cancelled
Ultralytics CI / Benchmarks (yolo11n, ubuntu-latest, 3.11) (push) Has been cancelled
Ultralytics CI / Tests (macos-15, 3.11, latest) (push) Has been cancelled
Ultralytics CI / Tests (ubuntu-latest, 3.11, latest) (push) Has been cancelled
Ultralytics CI / Tests (ubuntu-latest, 3.8, 1.8.0) (push) Has been cancelled
Ultralytics CI / Tests (windows-latest, 3.11, latest) (push) Has been cancelled
Ultralytics CI / GPU (push) Has been cancelled
Ultralytics CI / RaspberryPi (push) Has been cancelled
Ultralytics CI / Conda (ubuntu-latest, 3.11) (push) Has been cancelled
Ultralytics CI / Summary (push) Has been cancelled
Publish Docker Images / Push (push) Has been cancelled
Publish Docker Images / Push-1 (push) Has been cancelled
Publish Docker Images / Push-2 (push) Has been cancelled
Publish Docker Images / Push-3 (push) Has been cancelled
Publish Docker Images / Push-4 (push) Has been cancelled
Publish Docker Images / Push-5 (push) Has been cancelled
Publish Docker Images / Push-6 (push) Has been cancelled
Publish Docker Images / trigger-actions (push) Has been cancelled
Publish Docker Images / notify (push) Has been cancelled
Publish Docs / Docs (push) Has been cancelled
Publish to PyPI / check (push) Has been cancelled
Publish to PyPI / build (push) Has been cancelled
Publish to PyPI / publish (push) Has been cancelled
Publish to PyPI / notify (push) Has been cancelled

This commit is contained in:
Kare-Udon 2025-11-27 09:57:34 +00:00 committed by GitHub
parent e74b035c02
commit 696c1b0793
5 changed files with 34 additions and 11 deletions

View file

@ -102,9 +102,9 @@ class Detect(nn.Module):
# Inference path
shape = x[0].shape # BCHW
x_cat = torch.cat([xi.view(shape[0], self.no, -1) for xi in x], 2)
if self.format != "imx" and (self.dynamic or self.shape != shape):
self.anchors, self.strides = (x.transpose(0, 1) for x in make_anchors(x, self.stride, 0.5))
self.shape = shape
anchors, strides = make_anchors(x, self.stride, 0.5)
anchors = anchors.transpose(0, 1)
strides = strides.transpose(0, 1)
if self.export and self.format in {"saved_model", "pb", "tflite", "edgetpu", "tfjs"}: # avoid TF FlexSplitV ops
box = x_cat[:, : self.reg_max * 4]
@ -118,15 +118,15 @@ class Detect(nn.Module):
grid_h = shape[2]
grid_w = shape[3]
grid_size = torch.tensor([grid_w, grid_h, grid_w, grid_h], device=box.device).reshape(1, 4, 1)
norm = self.strides / (self.stride[0] * grid_size)
dbox = self.decode_bboxes(self.dfl(box) * norm, self.anchors.unsqueeze(0) * norm[:, :2])
norm = strides / (stride[0] * grid_size)
dbox = self.decode_bboxes(self.dfl(box) * norm, anchors.unsqueeze(0) * norm[:, :2])
elif self.export and self.format == "imx":
dbox = self.decode_bboxes(
self.dfl(box) * self.strides, self.anchors.unsqueeze(0) * self.strides, xywh=False
self.dfl(box) * strides, anchors.unsqueeze(0) * strides, xywh=False
)
return dbox.transpose(1, 2), cls.sigmoid().permute(0, 2, 1)
else:
dbox = self.decode_bboxes(self.dfl(box), self.anchors.unsqueeze(0)) * self.strides
dbox = self.decode_bboxes(self.dfl(box), anchors.unsqueeze(0)) * strides
return torch.cat((dbox, cls.sigmoid()), 1)