MobileSAM
MobileSAM replaces SAM's ViT-H image encoder with a distilled TinyViT encoder, so the same promptable point-and-box workflow runs on lighter hardware. LibreYOLO carries a native port of it through a dedicated LibreSAM factory, separate from the LibreYOLO() detector factory.
- Tasks
- instance segmentation
- Sizes
- tiny at 1024 px
- Install
pip install libreyolo- Support tier
- Sibling tier, since v. A separate product surface with its own factory and contract.
- Licenses
- Code Apache-2.0, weights Apache-2.0. Commercial use
Install
MobileSAM needs the sam extra: LibreYOLO's own weight download still goes
through transformers' Hugging Face snapshot tooling, even though inference
runs on a native, non-transformers decoder.
pip install "libreyolo[sam]"Predict
LibreSAM(...) (or the family-specific LibreMobileSAM(...)) is a separate
entry point from LibreYOLO(...): it returns a promptable segmenter rather
than a detector, because a forward pass here is meaningless without a
spatial prompt. There is no libreyolo predict CLI command for this family;
use the Python API.
from libreyolo import LibreSAM, SAMPLE_IMAGE # MobileSAM has a single size, "tiny", so no other alias is needed.model = LibreSAM("mobilesam") # A point prompt: [x, y] in pixel coordinates, label 1 = foreground.result = model.predict(SAMPLE_IMAGE, points=[640, 420], labels=[1])print(result.masks.xy) # polygon per maskprint(result.boxes.xyxy) # tight box derived from the mask # A box prompt instead of a point.result = model.predict(SAMPLE_IMAGE, bboxes=[300, 200, 900, 700]) # No prompt at all segments the whole image (a simplified automatic# mask generator, not the exhaustive reference one).result = model.predict(SAMPLE_IMAGE)from libreyolo import LibreMobileSAM, SAMPLE_IMAGE model = LibreMobileSAM() # The image encoder is the expensive part. set_image() runs it once;# every predict() call after that reuses the cached embedding.model.set_image(SAMPLE_IMAGE)a = model.predict(points=[640, 420], labels=[1])b = model.predict(bboxes=[300, 200, 900, 700])model.reset_image()A point prompt accepts [x, y] for one object, [[x, y], ...] for several, or
numpy arrays; labels marks each point 1 (foreground) or 0 (background)
and defaults to all foreground. A box prompt takes [x1, y1, x2, y2] or a list
of boxes, one mask per box. Omitting both prompts segments the whole image by
prompting a dense grid and keeping the confident, non-overlapping masks; this
"segment everything" mode is simplified against the reference automatic mask
generator and can under-segment crowded scenes, so a real point or box prompt
is the precise path. conf filters by predicted mask quality (IoU), not a
detection confidence: pass 0.0 to keep every candidate. multimask=True
returns all three of SAM's whole-versus-part ambiguity masks per prompt
instead of the single best one. device= moves the model and, if a
set_image() session is active, its cached embedding. Every mask carries
class id 0, named "object", since a promptable mask has no fixed class
set. train(), val(), export() and track() all raise
NotImplementedError for this family: MobileSAM is predict-only in
LibreYOLO. See prediction for source types.
Variants
One size, tiny, at a fixed 1024 px input: MobileSAM ships a single TinyViT encoder rather than the base/large/huge ladder SAM-1 offers.
Checkpoints
Every published weight file for this family.
| File | Input (px) | Weights license |
|---|---|---|
| Instance segmentation | ||
| LibreMobileSAM.pt | apache-2.0 | |
Every file above exists in the LibreYOLO org today and downloads on first use.
Licensing
Check the license on the Hugging Face repository of the specific weights you download. Every checkpoint in the LibreYOLO org carries one, and they are not always the same across a family. That repository is the authoritative source; the summary below describes what applied when this page was last verified.
This is a description of the licenses involved, not legal advice. If the answer matters commercially, read the licenses yourself and take your own counsel.
- Original work
- MobileSAM, Kyung Hee University
- Upstream license
- Apache-2.0
- Upstream source
- github.com/ChaoningZhang/MobileSAM
- LibreYOLO code
- MIT
- Weights
- Apache-2.0, republished at huggingface.co/LibreYOLO
- Interpretation
- Apache-2.0 is a permissive license, so this code and these weights can be used in commercial and closed-source products. It asks you to keep the license text and attribution notices with any copy you redistribute, and it grants a patent license. LibreYOLO carries a native port of the TinyViT image encoder, prompt encoder, two-way transformer and mask decoder rather than vendoring upstream files unmodified, checked for bit-exact parity against the original Apache-2.0 implementation, with a NOTICE recording that provenance. The converted checkpoint is hosted as LibreMobileSAM.pt on the LibreYOLO Hugging Face org, tagged Apache-2.0 there as well.
Citation
@article{mobile_sam,
title={Faster Segment Anything: Towards Lightweight SAM for Mobile Applications},
author={Zhang, Chaoning and Han, Dongshen and Qiao, Yu and Kim, Jung Uk and Bae, Sung-Ho and Lee, Seungkyu and Hong, Choong Seon},
journal={arXiv preprint arXiv:2306.14289},
year={2023}
}Copied from the authors' citation block at github.com/ChaoningZhang/MobileSAM#bibtex-of-our-mobilesam.