MobileSAM icon indicating copy to clipboard operation
MobileSAM copied to clipboard

Error running notebook

Open cyborgdennett opened this issue 2 years ago • 2 comments

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 avatar Oct 05 '23 13:10 cyborgdennett

Add

!pip install timm

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

cyborgdennett avatar Oct 05 '23 13:10 cyborgdennett

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)

cyborgdennett avatar Oct 05 '23 13:10 cyborgdennett