Commit Β·
ba6c3fe
0
Parent(s):
fastforks 0.1.0
Browse files- .gitattributes +35 -0
- README.md +114 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
---
|
| 13 |
+
# Segment Anything 2.1 (SAM 2.1), image (fastforks)
|
| 14 |
+
|
| 15 |
+
Segment Anything 2.1 (Ravi et al. 2024), image mode: promptable segmentation with a hierarchical Hiera image encoder, an FPN neck and the SAM prompt encoder / mask decoder with high-resolution skip features; masks from points, boxes and mask logits (no video memory). The portable `module()` is the image encoder only.
|
| 16 |
+
|
| 17 |
+
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/facebookresearch/sam2> at `2b90b9f`.
|
| 18 |
+
|
| 19 |
+
Task: promptable_segmentation. Tier: stable. Outputs: `pred_masks`, `iou_scores`. Backends: `portable`, `kernels`.
|
| 20 |
+
|
| 21 |
+
Input: one image plus a point, box or text prompt. Output: masks with quality scores.
|
| 22 |
+
|
| 23 |
+
## Variants
|
| 24 |
+
|
| 25 |
+
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/sam2/card.toml).
|
| 26 |
+
|
| 27 |
+
| variant | weights (author link) | SHA-256 | weights licence | commercial use |
|
| 28 |
+
|---|---|---|---|---|
|
| 29 |
+
| `sam2.1-hiera-base-plus@1` | [sam2.1_hiera_base_plus.pt](https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_base_plus.pt) | `a2345aede871` | Apache-2.0 | yes |
|
| 30 |
+
| `sam2.1-hiera-large@1` | [sam2.1_hiera_large.pt](https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_large.pt) | `2647878d5dfa` | Apache-2.0 | yes |
|
| 31 |
+
| `sam2.1-hiera-small@1` | [sam2.1_hiera_small.pt](https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_small.pt) | `6d1aa6f30de5` | Apache-2.0 | yes |
|
| 32 |
+
| `sam2.1-hiera-tiny@1` | [sam2.1_hiera_tiny.pt](https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_tiny.pt) | `7402e0d864fa` | Apache-2.0 | yes |
|
| 33 |
+
|
| 34 |
+
## Licence
|
| 35 |
+
|
| 36 |
+
Original-code strings, recorded as they are (research-use package; check them before any other use). Code: Apache-2.0. Files: `LICENSE`.
|
| 37 |
+
|
| 38 |
+
Training data: SA-1B and the SA-V video dataset (plus internal data) per the paper; SA-V itself is under CC BY 4.0, SA-1B under its research licence.
|
| 39 |
+
|
| 40 |
+
Licence evidence: https://github.com/facebookresearch/sam2/blob/main/README.md (License section: model checkpoints and code under Apache 2.0)
|
| 41 |
+
|
| 42 |
+
## Input size
|
| 43 |
+
|
| 44 |
+
any H x W >= 1, resized inside to the fixed encoder input 1024x1024 (the default export size)
|
| 45 |
+
Tested up to (portable, fp16, RTX 5060 Ti 16 GB): `sam2.1-hiera-base-plus` 1080x1920 (0.4 GiB peak allocated, 0.6 reserved); `sam2.1-hiera-large` 1080x1920 (0.7 GiB peak allocated, 0.9 reserved); `sam2.1-hiera-small` 1080x1920 (0.3 GiB peak allocated, 0.4 reserved); `sam2.1-hiera-tiny` 1080x1920 (0.3 GiB peak allocated, 0.4 reserved)
|
| 46 |
+
|
| 47 |
+
## Speed and memory
|
| 48 |
+
|
| 49 |
+
### Promptable segmentation, synthetic, 1024x1024
|
| 50 |
+
|
| 51 |
+
| model | time (ms): original fp32 | original | portable | kernels | kernels speed-up: vs original | vs portable | peak memory (MiB, allocated / reserved): original | portable | kernels |
|
| 52 |
+
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
| 53 |
+
| `sam2.1-hiera-base-plus` | 102 | β | 32.0 | 25.1 | β | 1.3x | β | 412 / 464 | 426 / 524 |
|
| 54 |
+
| `sam2.1-hiera-large` | 243 | β | 68.0 | 48.8 | β | 1.4x | β | 742 / 768 | 760 / 828 |
|
| 55 |
+
| `sam2.1-hiera-small` | 68.5 | β | 18.8 | 15.6 | β | 1.2x | β | 318 / 366 | 330 / 386 |
|
| 56 |
+
| `sam2.1-hiera-tiny` | 61.3 | β | 16.6 | 13.9 | β | 1.2x | β | 304 / 382 | 316 / 362 |
|
| 57 |
+
|
| 58 |
+
### Startup and first call
|
| 59 |
+
|
| 60 |
+
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
|
| 61 |
+
| --- | --- | --- | --- | --- | --- | --- |
|
| 62 |
+
| `sam2.1-hiera-base-plus` | 0.53 | 0.43 | 0.19β | 0.10 | 0.03β | 0.03β |
|
| 63 |
+
| `sam2.1-hiera-large` | 2.92 | 1.10 | 0.39β | 0.24 | 0.07β | 0.05β |
|
| 64 |
+
| `sam2.1-hiera-small` | 0.32 | 0.36 | 0.13β | 0.07 | 0.02β | 0.02β |
|
| 65 |
+
| `sam2.1-hiera-tiny` | 0.41 | 0.25 | 0.11β | 0.13 | 0.02β | 0.01β |
|
| 66 |
+
|
| 67 |
+
### torch.compile and TensorRT
|
| 68 |
+
|
| 69 |
+
| model | input | portable ms | compile ms | compile s (cold) | TensorRT fp16 ms | ONNX + build s | kernels ms | peak MiB (alloc / reserved): portable | compile | TensorRT (device) |
|
| 70 |
+
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
| 71 |
+
| `sam2.1-hiera-tiny` | 1024x1024 | 16.6 | 14.2 | 13.4 | 8.6 | 34 | 13.9 | 304 / 382 | 270 / 322 | 266 |
|
| 72 |
+
|
| 73 |
+
### Fixed-size speed and peak memory, all models
|
| 74 |
+
|
| 75 |
+
| model | mode | 480x640 | 720x1280 | 1080x1920 | 12 MP 3000x4000 |
|
| 76 |
+
| --- | --- | --- | --- | --- | --- |
|
| 77 |
+
| `sam2.1-hiera-base-plus` | portable | 32.0 ms / 395 / 540 | 31.9 ms / 402 / 558 | 32.1 ms / 415 / 568 | - |
|
| 78 |
+
| `sam2.1-hiera-base-plus` | kernels | 25.1 ms / 408 / 472 | 25.1 ms / 415 / 490 | 25.3 ms / 428 / 472 | - |
|
| 79 |
+
| `sam2.1-hiera-large` | portable | 68.2 ms / 724 / 936 | 68.6 ms / 732 / 948 | 68.3 ms / 745 / 954 | - |
|
| 80 |
+
| `sam2.1-hiera-large` | kernels | 48.7 ms / 742 / 824 | 48.7 ms / 750 / 836 | 49.0 ms / 763 / 842 | - |
|
| 81 |
+
| `sam2.1-hiera-small` | portable | 18.7 ms / 298 / 420 | 19.1 ms / 305 / 422 | 18.9 ms / 319 / 426 | - |
|
| 82 |
+
| `sam2.1-hiera-small` | kernels | 15.4 ms / 310 / 356 | 15.5 ms / 317 / 358 | 15.6 ms / 331 / 346 | - |
|
| 83 |
+
| `sam2.1-hiera-tiny` | portable | 16.7 ms / 285 / 410 | 16.6 ms / 292 / 410 | 16.8 ms / 305 / 426 | - |
|
| 84 |
+
| `sam2.1-hiera-tiny` | kernels | 13.8 ms / 296 / 346 | 13.8 ms / 304 / 346 | 14.0 ms / 317 / 346 | - |
|
| 85 |
+
|
| 86 |
+
Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).
|
| 87 |
+
|
| 88 |
+
Hardware, protocol and caveats: [benchmarks](https://github.com/kleinicke/fastforks/blob/main/docs/benchmarks.md) (RTX 5060 Ti 16 GB, sm_120). Original = the authors' code 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.
|
| 89 |
+
|
| 90 |
+
## Accuracy
|
| 91 |
+
|
| 92 |
+
### Parity with the original code
|
| 93 |
+
|
| 94 |
+
Every variant is checked against reference outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 3 % and p99 <= 15 % of the reference's median |value| (absolute error of the output `pred_masks`).
|
| 95 |
+
|
| 96 |
+
## Usage
|
| 97 |
+
|
| 98 |
+
```python
|
| 99 |
+
from fastforks import promptable_segmentation
|
| 100 |
+
|
| 101 |
+
model = promptable_segmentation.load("sam2.1-hiera-base-plus") # mode="auto": the preferred backend from recorded measurements
|
| 102 |
+
result = model("photo.jpg", input_points=[[x, y]], input_labels=[1])
|
| 103 |
+
result.masks # [M, H, W] bool
|
| 104 |
+
# SAM 3 (text prompts): model("photo.jpg", text="coin") -> boxes, scores, masks
|
| 105 |
+
result.backend # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16')
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
Install with `pip install fastforks` (see <https://github.com/kleinicke/fastforks>). Other variants: `sam2.1-hiera-base-plus`, `sam2.1-hiera-large`, `sam2.1-hiera-small`, `sam2.1-hiera-tiny`.
|
| 109 |
+
|
| 110 |
+
## Kernels backend
|
| 111 |
+
|
| 112 |
+
`promptable_segmentation.load("sam2.1-hiera-base-plus", mode="kernels")` runs our CUDA kernels (`dpt_fused`). 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.
|
| 113 |
+
|
| 114 |
+
<!-- staged from fastforks feccac41 (2026-11-06) -->
|