SegFormer

SegFormer is a semantic segmentation transformer that pairs a hierarchical Mix Transformer (MiT) encoder with a lightweight all-MLP decode head, avoiding the heavy decoders and fixed positional encodings earlier segmentation transformers needed. LibreYOLO supports it for one task, semantic segmentation, across six sizes.

Tasks
semantic
Sizes
Install
pip install libreyolo
Support tier
Supported, since v. Supporting trainables: kept green in CI, features land opportunistically.
Upstream
SegFormer by NVIDIA, NVIDIA Source Code License (non-commercial, research or evaluation only). Paper, source
Licenses
Code Apache-2.0, weights NVIDIA Source Code License (non-commercial, research or evaluation only). Commercial use

Install

SegFormer needs no optional extra. Everything it imports is in the base install.

bash
pip install libreyolo

Predict

Weights download from Hugging Face on first use and are cached locally.

Python
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreSegformerb0-sem.pt")result = model(SAMPLE_IMAGE, save=True) mask = result.semantic_maskprint(mask.data.shape, mask.classes)
CLI
libreyolo predict model=LibreSegformerb0-sem.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True

result.semantic_mask carries the dense class map: .data is an (H, W) tensor of class IDs on the original image size, and .classes lists the class IDs actually present. result.boxes is None, since there are no per-instance detections. conf and iou are accepted for API parity but do not change the output: the model returns one class per pixel, not per-instance detections to filter or de-duplicate. See prediction for sources, streaming and result handling.

Variants

Six sizes, b0 through b5, widening and deepening the Mix Transformer encoder at each step while keeping the same all-MLP decode head design.

Every file above exists in the LibreYOLO org today and downloads on first use.

Train

train() fine-tunes a published checkpoint by default. Pass no model_path to LibreSegformer(...) instead and it builds with a randomly initialized encoder and head, training from scratch, the only route to weights that carry none of the pretrained checkpoints' non-commercial restriction (see Licensing).

Python (fine-tune)
from libreyolo import LibreYOLO model = LibreYOLO("LibreSegformerb0-sem.pt")model.train(data="my-dataset.yaml", epochs=160, imgsz=512, batch=8)
CLI
libreyolo train model=LibreSegformerb0-sem.pt data=my-dataset.yaml \  epochs=160 imgsz=512 batch=8
From scratch
from libreyolo.models.segformer.model import LibreSegformer # No model_path: random init, nothing downloaded. The only route to# weights free of the pretrained checkpoints' non-commercial term.model = LibreSegformer(size="b0", nb_classes=150)model.train(data="my-dataset.yaml", epochs=160, imgsz=512, batch=8)
Multi-GPU
libreyolo train model=LibreSegformerb0-sem.pt data=my-dataset.yaml \  epochs=160 device=0,1 batch=16

Left alone, the trainer follows the SegFormer paper's ADE20K recipe: AdamW at a backbone base learning rate with the decode head trained at 10x that rate, weight decay everywhere except LayerNorm and the Mix-FFN positional convolution, and a linear decay schedule with a warmup. Convergence for the larger sizes, b3 through b5, has not been validated end to end.

See training for datasets, augmentation, multi-GPU and loggers.

Validate

val() returns a dictionary of metrics/ keys: mIoU and pixel accuracy, measured against any dataset in the format you trained on.

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreSegformerb0-sem.pt")metrics = model.val(data="my-dataset.yaml") print(metrics["metrics/mIoU"])print(metrics["metrics/pixel_accuracy"])
CLI
libreyolo val model=LibreSegformerb0-sem.pt data=my-dataset.yaml

Export

TaskONNXTorchScriptExecuTorchTensorRTOpenVINOPaddleMNNRKNNncnnTFLiteCoreMLCore AI
semanticsemantic to ONNX: supported. semantic to TorchScript: supported. semantic to ExecuTorch: supported. semantic to TensorRT: supported. semantic to OpenVINO: supported. semantic to Paddle: not supportedsemantic to MNN: not supportedsemantic to RKNN: not supportedsemantic to ncnn: not supportedsemantic to TFLite: not supportedsemantic to CoreML: not supportedsemantic to Core AI: not supported

An exported artifact loads back through LibreYOLO() on its file suffix, so a .onnx or .engine file behaves like a checkpoint and returns the same Results. Export lists the arguments every format accepts.

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreSegformerb0-sem.pt")model.export(format="onnx", imgsz=512)model.export(format="tensorrt", imgsz=512, half=True)
CLI
libreyolo export model=LibreSegformerb0-sem.pt format=onnx imgsz=512libreyolo export model=LibreSegformerb0-sem.pt format=tensorrt imgsz=512 half=True
Use the exported file
from libreyolo import LibreYOLO, SAMPLE_IMAGE # The factory routes on the file suffix, so an exported artifact loads# like any checkpoint and returns the same Results object.model = LibreYOLO("LibreSegformerb0-sem.onnx")result = model(SAMPLE_IMAGE) print(result.semantic_mask.data.shape)

Checkpoints

Every published weight file for this family.

Every file above exists in the LibreYOLO org today and downloads on first use.

Licensing

Check the license on the Hugging Face repository of the specific weights you download. Every checkpoint in the LibreYOLO org carries one, and they are not always the same across a family. That repository is the authoritative source; the summary below describes what applied when this page was last verified.

This is a description of the licenses involved, not legal advice. If the answer matters commercially, read the licenses yourself and take your own counsel.

Original work
SegFormer, NVIDIA
Upstream license
NVIDIA Source Code License (non-commercial, research or evaluation only)
LibreYOLO code
MIT
Weights
NVIDIA Source Code License (non-commercial, research or evaluation only), republished at huggingface.co/LibreYOLO
Interpretation
The pretrained ADE20K checkpoints LibreYOLO hosts for this family are converted from NVIDIA's official SegFormer release under the NVIDIA Source Code License. That license permits redistributing the weights and derivative works, provided the license text and attribution notices travel with them, but it limits USE to non-commercial research or evaluation, a restriction its Section 3.2 carries forward into every derivative and that cannot be relicensed away: these weights are NOT covered by LibreYOLO's normal permissive terms, and that limitation binds you, not just LibreYOLO. LibreYOLO's own SegFormer implementation is a separate Apache-2.0 port of Hugging Face Transformers' code, unrelated to NVIDIA's repository, so a model you train from scratch with LibreSegformer(...).train(...) carries none of this restriction.

LibreSegformer's encoder and decode head are a PyTorch port of Hugging Face Transformers' Apache-2.0 SegFormer implementation, not of NVlabs/SegFormer: NVIDIA's original repository was never read or copied, and is credited here only for attribution to the paper's authors. Only the pretrained checkpoints above carry NVIDIA's non-commercial restriction; the architecture and LibreYOLO's own code stay MIT throughout.

Citation

@inproceedings{xie2021segformer,
  title={SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers},
  author={Xie, Enze and Wang, Wenhai and Yu, Zhiding and Anandkumar, Anima and Alvarez, Jose M and Luo, Ping},
  booktitle={Neural Information Processing Systems (NeurIPS)},
  year={2021}
}

Copied from the authors' citation block at github.com/NVlabs/SegFormer#citation.

Verified against LibreYOLO v1.5.0. Support tables, checkpoints and benchmark numbers on this page are generated from the released library and the published weights, not written by hand.