Skip to content
This repository was archived by the owner on Jun 4, 2025. It is now read-only.

Commit d5e363f

Browse files
authored
Update detect.py non-inplace with y.tensor_split() (ultralytics#7062)
1 parent f327eee commit d5e363f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

models/yolo.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ def forward(self, x):
6262
y[..., 0:2] = (y[..., 0:2] * 2 - 0.5 + self.grid[i]) * self.stride[i] # xy
6363
y[..., 2:4] = (y[..., 2:4] * 2) ** 2 * self.anchor_grid[i] # wh
6464
else: # for YOLOv5 on AWS Inferentia https://github.com/ultralytics/yolov5/pull/2953
65-
xy = (y[..., 0:2] * 2 - 0.5 + self.grid[i]) * self.stride[i] # xy
66-
wh = (y[..., 2:4] * 2) ** 2 * self.anchor_grid[i] # wh
67-
y = torch.cat((xy, wh, y[..., 4:]), -1)
65+
xy, wh, conf = y.tensor_split((2, 4), 4)
66+
xy = (xy * 2 - 0.5 + self.grid[i]) * self.stride[i] # xy
67+
wh = (wh * 2) ** 2 * self.anchor_grid[i] # wh
68+
y = torch.cat((xy, wh, conf), 4)
6869
z.append(y.view(bs, -1, self.no))
6970

7071
return x if self.training else (torch.cat(z, 1), x)

0 commit comments

Comments
 (0)