From f3bed6305717cc225b13783af01a79b3166aa7c6 Mon Sep 17 00:00:00 2001 From: Corey Lowman Date: Wed, 26 Oct 2022 19:29:19 +0000 Subject: [PATCH] Cherry pick of #8067 from ultralytics fork --- utils/loss.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/loss.py b/utils/loss.py index bf9b592d4ad2..332dc9d2b2fc 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -189,8 +189,8 @@ def build_targets(self, p, targets): ], device=self.device).float() * g # offsets for i in range(self.nl): - anchors = self.anchors[i] - gain[2:6] = torch.tensor(p[i].shape)[[3, 2, 3, 2]] # xyxy gain + anchors, shape = self.anchors[i], p[i].shape + gain[2:6] = torch.tensor(shape)[[3, 2, 3, 2]] # xyxy gain # Match targets to anchors t = targets * gain @@ -220,7 +220,7 @@ def build_targets(self, p, targets): gi, gj = gij.T # grid indices # Append - indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1))) # image, anchor, grid indices + indices.append((b, a, gj.clamp_(0, shape[2] - 1), gi.clamp_(0, shape[3] - 1))) # image, anchor, grid tbox.append(torch.cat((gxy - gij, gwh), 1)) # box anch.append(anchors[a]) # anchors tcls.append(c) # class