glenn-jocher commited on
Commit
8f17a96
1 Parent(s): 8f17552
Files changed (1) hide show
  1. models/yolo.py +0 -28
models/yolo.py CHANGED
@@ -38,34 +38,6 @@ class Detect(nn.Module):
38
 
39
  return x if self.training else (torch.cat(z, 1), x)
40
 
41
- def forward_(self, x):
42
- if hasattr(self, 'nx'):
43
- z = [] # inference output
44
- for (y, gi, agi, si, nyi, nxi) in zip(x, self.grid, self.ag, self.stride, self.ny, self.nx):
45
- m = self.na * nxi * nyi
46
- y = y.view(1, self.na, self.no, nyi, nxi).permute(0, 1, 3, 4, 2).contiguous().view(m, self.no).sigmoid()
47
-
48
- xy = (y[..., 0:2] * 2. - 0.5 + gi) * si # xy
49
- wh = (y[..., 2:4] * 2) ** 2 * agi # wh
50
- p_cls = y[:, 4:5] if self.nc == 1 else y[:, 5:self.no] * y[:, 4:5] # conf
51
- z.append([p_cls, xy, wh])
52
-
53
- z = [torch.cat(x, 0) for x in zip(*z)]
54
- return z[0], torch.cat(z[1:3], 1) # scores, boxes: 3780x80, 3780x4
55
-
56
- else: # dry run
57
- self.nx = [0] * self.nl
58
- self.ny = [0] * self.nl
59
- self.ag = [0] * self.nl
60
- for i in range(self.nl):
61
- bs, _, ny, nx = x[i].shape
62
- m = self.na * nx * ny
63
- self.grid[i] = self._make_grid(nx, ny).repeat(1, self.na, 1, 1, 1).view(m, 2) / torch.tensor([[nx, ny]])
64
- self.ag[i] = self.anchor_grid[i].repeat(1, 1, nx, ny, 1).view(m, 2)
65
- self.nx[i] = nx
66
- self.ny[i] = ny
67
- return None
68
-
69
  @staticmethod
70
  def _make_grid(nx=20, ny=20):
71
  yv, xv = torch.meshgrid([torch.arange(ny), torch.arange(nx)])
 
38
 
39
  return x if self.training else (torch.cat(z, 1), x)
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  @staticmethod
42
  def _make_grid(nx=20, ny=20):
43
  yv, xv = torch.meshgrid([torch.arange(ny), torch.arange(nx)])