Mask2Former (fastforks)

Mask2Former (Cheng et al. 2022): Swin backbone, multi-scale deformable attention pixel decoder and a masked-attention transformer decoder; semantic logits from mask classification.

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/huggingface/transformers at c4c4605f9618.

Author weight repos: https://huggingface.co/facebook/mask2former-swin-large-ade-semantic.

Task: segmentation. Tier: stable. Outputs: logits. Backends: portable, kernels.

Input: one RGB image. Output: per-pixel class logits.

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
mask2former-swinl-ade20k@1 mask2former-swinl-ade20k.config.json
mask2former-swinl-ade20k.safetensors
573b9330846e
b143c144341c
CC-BY-NC-4.0 no

Licence

Original-code strings, recorded as they are (research-use package; check them before any other use). Code: Apache-2.0. Files: .

Training data: ImageNet-21k / ImageNet-22k (full ImageNet, fall 2011 release), ADE20K (SceneParsing, 150 classes).

Licence evidence: https://github.com/facebookresearch/Mask2Former/blob/9b0651c6c1d5b3af2e6da0589b719c514ec0d69a/MODEL_ZOO.md#license

Input size

any H x W >= 1, resized or padded inside the model Tested up to (portable, fp16, RTX 5060 Ti 16 GB): mask2former-swinl-ade20k 3000x4000 (14.1 GiB peak allocated, 15.1 reserved)

Speed and memory

Segmentation, synthetic, 1024x2048

model time (ms): original fp32 original portable kernels kernels speed-up: vs original vs portable peak memory (MiB, allocated / reserved): original portable kernels
mask2former-swinl-ade20k 244.17 144.79 103.88 60.44 2.4x 1.7x 3572 / 3878 1374 / 1660 1164 / 1400

Startup and first call

model load (s): original portable kernels first call (s): original portable kernels
mask2former-swinl-ade20k 4.86 (512x512) 3.21 3.17โ€  0.76 (512x512) 0.12โ€  0.07โ€ 

Fixed-size speed and peak memory, all models

model mode 640x480 1280x720 1920x1080 12 MP 4000x3000
mask2former-swinl-ade20k portable 71.9 ms / 1194 / 1912 96.1 ms / 1698 / 3182 104.1 ms / 2985 / 4500 152.8 ms / 14457 / 15480
mask2former-swinl-ade20k kernels 45.3 ms / 1194 / 1816 60.5 ms / 1699 / 3056 68.5 ms / 2986 / 4374 126.0 ms / 14457 / 15344

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 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.

Accuracy

Parity with the original code

Every variant is checked against golden 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.001 px and p99 <= 0.01 px.

Usage

from fastforks import segmentation

model = segmentation.load("mask2former-swinl-ade20k")  # portable PyTorch on the GPU if there is one, else the CPU
result = model("photo.jpg")
result.labels  # [H, W] per-pixel class index
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: mask2former-swinl-ade20k.

Kernels backend

segmentation.load("mask2former-swinl-ade20k", mode="kernels") runs our CUDA kernels (fvm_seg, seg_up). 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.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support