MobileSAM icon indicating copy to clipboard operation
MobileSAM copied to clipboard

Apple MPS support?

Open shersoni610 opened this issue 1 year ago • 1 comments

Hello,

Does anyone knows how to use apple "MPS" instead of cpu/cuda device?

shersoni610 avatar Jul 22 '23 23:07 shersoni610

Install torch with mps support then it should be enough to choose mps as backend

from mobile_sam import sam_model_registry, SamAutomaticMaskGenerator, SamPredictor

model_type = "vit_t"
sam_checkpoint = "./weights/mobile_sam.pt"

device = "mps"

mobile_sam = sam_model_registry[model_type](checkpoint=sam_checkpoint)
mobile_sam.to(device=device)
mobile_sam.eval()

predictor = SamPredictor(mobile_sam)
predictor.set_image(<your_image>)
masks, _, _ = predictor.predict(<input_prompts>)

JunkyByte avatar Jul 27 '23 21:07 JunkyByte