From d2e7ba2a3af8f6f17fa5240422b964a1ecf717d5 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 5 Apr 2022 14:23:15 +0200 Subject: [PATCH] val.py `--weights` and `--data` compatibility check (#7292) Improved error messages for understanding of user error with val.py. May help https://github.com/ultralytics/yolov5/issues/7291 --- val.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/val.py b/val.py index 019beedea61a..50a6d91edfff 100644 --- a/val.py +++ b/val.py @@ -162,6 +162,10 @@ def run( # Dataloader if not training: + if pt and not single_cls: # check --weights are trained on --data + ncm = model.model.yaml['nc'] + assert ncm == nc, f'{weights[0]} ({ncm} classes) trained on different --data than what you passed ({nc} ' \ + f'classes). Pass correct combination of --weights and --data that are trained together.' model.warmup(imgsz=(1 if pt else batch_size, 3, imgsz, imgsz)) # warmup pad = 0.0 if task in ('speed', 'benchmark') else 0.5 rect = False if task == 'benchmark' else pt # square inference for benchmarks