SegFormer B0
Fit diagram
Read at 100%
Clear selection
Download SVG
Download PNG
Click a block to read its description, or select it with Tab and Enter.
SegFormer B0
Semantic segmentation, 150 classes, 512 × 512 RGB, native eval. Shapes exclude batch.
LibreYOLO
SegFormer B0
Semantic segmentation, 150 classes, 512 × 512 RGB, native eval. Shapes exclude batch.
MiT encoder
RGB input and ImageNet normalization
3 × 512 × 512
Conv2d overlap embedding
3 to 32; k=7, s=4, p=3
Flatten + LayerNorm
128 × 128 spatial tokens, width 32
Transformer block, n=2
1 heads; reduction 8
LayerNorm + restore spatial map
32 × 128 × 128
F1
Conv2d overlap embedding
32 to 64; k=3, s=2, p=1
Flatten + LayerNorm
64 × 64 spatial tokens, width 64
Transformer block, n=2
2 heads; reduction 4
LayerNorm + restore spatial map
64 × 64 × 64
F2
Conv2d overlap embedding
64 to 160; k=3, s=2, p=1
Flatten + LayerNorm
32 × 32 spatial tokens, width 160
Transformer block, n=2
5 heads; reduction 2
LayerNorm + restore spatial map
160 × 32 × 32
F3
Conv2d overlap embedding
160 to 256; k=3, s=2, p=1
Flatten + LayerNorm
16 × 16 spatial tokens, width 256
Transformer block, n=2
8 heads; reduction 1
LayerNorm + restore spatial map
256 × 16 × 16
F4
No learned position embeddings; Mix-FFN supplies spatial mixing.
All-MLP decode head
F4
256 × 16 × 16
Flatten + Linear
256 to 256
Restore feature map
256 × 16 × 16
Bilinear resize
256 × 128 × 128
F3
160 × 32 × 32
Flatten + Linear
160 to 256
Restore feature map
256 × 32 × 32
Bilinear resize
256 × 128 × 128
F2
64 × 64 × 64
Flatten + Linear
64 to 256
Restore feature map
256 × 64 × 64
Bilinear resize
256 × 128 × 128
F1
32 × 128 × 128
Flatten + Linear
32 to 256
Restore feature map
256 × 128 × 128
Bilinear resize
256 × 128 × 128
Concat in reverse stage order: F4, F3, F2, F1
1024 × 128 × 128
Conv2d 1×1
1024 to 256; bias=False
BatchNorm2d
256 channels
ReLU
Dropout 0.1
Identity in eval
Conv2d 1×1
256 to 150; bias=True
Bilinear resize to input size
align_corners=False
Semantic logits
150 × 512 × 512
All linear and overlap/reduction convolutions have bias unless marked otherwise.
Stage 1 transformer block
Input tokens
16384 × 32
LayerNorm
32 channels, epsilon 1e-5
Linear Q
32 to 32
Conv2d reduction
k=s=8; 32 channels
Flatten + LayerNorm
256 × 32
Linear K
32 to 32
Linear V
32 to 32
Q × transpose(K)
Scale 1/sqrt(32); 1 heads
Softmax over keys
16384 queries, 256 keys
Weights × V
1 heads, width 32
Concat heads
16384 × 32
Output linear
32 to 32
+
LayerNorm
32 channels
Linear Mix-FFN
32 to 128
Depthwise Conv2d 3×3
128 channels/groups; stride1, padding1
GELU
Linear Mix-FFN
128 to 32
+
Output tokens
16384 × 32
DropPath and all dropout are identities during eval.
Stage 2 transformer block
Input tokens
4096 × 64
LayerNorm
64 channels, epsilon 1e-5
Linear Q
64 to 64
Conv2d reduction
k=s=4; 64 channels
Flatten + LayerNorm
256 × 64
Linear K
64 to 64
Linear V
64 to 64
Q × transpose(K)
Scale 1/sqrt(32); 2 heads
Softmax over keys
4096 queries, 256 keys
Weights × V
2 heads, width 32
Concat heads
4096 × 64
Output linear
64 to 64
+
LayerNorm
64 channels
Linear Mix-FFN
64 to 256
Depthwise Conv2d 3×3
256 channels/groups; stride1, padding1
GELU
Linear Mix-FFN
256 to 64
+
Output tokens
4096 × 64
DropPath and all dropout are identities during eval.
Stage 3 transformer block
Input tokens
1024 × 160
LayerNorm
160 channels, epsilon 1e-5
Linear Q
160 to 160
Conv2d reduction
k=s=2; 160 channels
Flatten + LayerNorm
256 × 160
Linear K
160 to 160
Linear V
160 to 160
Q × transpose(K)
Scale 1/sqrt(32); 5 heads
Softmax over keys
1024 queries, 256 keys
Weights × V
5 heads, width 32
Concat heads
1024 × 160
Output linear
160 to 160
+
LayerNorm
160 channels
Linear Mix-FFN
160 to 640
Depthwise Conv2d 3×3
640 channels/groups; stride1, padding1
GELU
Linear Mix-FFN
640 to 160
+
Output tokens
1024 × 160
DropPath and all dropout are identities during eval.
Stage 4 transformer block
Input tokens
256 × 256
LayerNorm
256 channels, epsilon 1e-5
Linear Q
256 to 256
Identity K/V input
256 channels
Identity
256 × 256
Linear K
256 to 256
Linear V
256 to 256
Q × transpose(K)
Scale 1/sqrt(32); 8 heads
Softmax over keys
256 queries, 256 keys
Weights × V
8 heads, width 32
Concat heads
256 × 256
Output linear
256 to 256
+
LayerNorm
256 channels
Linear Mix-FFN
256 to 1024
Depthwise Conv2d 3×3
1024 channels/groups; stride1, padding1
GELU
Linear Mix-FFN
1024 to 256
+
Output tokens
256 × 256
DropPath and all dropout are identities during eval.
Source: libreyolo/models/segformer/nn.py and model.py. Revision a4d0ecc9e17f.
libreyolo.com