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:
mobilesamv2tinyvitefficientvitultralyticsundermobilesam_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 .
Build distributions
python -m build
This will generate wheel and source distributions under dist/.
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mobilesam_lite-0.1.0.tar.gz.
File metadata
- Download URL: mobilesam_lite-0.1.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efd99dab3594be43b66ff11bf2fa7df571693fcbfeed57204447fd81309ccedd
|
|
| MD5 |
b5067f808d08ce835f7e2e1dd7015ba4
|
|
| BLAKE2b-256 |
f9cbdd1421d787c2bcfc3d8a31e1897e3d221404d8d02d1bfedc8bdb6e3c6200
|
File details
Details for the file mobilesam_lite-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mobilesam_lite-0.1.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b030da1c043d779571fa817fe4ca866f59f1496c19bd6004db5c390deba9a125
|
|
| MD5 |
f570b142fb871ef3de906f752aeae20d
|
|
| BLAKE2b-256 |
08e7ba82c9b2116a0b6572eeab9be5b210ade83fe0a328db053c52eaafa7aea3
|