Skip to content

Commit

Permalink
Fix val.py 'no labels found bug'
Browse files Browse the repository at this point in the history
Resolves #8791

Bug first introduced in #8782
  • Loading branch information
glenn-jocher authored Jul 31, 2022
1 parent 59595c1 commit 1df732c
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions val.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def run(

seen = 0
confusion_matrix = ConfusionMatrix(nc=nc)
names = {k: v for k, v in enumerate(model.names if hasattr(model, 'names') else model.module.names)}
names = dict(enumerate(model.names if hasattr(model, 'names') else model.module.names))
class_map = coco80_to_coco91_class() if is_coco else list(range(1000))
s = ('%20s' + '%11s' * 6) % ('Class', 'Images', 'Labels', 'P', 'R', '[email protected]', '[email protected]:.95')
dt, p, r, f1, mp, mr, map50, map = [0.0, 0.0, 0.0], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
Expand Down Expand Up @@ -250,7 +250,7 @@ def run(

# Save/log
if save_txt:
save_one_txt(predn, save_conf, shape, file=save_dir / 'labels' / (path.stem + '.txt'))
save_one_txt(predn, save_conf, shape, file=save_dir / 'labels' / f'{path.stem}.txt')
if save_json:
save_one_json(predn, jdict, path, class_map) # append to COCO-JSON dictionary
callbacks.run('on_val_image_end', pred, predn, path, names, im[si])
Expand All @@ -268,9 +268,7 @@ def run(
tp, fp, p, r, f1, ap, ap_class = ap_per_class(*stats, plot=plots, save_dir=save_dir, names=names)
ap50, ap = ap[:, 0], ap.mean(1) # [email protected], [email protected]:0.95
mp, mr, map50, map = p.mean(), r.mean(), ap50.mean(), ap.mean()
nt = np.bincount(stats[3].astype(int), minlength=nc) # number of targets per class
else:
nt = torch.zeros(1)
nt = np.bincount(stats[3].astype(int), minlength=nc) # number of targets per class

# Print results
pf = '%20s' + '%11i' * 2 + '%11.3g' * 4 # print format
Expand Down

0 comments on commit 1df732c

Please sign in to comment.