Flor commited on
Commit
4d52b0c
·
verified ·
1 Parent(s): dedf970

card: update from fastforks 1cbf1671

Browse files
Files changed (1) hide show
  1. README.md +103 -0
README.md ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: "fastforks"
3
+ pipeline_tag: "mask-generation"
4
+ license: "apache-2.0"
5
+ tags:
6
+ - "promptable_segmentation"
7
+ - "segment-anything"
8
+ - "promptable-segmentation"
9
+ - "cuda"
10
+ - "pytorch"
11
+ - "fastforks"
12
+ - "fastforks-card"
13
+ ---
14
+ # MobileSAM (fastforks)
15
+
16
+ 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.
17
+
18
+ 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`.
19
+
20
+ Task: promptable_segmentation. Tier: experimental. Outputs: `pred_masks`, `iou_scores`. Backends: `portable`, `kernels`.
21
+
22
+ Input: one image plus a point, box or text prompt. Output: masks with quality scores.
23
+
24
+ ## Variants
25
+
26
+ 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).
27
+
28
+ | variant | weights (author link) | SHA-256 | weights licence | commercial use |
29
+ |---|---|---|---|---|
30
+ | `mobile-sam@1` | [mobile_sam.pt](https://github.com/ChaoningZhang/MobileSAM/raw/f706ad9c4eb7f219c00d9050e46328518ffb65d2/weights/mobile_sam.pt) | `6dbb90523a35` | Apache-2.0 | yes |
31
+
32
+ ## Licence
33
+
34
+ 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`.
35
+
36
+ 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.
37
+
38
+ 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
39
+
40
+ ## Input size
41
+
42
+ any H x W >= 1, resized inside to the fixed encoder input 1024x1024 (the default export size)
43
+ Tested up to (portable, fp16, RTX 5060 Ti 16 GB): `mobile-sam` 1080x1920 (0.2 GiB peak allocated, 0.2 reserved)
44
+
45
+ ## Speed and memory
46
+
47
+ ### Promptable segmentation, synthetic, 1024x1024
48
+
49
+ | model | time (ms): original fp32 | original | portable | kernels | kernels speed-up: vs original | vs portable | peak memory (MiB, allocated / reserved): original | portable | kernels |
50
+ | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
51
+ | `mobile-sam` | 30.3 | 23.5 | 10.5 | 6.86 | 3.4x | 1.5x | 207 / 286 | 183 / 210 | 215 / 296 |
52
+
53
+ ### Startup and first call
54
+
55
+ | model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
56
+ | --- | --- | --- | --- | --- | --- | --- |
57
+ | `mobile-sam` | 0.21 | 0.71 | 1.60 | 1.01 | 0.47 | 0.29 |
58
+
59
+ ### torch.compile and TensorRT
60
+
61
+ | 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) |
62
+ | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
63
+ | `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 |
64
+
65
+ Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).
66
+
67
+ 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.
68
+
69
+ ## Accuracy
70
+
71
+ ### On public datasets
72
+
73
+ 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.
74
+
75
+ | variant | dataset | original fp32 | original fp16 | portable | kernels | note |
76
+ |---|---|---|---|---|---|---|
77
+ | `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 | |
78
+
79
+ Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 5eafe838+dirty, 2026-11-10.
80
+
81
+ ### Parity with the original code
82
+
83
+ 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`).
84
+
85
+ ## Usage
86
+
87
+ ```python
88
+ from fastforks import promptable_segmentation
89
+
90
+ model = promptable_segmentation.load("mobile-sam") # mode="auto": the preferred backend from recorded measurements
91
+ result = model("photo.jpg", input_points=[[x, y]], input_labels=[1])
92
+ result.masks # [M, H, W] bool
93
+ # SAM 3 (text prompts): model("photo.jpg", text="coin") -> boxes, scores, masks
94
+ result.backend # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16')
95
+ ```
96
+
97
+ Install with `pip install fastforks` (see <https://github.com/kleinicke/fastforks>). Other variants: `mobile-sam`.
98
+
99
+ ## Kernels backend
100
+
101
+ `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.
102
+
103
+ <!-- staged from fastforks 1cbf1671 (2026-11-15) -->