YOLOv5 Apple Metal Performance Shader (MPS) support (#7878)
* Apple Metal Performance Shader (MPS) device support Following https://pytorch.org/blog/introducing-accelerated-pytorch-training-on-mac/ Should work with Apple M1 devices with PyTorch nightly installed with command `--device mps`. Usage examples: ```bash python train.py --device mps python detect.py --device mps python val.py --device mps ``` * Update device strategy to fix MPS issue
This commit is contained in:
1 parent
27911dc824
commit
c215878f11
5 files changed
+11
-8
No files matched your search
@@ -71,14 +71,14 @@ class Ensemble(nn.ModuleList):
|
||||
return y, None # inference, train output
|
||||
|
||||
|
||||
def attempt_load(weights, map_location=None, inplace=True, fuse=True):
|
||||
def attempt_load(weights, device=None, inplace=True, fuse=True):
|
||||
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=map_location) # load
|
||||
ckpt = (ckpt.get('ema') or ckpt['model']).float() # FP32 model
|
||||
ckpt = torch.load(attempt_download(w))
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user