HQ-SAM (fastforks)
Segment Anything in High Quality (Ke et al. 2023): SAM with one more output token and a small head that fuses the final embedding with an early ViT feature, for sharper mask borders and thin structures; SAM's weights are frozen, so prompts work the same. Each prompt gives one mask (SAM's mask plus the HQ mask, upstream's default); multimask_output picks the best-scored of SAM's three candidates as the SAM part. The portable module() is the image side only (embedding and HQ feature).
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/SysCV/sam-hq at e696978d6035.
Author weight repos: https://huggingface.co/lkeab/hq-sam.
Task: promptable_segmentation. Tier: stable. 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.
| variant | weights (author link) | SHA-256 | weights licence | commercial use |
|---|---|---|---|---|
sam-hq-vit-b@1 |
sam_hq_vit_b.pth | 14a9d662cd6f |
Apache-2.0 | yes |
sam-hq-vit-h@1 |
sam_hq_vit_h.pth | a7ac14a08532 |
Apache-2.0 | yes |
sam-hq-vit-l@1 |
sam_hq_vit_l.pth | e1a6c385d62b |
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. Licence files: LICENSE.
Training data: the HQ head is trained on HQSeg-44K (six existing fine-mask datasets, per the paper; their terms were not checked) on top of SAM's frozen weights (SA-1B, under the SA-1B research licence).
Licence evidence: https://huggingface.co/lkeab/hq-sam/blob/09b02a333b37772133eff3997bdba997867374b7/README.md (license: apache-2.0); code: https://github.com/SysCV/sam-hq/blob/e696978d60352dc9a26b12631cd91781502c6546/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): sam-hq-vit-b 1080x1920 (0.4 GiB peak allocated, 0.5 reserved); sam-hq-vit-h 1080x1920 (1.5 GiB peak allocated, 1.9 reserved); sam-hq-vit-l 1080x1920 (0.8 GiB peak allocated, 1.1 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 |
|---|---|---|---|---|---|---|---|---|---|
sam-hq-vit-b |
172 | 103 | 49.7 | 36.8 | 2.8x | 1.4x | 1704 / 1756 | 388 / 422 | 433 / 564 |
sam-hq-vit-h |
738 | 311 | 217 | 144 | 2.2x | 1.5x | 4266 / 4318 | 1500 / 1566 | 1541 / 1708 |
sam-hq-vit-l |
412 | 202 | 118 | 81.4 | 2.5x | 1.4x | 2969 / 3018 | 846 / 902 | 889 / 1046 |
Startup and first call
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
|---|---|---|---|---|---|---|
sam-hq-vit-b |
0.77 | 0.27 | 1.06 | 0.19 | 0.41 | 0.35 |
sam-hq-vit-h |
3.92 | 1.34 | 2.29 | 0.32 | 0.52 | 0.47 |
sam-hq-vit-l |
1.98 | 0.76 | 1.64 | 0.20 | 0.41 | 0.40 |
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) |
|---|---|---|---|---|---|---|---|---|---|---|---|
sam-hq-vit-b |
1024x1024 | 49.7 ms | 39.4 ms | 28.0 ms (image encoder only) | 36.8 ms | 32.8 s | 39.0 s | 388 / 422 | 372 / 422 | 433 / 564 | 609 / 642 |
sam-hq-vit-h |
1024x1024 | 217 ms | 187 ms | 125 ms (image encoder only) | 144 ms | 42.3 s | 69.1 s | 1500 / 1566 | 1476 / 1526 | 1541 / 1708 | 2790 / 2818 |
sam-hq-vit-l |
1024x1024 | 118 ms | 97.0 ms | 68.3 ms (image encoder only) | 81.4 ms | 32.9 s | 53.3 s | 846 / 902 | 822 / 902 | 889 / 1046 | 1482 / 1538 |
Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).
Hardware, protocol and caveats: benchmarks (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 |
|---|---|---|---|---|---|---|
sam-hq-vit-b |
COCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask % | 52.19 / 51.05 | 52.28 / 51.11 | 52.19 / 51.04 | 52.19 / 51.04 | |
sam-hq-vit-l |
COCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask % | 56.04 / 52.52 | 56.00 / 52.53 | 56.09 / 52.52 | 56.08 / 52.52 | |
sam-hq-vit-h |
COCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask % | 56.15 / 53.43 | 56.09 / 53.45 | 56.16 / 53.43 | 56.14 / 53.43 |
Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks f2992269, 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.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.43 % and p99 <= 1.7 % of the reference's median |value| (absolute error of the output pred_masks).
Usage
from fastforks import promptable_segmentation
model = promptable_segmentation.load("sam-hq-vit-b") # 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: sam-hq-vit-b, sam-hq-vit-h, sam-hq-vit-l.
Kernels backend
promptable_segmentation.load("sam-hq-vit-b", 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.