Unverified 提交 34cb277d authored 作者: Glenn Jocher's avatar Glenn Jocher 提交者: GitHub

Fix val.py 'no labels found bug' (#8806)

Resolves https://github.com/ultralytics/yolov5/issues/8791 Bug first introduced in #8782
上级 59595c13
...@@ -182,7 +182,7 @@ def run( ...@@ -182,7 +182,7 @@ def run(
seen = 0 seen = 0
confusion_matrix = ConfusionMatrix(nc=nc) 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)) class_map = coco80_to_coco91_class() if is_coco else list(range(1000))
s = ('%20s' + '%11s' * 6) % ('Class', 'Images', 'Labels', 'P', 'R', 'mAP@.5', 'mAP@.5:.95') s = ('%20s' + '%11s' * 6) % ('Class', 'Images', 'Labels', 'P', 'R', 'mAP@.5', 'mAP@.5:.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 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
...@@ -250,7 +250,7 @@ def run( ...@@ -250,7 +250,7 @@ def run(
# Save/log # Save/log
if save_txt: 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: if save_json:
save_one_json(predn, jdict, path, class_map) # append to COCO-JSON dictionary 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]) callbacks.run('on_val_image_end', pred, predn, path, names, im[si])
...@@ -268,9 +268,7 @@ def run( ...@@ -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) 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) # AP@0.5, AP@0.5:0.95 ap50, ap = ap[:, 0], ap.mean(1) # AP@0.5, AP@0.5:0.95
mp, mr, map50, map = p.mean(), r.mean(), ap50.mean(), ap.mean() 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 nt = np.bincount(stats[3].astype(int), minlength=nc) # number of targets per class
else:
nt = torch.zeros(1)
# Print results # Print results
pf = '%20s' + '%11i' * 2 + '%11.3g' * 4 # print format pf = '%20s' + '%11i' * 2 + '%11.3g' * 4 # print format
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论