From 18674e2f037953001f007e4cd5ab176048093e88 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 6 Jun 2022 23:58:50 +0200 Subject: [PATCH] experimental.py Apple MPS device fix (#8121) * experimental.py Apple MPS fix May resolve https://github.com/ultralytics/yolov5/issues/8102 * Update experimental.py * Update experimental.py --- models/experimental.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/experimental.py b/models/experimental.py index c2d934546714..db8e5b8e1dfd 100644 --- a/models/experimental.py +++ b/models/experimental.py @@ -72,13 +72,13 @@ def forward(self, x, augment=False, profile=False, visualize=False): def attempt_load(weights, device=None, inplace=True, fuse=True): + # Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a from models.yolo import Detect, Model - # Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a model = Ensemble() for w in weights if isinstance(weights, list) else [weights]: - ckpt = torch.load(attempt_download(w), map_location=device) - ckpt = (ckpt.get('ema') or ckpt['model']).float() # FP32 model + ckpt = torch.load(attempt_download(w), map_location='cpu') # load + ckpt = (ckpt.get('ema') or ckpt['model']).to(device).float() # FP32 model model.append(ckpt.fuse().eval() if fuse else ckpt.eval()) # fused or un-fused model in eval mode # Compatibility updates