glenn-jocher commited on
Commit
d2e7ba2
1 Parent(s): 5f97001

val.py `--weights` and `--data` compatibility check (#7292)

Browse files

Improved error messages for understanding of user error with val.py. May help https://github.com/ultralytics/yolov5/issues/7291

Files changed (1) hide show
  1. val.py +4 -0
val.py CHANGED
@@ -162,6 +162,10 @@ def run(
162
 
163
  # Dataloader
164
  if not training:
 
 
 
 
165
  model.warmup(imgsz=(1 if pt else batch_size, 3, imgsz, imgsz)) # warmup
166
  pad = 0.0 if task in ('speed', 'benchmark') else 0.5
167
  rect = False if task == 'benchmark' else pt # square inference for benchmarks
 
162
 
163
  # Dataloader
164
  if not training:
165
+ if pt and not single_cls: # check --weights are trained on --data
166
+ ncm = model.model.yaml['nc']
167
+ assert ncm == nc, f'{weights[0]} ({ncm} classes) trained on different --data than what you passed ({nc} ' \
168
+ f'classes). Pass correct combination of --weights and --data that are trained together.'
169
  model.warmup(imgsz=(1 if pt else batch_size, 3, imgsz, imgsz)) # warmup
170
  pad = 0.0 if task in ('speed', 'benchmark') else 0.5
171
  rect = False if task == 'benchmark' else pt # square inference for benchmarks