glenn-jocher commited on
Commit
18674e2
·
unverified ·
1 Parent(s): 47233e1

experimental.py Apple MPS device fix (#8121)

Browse files

* experimental.py Apple MPS fix

May resolve https://github.com/ultralytics/yolov5/issues/8102

* Update experimental.py

* Update experimental.py

Files changed (1) hide show
  1. models/experimental.py +3 -3
models/experimental.py CHANGED
@@ -72,13 +72,13 @@ class Ensemble(nn.ModuleList):
72
 
73
 
74
  def attempt_load(weights, device=None, inplace=True, fuse=True):
 
75
  from models.yolo import Detect, Model
76
 
77
- # Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a
78
  model = Ensemble()
79
  for w in weights if isinstance(weights, list) else [weights]:
80
- ckpt = torch.load(attempt_download(w), map_location=device)
81
- ckpt = (ckpt.get('ema') or ckpt['model']).float() # FP32 model
82
  model.append(ckpt.fuse().eval() if fuse else ckpt.eval()) # fused or un-fused model in eval mode
83
 
84
  # Compatibility updates
 
72
 
73
 
74
  def attempt_load(weights, device=None, inplace=True, fuse=True):
75
+ # Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a
76
  from models.yolo import Detect, Model
77
 
 
78
  model = Ensemble()
79
  for w in weights if isinstance(weights, list) else [weights]:
80
+ ckpt = torch.load(attempt_download(w), map_location='cpu') # load
81
+ ckpt = (ckpt.get('ema') or ckpt['model']).to(device).float() # FP32 model
82
  model.append(ckpt.fuse().eval() if fuse else ckpt.eval()) # fused or un-fused model in eval mode
83
 
84
  # Compatibility updates