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
This commit is contained in:
Glenn Jocher 2022-04-05 14:23:15 +02:00 committed by GitHub
parent 5f97001ed4
commit d2e7ba2a3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

4
val.py
View File

@ -162,6 +162,10 @@ def run(
# Dataloader # Dataloader
if not training: 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 model.warmup(imgsz=(1 if pt else batch_size, 3, imgsz, imgsz)) # warmup
pad = 0.0 if task in ('speed', 'benchmark') else 0.5 pad = 0.0 if task in ('speed', 'benchmark') else 0.5
rect = False if task == 'benchmark' else pt # square inference for benchmarks rect = False if task == 'benchmark' else pt # square inference for benchmarks