InSPyReNet
InSPyReNet (Kim et al., ACCV 2022) as transparent-background ships it: cuts the foreground out of a photo as a soft mask at 1024 x 1024 (384 x 384 fast); a Swin-B encoder with an image-pyramid decoder. MIT code and weights.
experimental Fork of plemeri/transparent-background@f0fa917 · backends: portable, kernels
- Paper Revisiting Image Pyramid Structure for High Resolution Salient Object Detection ACCV 2022 · first released 20 Sept 2022
- Authors’ code plemeri/InSPyReNet (PyTorch), not the code forked here: fastforks follows the authors' transparent-background package, which ships the released InSPyReNet weights (Plus_Ultra) and the inference call that ComfyUI nodes use, rather than the research repository.
Paper 2022 Added in 0.2.0 Evaluated with 0.2.0
Use it
pip install fastforks Lean install with only what this model needs: pip install fastforks-core
from fastforks import matting
model = matting.load("inspyrenet") # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.alpha
result.backend # what ran: mode, device, dtype, kernels fastforks bench inspyrenet Times the model on this machine. load(…, mode="portable") or mode="kernels" picks a backend; usage guide.
Speed and memory
Every backend on one GPU (RTX 5060 Ti 16 GB) and the same input, the authors’ code included. Kernels runs fp16. Portable runs fp16 on CUDA.
Input: synthetic, 1080x1920 (the task’s standard size)
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | not measured | – | – | – | – |
| Original (own default)plemeri/transparent-background@f0fa91701a98, float pre- and post-processing | fp32 | 241 | – | 3,240 MiB/3,262 MiB | 6.7 | 1.49 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 109 | 2.2× | 1,649 MiB/1,848 MiB | 0.8 | 0.63 |
| Kernels | not measured | – | – | – | – | |
| Portable + torch.compile | 85.8 | 2.8× | 913 MiB/1,018 MiB | 71 (build) | – | |
| TensorRT fp16 | fp16 | 51.1 | 4.7× | 904 MiBenginenot comparable | 133 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-13 to 2026-11-14. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5. Ratios divide two
times of this table (same GPU, same input). Original fp16 is the authors’ own precision option, else torch.autocast. torch.compile and TensorRT: build time instead of load time. TensorRT memory (engine, not comparable) is the GPU memory the engine took, read from the driver because TensorRT allocates outside PyTorch, so it can't be compared with the PyTorch peaks of the other rows.
Other devices
| Device | Backend | dtype | ms / call | Peak memory | Output vs reference | Input |
|---|---|---|---|---|---|---|
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14 | Original | fp32 | 864 | 7,535 MiB process | – | 1080x1920 |
| Portable | fp16 | 702 | 4,172 MiB process | matches | 1080x1920 | |
| Portable | fp32 | 1108 | 7,284 MiB process | matches | 1080x1920 | |
| Kernels | fp32 | not implemented | – | 1080x1920 | ||
CUDA memory is torch’s peak allocated / reserved; Apple has no such counter, so the Mac rows show the process footprint (weights, Python and torch included). “Output vs reference” compares the device’s output with the stored golden output under the card’s tolerance; – = not checked on that device. Kernels “not implemented” = no kernels for this model on that backend yet: it runs portable there.
Licence and weights
Commercial use allowed
- Code
- MIT LICENSE
- Weights
- MIT source
- Training data
-
- DUTS (salient object detection) not stated
- HRSOD (high-resolution salient object detection) not stated
- UHRSD (ultra-high-resolution salient object detection) not stated
- DIS5K (dichotomous image segmentation) noncommercial, non-commercial
Our reading of the licences, not legal advice.
Weights
ckpt_base.pth 368 MB· hosted on GitHubfastforks downloads and checks these files on first use (fastforks download inspyrenet).
Accuracy
The test set through the authors’ code and through ours: same checkpoint, same protocol. The distance between the original’s fp32 and fp16 runs is what half precision alone costs; our runs should stay within it.
DIS5K validation (DIS-VD)
every 2nd image (235), MAE / max F-beta
| Run | dtype | mae ↑ | max_fbeta ↑ | Δ mae vs fp32 original | images | ms / image |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 0.0129 | 0.9699 | reference | 235 | 242 |
| Original fp16 | not measured | |||||
| Portable fp32 | fp32 | 0.0129 | 0.9699 | ±0.0000 | 235 | 257 |
| Portable | fp16 | 0.0129 | 0.9699 | ±0.0000 | 235 | 162 |
| Kernels | not measured | |||||
Each image at its own size against its binary mask: MAE of the alpha, max F-beta (beta^2 = 0.3) over 256 thresholds (BiRefNet's evaluation). Original = the authors’ code, same checkpoint and protocol. Measured on original fp32: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13; portable fp32, portable: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 45a5c91f, 2026-11-13.
Closeness to the original
Beyond the test-set scores: the raw output of ours against the original’s fp32 output on the same input, pixel by pixel. CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.02 and p99 <= 0.25 (absolute error of the output alpha).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.002 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.02 | 0.00003 |
| GPU default dtypes, p99 |diff| | ≤ 0.25 | 0.00067 |
Recorded for inspyrenet on RTX 5060 Ti, torch 2.10.0+cu130, 2026-11-17, with these kernels: image_normalize
Details
InSPyReNet (Kim et al., ACCV 2022): salient object detection with an inverse saliency pyramid: a Swin-B encoder, pyramid attention context modules and scale-invariant context attention that reconstruct the saliency map from a coarse map plus Laplacian residuals. The `transparent-background` models ComfyUI's InSPyReNet nodes run: `inspyrenet` (base, 1024 x 1024) and `inspyrenet-fast` (384 x 384), both trained on the authors' extra-data mix (Plus Ultra).
- Input / output
- Input: one RGB image (trimap-guided models also a trimap: background / unknown / foreground). Output: an alpha matte
[H, W]in [0, 1] at the input size: 1 = foreground (background removal, dichotomous / salient object segmentation). - Input size
- any H x W >= 32, padded to a multiple of 32; tested up to 3000x4000 (2,024 MiB allocated)
- Outputs
alpha- CUDA kernels
image_normalize
- Apple (MPS)
- fp32, fp16
Full reference, generated from the repository
InSPyReNet (Kim et al., ACCV 2022) as transparent-background ships it: cuts the foreground out of a photo as a soft mask at 1024 x 1024 (384 x 384 fast); a Swin-B encoder with an image-pyramid decoder. MIT code and weights.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
inspyrenet | synthetic (1080x1920) | original portable kernels portable + torch.compile TensorRT fp16 | 241 109 – 85.8 51.1 | 3240 / 3262 1649 / 1848 – 913 / 1018 1181 / 1252 |
inspyrenet-fast | synthetic (1080x1920) | original portable kernels portable + torch.compile TensorRT fp16 | 71.1 41.7 – 17.7 6.99 | 810 / 836 432 / 488 – 345 / 376 561 / 600 |
Details
- Original code: https://github.com/plemeri/transparent-background at
f0fa91701a98 - Code licence: MIT (permissive); files:
LICENSE - Weights licence: MIT
- Licence evidence: https://github.com/plemeri/transparent-background/blob/f0fa91701a98cfc8e955c554e84522f365ec6da3/LICENSE ; https://github.com/plemeri/transparent-background/releases/tag/1.2.12 ; https://github.com/plemeri/InSPyReNet/blob/692ad8a5774cf95ef615a730d5070aad18f6b160/docs/model_zoo.md
- Training data: DUTS (salient object detection), HRSOD (high-resolution salient object detection), UHRSD (ultra-high-resolution salient object detection), DIS5K (dichotomous image segmentation) (plemeri/InSPyReNet docs/model_zoo.md, Plus_Ultra(_LR): DUTS-TR/TE, HRSOD-TR/TE, UHRSD-TR/TE, DIS-TR/VD/TE1-4, DUT-OMRON, ECSSD, HKU-IS, PASCAL-S, DAVIS-S, FSS-1000, MSRA-10K (all test sets included, so benchmark numbers on them are not held out). Swin-B backbone from ImageNet-22k -> 1k.)
- Kernel libraries:
image_normalize - Variants:
inspyrenet,inspyrenet-fast - Outputs: alpha
- Input size: any H x W >= 32, padded to a multiple of 32
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
inspyrenet3000x4000 (2.0 GiB peak allocated, 2.4 reserved);inspyrenet-fast3000x4000 (0.9 GiB peak allocated, 1.0 reserved) inspyrenet1080x1920, first call: portable + torch.compile 71 s (cold Inductor cache), TensorRT fp16 133 s (ONNX + engine).inspyrenet-fast1080x1920, first call: portable + torch.compile 77 s (cold Inductor cache), TensorRT fp16 138 s (ONNX + engine).inspyrenetoriginal 1080x1920: plemeri/transparent-background@f0fa91701a98, float pre- and post-processinginspyrenet-fastoriginal 1080x1920: plemeri/transparent-background@f0fa91701a98, float pre- and post-processinginspyrenetload / first call: original 6.68 s / 1.487 s, portable 0.78 s / 0.625 sinspyrenet-fastload / first call: original 5.93 s / 1.329 s, portable 11.07 s / 0.794 s- Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5
Measured
Each image at its own size against its binary mask: MAE of the alpha, max F-beta (beta^2 = 0.3) over 256 thresholds (BiRefNet's evaluation). Original = the original code named under Details, same checkpoint and protocol.
| variant | dataset | original fp32 | portable | portable fp32 | note |
|---|---|---|---|---|---|
inspyrenet | DIS5K validation (DIS-VD), every 2nd image (235), MAE / max F-beta | 0.0129 / 0.9699 | 0.0129 / 0.9699 | 0.0129 / 0.9699 | |
inspyrenet-fast | DIS5K validation (DIS-VD), every 2nd image (235), MAE / max F-beta | 0.0420 / 0.8952 | 0.0420 / 0.8952 | 0.0420 / 0.8952 |
Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 45a5c91f, 2026-11-13.
Parity
CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.02 and p99 <= 0.25 (absolute error of the output alpha).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
inspyrenet | 3e-05 / 0.00067 | RTX 5060 Ti, torch 2.10.0+cu130 | image_normalize@592f5511307a:sm_120 |
inspyrenet-fast | 1e-05 / 0.00029 | RTX 5060 Ti, torch 2.10.0+cu130 | image_normalize@592f5511307a:sm_120 |
Example output
No example rendered for this checkpoint yet.