glenn-jocher commited on
Commit
3f3852e
1 Parent(s): ab5b917

Fix val.py Ensemble() (#7490)

Browse files
Files changed (2) hide show
  1. models/experimental.py +3 -2
  2. val.py +1 -1
models/experimental.py CHANGED
@@ -115,7 +115,8 @@ def attempt_load(weights, map_location=None, inplace=True, fuse=True):
115
  return model[-1] # return model
116
  else:
117
  print(f'Ensemble created with {weights}\n')
118
- for k in ['names']:
119
- setattr(model, k, getattr(model[-1], k))
120
  model.stride = model[torch.argmax(torch.tensor([m.stride.max() for m in model])).int()].stride # max stride
 
121
  return model # return ensemble
 
115
  return model[-1] # return model
116
  else:
117
  print(f'Ensemble created with {weights}\n')
118
+ for k in 'names', 'nc', 'yaml':
119
+ setattr(model, k, getattr(model[0], k))
120
  model.stride = model[torch.argmax(torch.tensor([m.stride.max() for m in model])).int()].stride # max stride
121
+ assert all(model[0].nc == m.nc for m in model), f'Models have different class counts: {[m.nc for m in model]}'
122
  return model # return ensemble
val.py CHANGED
@@ -163,7 +163,7 @@ def run(
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
 
163
  # Dataloader
164
  if not training:
165
  if pt and not single_cls: # check --weights are trained on --data
166
+ ncm = model.model.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