Semantic segmentation
SegFormer-B0 (ADE20K)
Labels every pixel of a scene with one of 150 classes: sky, road, wall, person, tree and more. Small and fast. NVIDIA license, non-commercial.
About this model
SegFormer-B0 reads a whole scene and gives every pixel a class among the 150 of ADE20K: stuff like sky, road, grass, wall and water, and things like people, cars, chairs and boats. Unlike instance segmentation, all cars share one class and are not told apart.
B0 is the smallest SegFormer: a 3.7 million parameter transformer encoder with a light all-MLP decoder, trained by NVIDIA on ADE20K at 512 x 512.
What you can build
- Understand the layout of a scene: where the floor, walls and sky are
- Replace or blur the sky or background
- Estimate how much of a view is road, vegetation or water
- Give robots or AR apps a coarse map of surfaces
Parking lot cars
f16Roc0ast3r, CC0, https://commons.wikimedia.org/wiki/File:Cars_in_a_parking_lot_across_a_road_(2024)_-_0743.jpg
Largest classes on the Metal (FP16 pack), share of the photo: sky 43.0% road 24.0% mountain 14.0% sidewalk 5.8% car 5.5% building 2.6% rock 1.5% sand 1.4%
Harbor boats
f16W.carter, Public domain, https://commons.wikimedia.org/wiki/File:North_Harbor_Lysekil_with_motor_boat.jpg
Largest classes on the Metal (FP16 pack), share of the photo: water 40.8% sky 24.7% mountain 12.9% pier 7.3% bridge 6.3% railing 5.7% boat 1.6% person 0.4%
Suspension bridge
f16Derek Jensen (Tysto), Public domain, https://commons.wikimedia.org/wiki/File:Cincinnati-roebling-suspension-bridge.jpg
Largest classes on the Metal (FP16 pack), share of the photo: sky 40.2% bridge 36.6% water 16.1% building 2.5% tree 2.1% earth 1.9% grass 0.6% streetlight 0.1%
Variants & downloads
Choose the build for your appModel files are hosted on Google Drive. Large files may open a confirmation page before downloading.
Standard
SlabWeights stored in FP16: half the size of FP32, the same results (see Accuracy).
Platforms: macos · android
segformer-b0-ade-f16.slab
10.6 MB · Hosted download
SHA-256 checksum
57f72c1f80db984b657efc603e7bd2dda4615af8834df4cc3b217f460f40081bLICENSE-SegFormer.txt
4 KB
SHA-256 checksum
f549820c06519e3105e5174a2fd7285224ffd2268a7f879a843b1a255fd04a61Conversion details
- command
- python -c "import torch; from transformers import SegformerForSemanticSegmentation as S; m = S.from_pretrained('nvidia/segformer-b0-finetuned-ade-512-512', revision='489d5cd81a0b59fab9b7ea758d3548ebe99677da').eval(); W = type('W', (torch.nn.Module,), {'forward': lambda s, x: s.m(pixel_values=x).logits}); w = W(); w.m = m; torch.onnx.export(w,torch.randn(1, 3, 512, 512), 'model.onnx', input_names=['pixel_values'], output_names=['logits'], opset_version=17, dynamo=False); open('labels.txt', 'w').write('\n'.join(m.config.id2label[i] for i in range(150)))" slab-load convert model.onnx model.slab --input pixel_values=1x3x512x512 --meta task=segment --meta resize=stretch --meta interpolation=bilinear --meta antialias:bool=true --meta normalize=imagenet --meta color=rgb --meta labels:labels=@labels.txt slab-load quantize model.slab segformer-b0-ade-f16.slab --f16 slab-load meta set segformer-b0-ade-f16.slab default_backend.macos=gpu
Integration examples
Python
python
import slab
cfg = slab.Config(cache_dir="/tmp/slab_cache", license=open("license.slablic.txt").read())
session = slab.Session(cfg, "segformer-b0-ade-f16.slab", warmup=True)
photo = slab.Frame.open("photo.jpg")
out = session.run(slab.Input(frame=photo))
seg = out.class_map() # Gray8 Frame, the photo's size
print(out.label(seg[10, 10])) # the class at row 10, column 10, e.g. "sky"
Device & backend compatibility
Pack default: macos / GPU. The fastest backend on the Mac (about 10 ms per frame); the Neural Engine takes 18 ms and 7 s to open.
| Platform | Engine | Status | Precision |
|---|---|---|---|
| apple | CPU CPU | Supported Measured on macOS. | f32 |
| apple | Metal GPU | Supported Measured on macOS. The default. | f32 |
| apple | Apple Neural Engine NPU | Supported Measured on macOS. The Neural Engine computes in FP16. | f16 |
| android | CPU CPU | Supported Measured on a Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2, Adreno 740), Android 17. | f32 |
| android | Vulkan GPU | Supported Measured on a Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2, Adreno 740), Android 17. | f32 |
| android | Qualcomm Hexagon NPU (QNN) NPU | Supported Measured on a Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2, Adreno 740), Android 17. The NPU computes in FP16 (the int8 pack's weights are widened to FP16). | f16 |
Performance
Results depend on the device, runtime, and test conditions. Each measurement keeps its own context.
Mac with Apple M1 Max
Slab · CPU
macOS 26.6.2
161.5 ms
Measured time · scope below
Median of 100 warm runs of the model (Slab's run time). From a 1920 x 1080 photo, resizing included: 161.57 ms median. class_map() at 1920 x 1080 adds about 11 ms.
Mac with Apple M1 Max
Slab · GPU
macOS 26.6.2
9.9 ms
Measured time · scope below
Median of 100 warm runs of the model (Slab's run time). From a 1920 x 1080 photo, resizing included: 11.51 ms median. class_map() at 1920 x 1080 adds about 11 ms.
Mac with Apple M1 Max
Slab · NPU
macOS 26.6.2
17.7 ms
Measured time · scope below
Median of 100 warm runs of the model (Slab's run time). From a 1920 x 1080 photo, resizing included: 18.01 ms median. class_map() at 1920 x 1080 adds about 11 ms.
Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2)
Slab · CPU
Android 17
447.0 ms
Measured time · scope below
Median of 26 warm runs of the model (Slab's run time). From a 1920 x 1080 photo, resizing included: 436 ms median. open_ms: opening the session. Peak memory (resident) after the runs: 215 MB.
Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2)
Slab · GPU
Android 17
250.0 ms
Measured time · scope below
Median of 46 warm runs of the model (Slab's run time). From a 1920 x 1080 photo, resizing included: 217 ms median. open_ms: opening the session with the GPU programs already in the cache folder (the first open on a device compiles them, about 0.3 s more). Peak memory (resident) after the runs: 109 MB.
Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2)
Slab · NPU
Android 17
100.0 ms
Measured time · scope below
Median of 81 warm runs of the model (Slab's run time). From a 1920 x 1080 photo, preprocessing on the CPU included: 122 ms median. open_ms: opening the session, including preparing the model for the Hexagon NPU. Peak memory (resident) after the runs: 103 MB.
Accuracy checks
macos · CPU · f16
The model's Hugging Face image processor, the PyTorch model and post_process_semantic_segmentation at the photo's size (transformers 5.21), 67 public-domain and CC0 photos (Wikimedia Commons); agreement is the share of pixels given the same class, class IoU the mean over the classes in either map
With Slab preprocessing and class_map(): 99.86% of pixels agree (98.93% on the worst photo), class IoU 0.980. On identical input tensors: 99.92% of pixels agree, class IoU 0.986.
macos · GPU · f16
The model's Hugging Face image processor, the PyTorch model and post_process_semantic_segmentation at the photo's size (transformers 5.21), 67 public-domain and CC0 photos (Wikimedia Commons); agreement is the share of pixels given the same class, class IoU the mean over the classes in either map
With Slab preprocessing and class_map(): 99.86% of pixels agree (98.93% on the worst photo), class IoU 0.980. On identical input tensors: 99.92% of pixels agree, class IoU 0.986.
macos · NPU · f16
The model's Hugging Face image processor, the PyTorch model and post_process_semantic_segmentation at the photo's size (transformers 5.21), 67 public-domain and CC0 photos (Wikimedia Commons); agreement is the share of pixels given the same class, class IoU the mean over the classes in either map
With Slab preprocessing and class_map(): 99.24% of pixels agree (98.16% on the worst photo), class IoU 0.872. On identical input tensors: 99.27% of pixels agree, class IoU 0.875.
android · NPU · f16
Slab's CPU engine (FP32) on the same 1920 x 1080 photo
Cosine similarity of the output with the CPU's: 1.00000; the same class on 99.99% of pixels.
Before you choose this model
- Non-commercial use only (NVIDIA Source Code License).
- The class map comes from a 128 x 128 grid, so small objects and thin structures are often absorbed into their surroundings.
- It does not separate objects of the same class.
- The input is stretched to a square, which distorts very wide or tall photos.