ChaoningZhang / MobileSAM

This is the official code for MobileSAM project that makes SAM lightweight for mobile applications and beyond!
Apache License 2.0
4.49k stars 469 forks source link

Error running notebook #106

Open cyborgdennett opened 9 months ago

cyborgdennett commented 9 months ago

Hi, I try to run the notebook https://github.com/ChaoningZhang/MobileSAM/blob/master/notebooks/automatic_mask_generator_example.ipynb on colab, and I get this error. image

cyborgdennett commented 9 months ago

Add

!pip install timm

to the import and install of the notebook to fix this issue

cyborgdennett commented 9 months ago

On colab you get one more error, when loading the model. Fix with the following code:

import sys
sys.path.append("..")
from mobile_sam import sam_model_registry, SamAutomaticMaskGenerator, SamPredictor

if 'google.colab' in sys.modules:
  sam_checkpoint = "/content/mobile_sam.pt"
else:
  sam_checkpoint = "../weights/mobile_sam.pt"

model_type = "vit_t"

device = "cuda" if torch.cuda.is_available() else "cpu"

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

mask_generator = SamAutomaticMaskGenerator(sam)