Commit
·
ba9ab66
1
Parent(s):
0362f10
model.names for dataParallel
Browse files
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.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.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
|
test.py
CHANGED
@@ -65,15 +65,17 @@ def test(data,
|
|
65 |
single_cls=opt.single_cls, # single class mode
|
66 |
pad=0.0 if fast else 0.5) # padding
|
67 |
batch_size = min(batch_size, len(dataset))
|
|
|
68 |
dataloader = DataLoader(dataset,
|
69 |
batch_size=batch_size,
|
70 |
-
num_workers=
|
71 |
pin_memory=True,
|
72 |
collate_fn=dataset.collate_fn)
|
73 |
|
74 |
seen = 0
|
75 |
model.eval()
|
76 |
_ = model(torch.zeros((1, 3, imgsz, imgsz), device=device)) if device.type != 'cpu' else None # run once
|
|
|
77 |
coco91class = coco80_to_coco91_class()
|
78 |
s = ('%20s' + '%12s' * 6) % ('Class', 'Images', 'Targets', 'P', 'R', '[email protected]', '[email protected]:.95')
|
79 |
p, r, f1, mp, mr, map50, map, t0, t1 = 0., 0., 0., 0., 0., 0., 0., 0., 0.
|
@@ -168,9 +170,9 @@ def test(data,
|
|
168 |
# Plot images
|
169 |
if batch_i < 1:
|
170 |
f = 'test_batch%g_gt.jpg' % batch_i # filename
|
171 |
-
plot_images(imgs, targets, paths, f,
|
172 |
f = 'test_batch%g_pred.jpg' % batch_i
|
173 |
-
plot_images(imgs, output_to_target(output, width, height), paths, f,
|
174 |
|
175 |
# Compute statistics
|
176 |
stats = [np.concatenate(x, 0) for x in zip(*stats)] # to numpy
|
@@ -189,7 +191,7 @@ def test(data,
|
|
189 |
# Print results per class
|
190 |
if verbose and nc > 1 and len(stats):
|
191 |
for i, c in enumerate(ap_class):
|
192 |
-
print(pf % (
|
193 |
|
194 |
# Print speeds
|
195 |
t = tuple(x / seen * 1E3 for x in (t0, t1, t0 + t1)) + (imgsz, imgsz, batch_size) # tuple
|
|
|
65 |
single_cls=opt.single_cls, # single class mode
|
66 |
pad=0.0 if fast else 0.5) # padding
|
67 |
batch_size = min(batch_size, len(dataset))
|
68 |
+
nw = min([os.cpu_count(), batch_size if batch_size > 1 else 0, 8]) # number of workers
|
69 |
dataloader = DataLoader(dataset,
|
70 |
batch_size=batch_size,
|
71 |
+
num_workers=nw,
|
72 |
pin_memory=True,
|
73 |
collate_fn=dataset.collate_fn)
|
74 |
|
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', '[email protected]', '[email protected]:.95')
|
81 |
p, r, f1, mp, mr, map50, map, t0, t1 = 0., 0., 0., 0., 0., 0., 0., 0., 0.
|
|
|
170 |
# Plot images
|
171 |
if batch_i < 1:
|
172 |
f = 'test_batch%g_gt.jpg' % batch_i # filename
|
173 |
+
plot_images(imgs, targets, paths, f, names) # ground truth
|
174 |
f = 'test_batch%g_pred.jpg' % batch_i
|
175 |
+
plot_images(imgs, output_to_target(output, width, height), paths, f, names) # predictions
|
176 |
|
177 |
# Compute statistics
|
178 |
stats = [np.concatenate(x, 0) for x in zip(*stats)] # to numpy
|
|
|
191 |
# Print results per class
|
192 |
if verbose and nc > 1 and len(stats):
|
193 |
for i, c in enumerate(ap_class):
|
194 |
+
print(pf % (names[c], seen, nt[c], p[i], r[i], ap50[i], ap[i]))
|
195 |
|
196 |
# Print speeds
|
197 |
t = tuple(x / seen * 1E3 for x in (t0, t1, t0 + t1)) + (imgsz, imgsz, batch_size) # tuple
|