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 .
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 \
--image /path/to/image.jpg \
--output-dir wheel_verify_mobilesamv2_output
This script runs the MobileSAMv2 seg-every pipeline with ObjectAwareModel box proposals plus the prompt-guided decoder.
Inputs:
--checkpoint: image encoder checkpoint--prompt-decoder-checkpoint:Prompt_guided_Mask_Decoder.pt--object-aware-model-checkpoint:ObjectAwareModel.pt--image: optional input image path. If omitted, the script uses a synthetic test image.--output-dir: directory for generated visualizations- Optional tuning args:
--encoder-type,--imgsz,--iou,--conf,--retina,--decoder-batch-size,--min-box-area-ratio,--max-box-area-ratio
Outputs:
- Console summary with device, input image shape, detected box count, filtered box count, mask tensor shape, and saved output path
boxes.png: detected boxes after filteringmask_union.png: binary union of all predicted masksmask_union_overlay.png: union mask blended over the input imagemask_overlay.png: per-mask color overlay for the seg-every result
Example assets for the MobileSAMv2 seg-every flow:
Input image:
Output overlay:
Reference: Official MobileSAM repository
https://github.com/chaoningzhang/mobilesam
If you find this repo useful to you please consider click the button below to donate and support my work!
Metadata
Release files for mobilesam-lite 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mobilesam_lite-0.1.2.tar.gz | 608.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mobilesam_lite-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.3 MB
Release files / mobilesam_lite-0.1.2.tar.gz
| Download URL | mobilesam_lite-0.1.2.tar.gz |
|---|---|
| Size | 608.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
769b7e09f94f991e271345d4917a18e0b19150522ef82f4b060ed0d3da0e9dfd
|
|
BLAKE2b-256 checksum How to use checksums |
ab54f42fa6be986fe9b2e0979b1bec6327243837b9f0011bb5a8956e484d4088
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Release files / mobilesam_lite-0.1.2-py3-none-any.whl
| Download URL | mobilesam_lite-0.1.2-py3-none-any.whl |
|---|---|
| Size | 728.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1cffa3c11ee24b9ccf26a13bd946570ed4146a96e98da2edc855aa03aac60198
|
|
BLAKE2b-256 checksum How to use checksums |
e971ea86ad08abf144a56313252fb2b86cfbc1da51293e04ad636766e78d92b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|