Update detect.py non-inplace with y.tensor_split() (#7062)

This commit is contained in:
Glenn Jocher authored and GitHub committed 2022-03-20 18:02:05 +01:00
1 parent f327eee614
commit d5e363f29d
1 file changed
+4 -3
+4 -3
View File
@@ -62,9 +62,10 @@ class Detect(nn.Module):
y[..., 0:2] = (y[..., 0:2] * 2 - 0.5 + self.grid[i]) * self.stride[i] # xy
y[..., 2:4] = (y[..., 2:4] * 2) ** 2 * self.anchor_grid[i] # wh
else: # for YOLOv5 on AWS Inferentia https://github.com/ultralytics/yolov5/pull/2953
xy = (y[..., 0:2] * 2 - 0.5 + self.grid[i]) * self.stride[i] # xy
wh = (y[..., 2:4] * 2) ** 2 * self.anchor_grid[i] # wh
y = torch.cat((xy, wh, y[..., 4:]), -1)
xy, wh, conf = y.tensor_split((2, 4), 4)
xy = (xy * 2 - 0.5 + self.grid[i]) * self.stride[i] # xy
wh = (wh * 2) ** 2 * self.anchor_grid[i] # wh
y = torch.cat((xy, wh, conf), 4)
z.append(y.view(bs, -1, self.no))
return x if self.training else (torch.cat(z, 1), x)