|
Download README.md from fastforks/mobile-sam: direct link, hf CLI and curl.
- Browser
- Download file 6.53 kB
-
https://huggingface.co/fastforks/mobile-sam/resolve/main/README.md
- Command line
-
hf download hf://fastforks/mobile-sam/README.md
-
curl -L -o README.md https://huggingface.co/fastforks/mobile-sam/resolve/main/README.md
6.53 kB
| library_name: "fastforks" | |
| pipeline_tag: "mask-generation" | |
| license: "apache-2.0" | |
| tags: | |
| - "promptable_segmentation" | |
| - "segment-anything" | |
| - "promptable-segmentation" | |
| - "cuda" | |
| - "pytorch" | |
| - "fastforks" | |
| - "fastforks-card" | |
| # MobileSAM (fastforks) | |
| MobileSAM (Zhang et al. 2023, Kyung Hee University): Segment Anything with the ViT-H image encoder replaced by a TinyViT-5M (an MBConv stage, then window attention with depthwise convs) distilled from it; SAM's own prompt encoder and mask decoder, so points, boxes and mask logits work the same. The portable `module()` is the image encoder only. | |
| This repo is the model card only: it holds no weights. fastforks downloads the authors' weights from the links below and checks them against the SHA-256 in the model card. Code: <https://github.com/kleinicke/fastforks>. Kernels for the `kernels` backend: <https://huggingface.co/fastforks/kernels>. Original code: <https://github.com/ChaoningZhang/MobileSAM> at `f706ad9c4eb7`. | |
| Task: promptable_segmentation. Tier: experimental. Outputs: `pred_masks`, `iou_scores`. Backends: `portable`, `kernels`. | |
| Input: one image plus a point, box or text prompt. Output: masks with quality scores. | |
| ## Variants | |
| Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in [`card.toml`](https://github.com/kleinicke/fastforks/blob/main/src/fastforks/promptable_segmentation/models/mobile_sam/card.toml). | |
| | variant | weights (author link) | SHA-256 | weights licence | commercial use | | |
| |---|---|---|---|---| | |
| | `mobile-sam@1` | [mobile_sam.pt](https://github.com/ChaoningZhang/MobileSAM/raw/f706ad9c4eb7f219c00d9050e46328518ffb65d2/weights/mobile_sam.pt) | `6dbb90523a35` | Apache-2.0 | yes | | |
| ## Licence | |
| Original-code strings, recorded as they are (research-use package; check them before any other use). Code: Apache-2.0 AND MIT. Licence files: `LICENSE`, `LICENSE-TinyViT`. | |
| Training data: image encoder distilled from SAM ViT-H on 1 % of SA-1B (about 100k images) per the README and paper; prompt encoder and mask decoder are SAM's (trained on SA-1B: 11M licensed images, 1.1B automatically generated masks); the dataset itself is under the SA-1B research licence. | |
| Licence evidence: https://github.com/ChaoningZhang/MobileSAM/blob/f706ad9c4eb7f219c00d9050e46328518ffb65d2/LICENSE (Apache-2.0; weights/mobile_sam.pt is in the same tree and the README names no other terms); the same file from a co-author: https://huggingface.co/dhkim2810/MobileSAM/blob/4e2e5245fe9dc63096d575d36e70eb39b03b3aba/README.md (license: mit); TinyViT: https://github.com/microsoft/Cream/blob/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/LICENSE | |
| ## Input size | |
| any H x W >= 1, resized inside to the fixed encoder input 1024x1024 (the default export size) | |
| Tested up to (portable, fp16, RTX 5060 Ti 16 GB): `mobile-sam` 1080x1920 (0.2 GiB peak allocated, 0.2 reserved) | |
| ## Speed and memory | |
| ### Promptable segmentation, synthetic, 1024x1024 | |
| | model | time (ms): original fp32 | original | portable | kernels | kernels speed-up: vs original | vs portable | peak memory (MiB, allocated / reserved): original | portable | kernels | | |
| | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | |
| | `mobile-sam` | 30.3 | 23.5 | 10.5 | 6.86 | 3.4x | 1.5x | 207 / 286 | 183 / 210 | 215 / 296 | | |
| ### Startup and first call | |
| | model | load (s): original | portable | kernels | first call (s): original | portable | kernels | | |
| | --- | --- | --- | --- | --- | --- | --- | | |
| | `mobile-sam` | 0.21 | 0.71 | 1.60 | 1.01 | 0.47 | 0.29 | | |
| ### torch.compile and TensorRT | |
| | model | input | time: portable | compile | TensorRT fp16 | kernels | preparation: compile (cold first call) | ONNX + engine build | peak MiB (alloc / reserved): portable | compile | kernels | TensorRT (engine + torch) | | |
| | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | |
| | `mobile-sam` | 1024x1024 | 10.5 ms | 6.22 ms | 4.99 ms (image encoder only) | 6.86 ms | 25.5 s | 60.9 s | 183 / 210 | 203 / 232 | 215 / 296 | 219 / 252 | | |
| Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB). | |
| Hardware, protocol and caveats: [benchmarks](https://github.com/kleinicke/fastforks/blob/main/docs/benchmarks.md) (RTX 5060 Ti 16 GB, sm_120). Original = the original code named above at the precision of portable (fp16, or `(fp32)` where fp16 is unsupported or not finite); original fp32 = its default fp32 run. Peak memory is the torch allocator's. | |
| ## Accuracy | |
| ### On public datasets | |
| One point per ground-truth instance (the interior point farthest from the border); IoU of the best-scored of 3 masks / of the single mask. Original = the original code named under Details, same checkpoint and protocol. | |
| | variant | dataset | original fp32 | original fp16 | portable | kernels | note | | |
| |---|---|---|---|---|---|---| | |
| | `mobile-sam` | COCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask % | 51.53 / 49.90 | 51.48 / 49.91 | 51.53 / 49.91 | 51.53 / 49.91 | | | |
| Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 5eafe838+dirty, 2026-11-10. | |
| ### Parity with the original code | |
| Every variant is checked against reference outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 0.0013 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.81 % and p99 <= 4.1 % of the reference's median |value| (absolute error of the output `pred_masks`). | |
| ## Usage | |
| ```python | |
| from fastforks import promptable_segmentation | |
| model = promptable_segmentation.load("mobile-sam") # mode="auto": the preferred backend from recorded measurements | |
| result = model("photo.jpg", input_points=[[x, y]], input_labels=[1]) | |
| result.masks # [M, H, W] bool | |
| # SAM 3 (text prompts): model("photo.jpg", text="coin") -> boxes, scores, masks | |
| result.backend # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16') | |
| ``` | |
| Install with `pip install fastforks` (see <https://github.com/kleinicke/fastforks>). Other variants: `mobile-sam`. | |
| ## Kernels backend | |
| `promptable_segmentation.load("mobile-sam", mode="kernels")` runs our CUDA kernels (`fvm_conv`, `fvm_extra`, `fvm_mb`, `fvm_r3`). It needs a prebuilt kernel for your GPU architecture (downloaded from <https://huggingface.co/fastforks/kernels> on first use) and a recent NVIDIA driver; if there is none it raises `BackendUnavailableError` with the reason and never falls back silently. `mode="auto"` picks `kernels` when it can run and logs the choice. | |
| <!-- staged from fastforks 1cbf1671 (2026-11-15) --> | |