Skip to main content

Unofficial MobileSAMv2 and MobileSAM software package for lightweight Segment Anything and everything inference.

Project description

MobileSAM_lite

An unofficial Python package for MobileSAM and MobileSAMv2 runtime that adds support for lighter encoder models not available in the original implementation.

This package vendors the runtime code needed for inference:

  • mobilesamv2
  • tinyvit
  • efficientvit
  • ultralytics under mobilesam_lite/_vendor/ultralytics

It intentionally does not bundle model checkpoints. Download weights separately and pass the checkpoint path at runtime.

The optional mobilesamv2.promt_mobilesamv2 module now resolves its Ultralytics dependency from the vendored package in mobilesam_lite._vendor.ultralytics.

Install locally

pip install -e .

Install with pypi

pip install mobilesam-lite

Example

import torch

from mobilesam_lite.mobile_sam import SamPredictor, sam_model_registry

model = sam_model_registry["vit_t"]("./weight/mobile_sam.pt")
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
model.eval()

predictor = SamPredictor(model)

Verify an installed wheel

After installing the wheel into a clean environment, run:

python example_inference_mobilesam.py --checkpoint /path/to/mobile_sam.pt

You can also provide a real image:

python example_inference_mobilesam.py --checkpoint /path/to/mobile_sam.pt --image /path/to/image.jpg

The script prints the installed distribution version, the imported package path, and the output tensor shapes from one prediction call.

For the MobileSAMv2 decoder path, use:

python example_inference_mobilesamv2.py \
  --checkpoint /path/to/mobile_sam.pt \
  --prompt-decoder-checkpoint /path/to/Prompt_guided_Mask_Decoder.pt \
  --object-aware-model-checkpoint /path/to/ObjectAwareModel.pt

This script verifies the packaged MobileSAMv2 pipeline with ObjectAwareModel box proposals plus the prompt-guided decoder, and writes boxes.png, mask_union.png, mask_union_overlay.png, and mask_overlay.png into the chosen output directory.

Reference: Official MobileSAM repository

https://github.com/chaoningzhang/mobilesam

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mobilesam_lite-0.1.1.tar.gz (607.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mobilesam_lite-0.1.1-py3-none-any.whl (728.2 kB view details)

Uploaded Python 3

File details

Details for the file mobilesam_lite-0.1.1.tar.gz.

File metadata

  • Download URL: mobilesam_lite-0.1.1.tar.gz
  • Upload date:
  • Size: 607.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for mobilesam_lite-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a9612891c3f87011a6f7ceb70a2e9b079bd916fa02d77ddb4c8d3d7c9e40b5a8
MD5 4cabc161e5059f0b4fc2fed5303f1226
BLAKE2b-256 7390e52faa28e8a11abf47b3d66e859b0df53b967360be9c3f721a34cb7d11ff

See more details on using hashes here.

File details

Details for the file mobilesam_lite-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mobilesam_lite-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 728.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for mobilesam_lite-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5bc693932e1980a355b84dbeee8b8e5875f411bbb28905127d7a4bb6bb75d801
MD5 9948e92732297d84b5fed1cfdceb9925
BLAKE2b-256 59434a21d353462360aa534cedc3af15971f7c9c8f20a5d77b515f4d6174468d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page