multi-gpu test bug fix #15
This commit is contained in:
parent
a2336088f0
commit
dbdee3a4a3
|
|
@ -51,7 +51,7 @@ def detect(save_img=False):
|
||||||
dataset = LoadImages(source, img_size=imgsz)
|
dataset = LoadImages(source, img_size=imgsz)
|
||||||
|
|
||||||
# Get names and colors
|
# Get names and colors
|
||||||
names = model.module.names if hasattr(model, 'module') else model.names
|
names = model.names if hasattr(model, 'names') else model.modules.names
|
||||||
colors = [[random.randint(0, 255) for _ in range(3)] for _ in range(len(names))]
|
colors = [[random.randint(0, 255) for _ in range(3)] for _ in range(len(names))]
|
||||||
|
|
||||||
# Run inference
|
# Run inference
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,11 @@ class Detect(nn.Module):
|
||||||
x[i] = x[i].view(bs, self.na, self.no, ny, nx).permute(0, 1, 3, 4, 2).contiguous()
|
x[i] = x[i].view(bs, self.na, self.no, ny, nx).permute(0, 1, 3, 4, 2).contiguous()
|
||||||
|
|
||||||
if not self.training: # inference
|
if not self.training: # inference
|
||||||
if (self.grid[i].shape[2:4] != x[i].shape[2:4]) | (self.grid[i].device != x[i].device):
|
if self.grid[i].shape[2:4] != x[i].shape[2:4]:
|
||||||
self.grid[i] = self._make_grid(nx, ny).to(x[i].device)
|
self.grid[i] = self._make_grid(nx, ny).to(x[i].device)
|
||||||
|
|
||||||
y = x[i].sigmoid()
|
y = x[i].sigmoid()
|
||||||
y[..., 0:2] = (y[..., 0:2] * 2. - 0.5 + self.grid[i]) * self.stride[i] # xy
|
y[..., 0:2] = (y[..., 0:2] * 2. - 0.5 + self.grid[i].to(x[i].device)) * self.stride[i] # xy
|
||||||
y[..., 2:4] = (y[..., 2:4] * 2) ** 2 * self.anchor_grid[i] # wh
|
y[..., 2:4] = (y[..., 2:4] * 2) ** 2 * self.anchor_grid[i] # wh
|
||||||
z.append(y.view(bs, -1, self.no))
|
z.append(y.view(bs, -1, self.no))
|
||||||
|
|
||||||
|
|
|
||||||
2
test.py
2
test.py
|
|
@ -75,7 +75,7 @@ def test(data,
|
||||||
seen = 0
|
seen = 0
|
||||||
model.eval()
|
model.eval()
|
||||||
_ = model(torch.zeros((1, 3, imgsz, imgsz), device=device)) if device.type != 'cpu' else None # run once
|
_ = model(torch.zeros((1, 3, imgsz, imgsz), device=device)) if device.type != 'cpu' else None # run once
|
||||||
names = model.module.names if hasattr(model, 'module') else model.names
|
names = model.names if hasattr(model, 'names') else model.module.names
|
||||||
coco91class = coco80_to_coco91_class()
|
coco91class = coco80_to_coco91_class()
|
||||||
s = ('%20s' + '%12s' * 6) % ('Class', 'Images', 'Targets', 'P', 'R', 'mAP@.5', 'mAP@.5:.95')
|
s = ('%20s' + '%12s' * 6) % ('Class', 'Images', 'Targets', 'P', 'R', 'mAP@.5', 'mAP@.5:.95')
|
||||||
p, r, f1, mp, mr, map50, map, t0, t1 = 0., 0., 0., 0., 0., 0., 0., 0., 0.
|
p, r, f1, mp, mr, map50, map, t0, t1 = 0., 0., 0., 0., 0., 0., 0., 0., 0.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue