glenn-jocher commited on
Commit
dbdee3a
1 Parent(s): a233608

multi-gpu test bug fix #15

Browse files
Files changed (3) hide show
  1. detect.py +1 -1
  2. models/yolo.py +2 -2
  3. test.py +1 -1
detect.py CHANGED
@@ -51,7 +51,7 @@ def detect(save_img=False):
51
  dataset = LoadImages(source, img_size=imgsz)
52
 
53
  # Get names and colors
54
- names = model.module.names if hasattr(model, 'module') else model.names
55
  colors = [[random.randint(0, 255) for _ in range(3)] for _ in range(len(names))]
56
 
57
  # Run inference
 
51
  dataset = LoadImages(source, img_size=imgsz)
52
 
53
  # Get names and colors
54
+ names = model.names if hasattr(model, 'names') else model.modules.names
55
  colors = [[random.randint(0, 255) for _ in range(3)] for _ in range(len(names))]
56
 
57
  # Run inference
models/yolo.py CHANGED
@@ -27,11 +27,11 @@ class Detect(nn.Module):
27
  x[i] = x[i].view(bs, self.na, self.no, ny, nx).permute(0, 1, 3, 4, 2).contiguous()
28
 
29
  if not self.training: # inference
30
- if (self.grid[i].shape[2:4] != x[i].shape[2:4]) | (self.grid[i].device != x[i].device):
31
  self.grid[i] = self._make_grid(nx, ny).to(x[i].device)
32
 
33
  y = x[i].sigmoid()
34
- y[..., 0:2] = (y[..., 0:2] * 2. - 0.5 + self.grid[i]) * self.stride[i] # xy
35
  y[..., 2:4] = (y[..., 2:4] * 2) ** 2 * self.anchor_grid[i] # wh
36
  z.append(y.view(bs, -1, self.no))
37
 
 
27
  x[i] = x[i].view(bs, self.na, self.no, ny, nx).permute(0, 1, 3, 4, 2).contiguous()
28
 
29
  if not self.training: # inference
30
+ if self.grid[i].shape[2:4] != x[i].shape[2:4]:
31
  self.grid[i] = self._make_grid(nx, ny).to(x[i].device)
32
 
33
  y = x[i].sigmoid()
34
+ y[..., 0:2] = (y[..., 0:2] * 2. - 0.5 + self.grid[i].to(x[i].device)) * self.stride[i] # xy
35
  y[..., 2:4] = (y[..., 2:4] * 2) ** 2 * self.anchor_grid[i] # wh
36
  z.append(y.view(bs, -1, self.no))
37
 
test.py CHANGED
@@ -75,7 +75,7 @@ def test(data,
75
  seen = 0
76
  model.eval()
77
  _ = model(torch.zeros((1, 3, imgsz, imgsz), device=device)) if device.type != 'cpu' else None # run once
78
- names = model.module.names if hasattr(model, 'module') else model.names
79
  coco91class = coco80_to_coco91_class()
80
  s = ('%20s' + '%12s' * 6) % ('Class', 'Images', 'Targets', 'P', 'R', 'mAP@.5', 'mAP@.5:.95')
81
  p, r, f1, mp, mr, map50, map, t0, t1 = 0., 0., 0., 0., 0., 0., 0., 0., 0.
 
75
  seen = 0
76
  model.eval()
77
  _ = model(torch.zeros((1, 3, imgsz, imgsz), device=device)) if device.type != 'cpu' else None # run once
78
+ names = model.names if hasattr(model, 'names') else model.module.names
79
  coco91class = coco80_to_coco91_class()
80
  s = ('%20s' + '%12s' * 6) % ('Class', 'Images', 'Targets', 'P', 'R', 'mAP@.5', 'mAP@.5:.95')
81
  p, r, f1, mp, mr, map50, map, t0, t1 = 0., 0., 0., 0., 0., 0., 0., 0., 0.