TransUNet Transformer U-Net Hybrid
TransUNet puts transformer layers in the U-Net bottleneck so global context guides exact pixel boundaries.
Why Does This Exist?
Pure U-Nets see locally; organs need far context like liver versus spleen sides. Pure transformers lose pixel detail. TransUNet (2021) encodes with CNNs, runs transformer layers on patches in the bottleneck, then decodes with skips. Input is CT slices; output is multi-organ masks with global coherence.
Think of It Like This
A quilt circle with a town meeting in the middle
Quilters sew local patches, pause for a town meeting to agree which patch goes where globally, then resume stitching edges precisely. Skipping the meeting misplaces whole districts; skipping stitching frays edges.
CNNs quilt and transformers meet. The analogy stops at order: meetings sit mid-network, not mid-day.
How It Actually Works
A ResNet stem downsamples to tokens of dim . Twelve self-attention layers mix globally. The decoder upsamples with three skips from early CNN stages, restoring resolution. Loss is Dice plus cross-entropy per organ.
Worked example
An abdominal slice shows liver left and stomach mid. CNN-only gives liver Dice but flips a cm stomach patch to liver at score. Transformer context sees spleen on the far side and corrects the patch to stomach . Boundary error falls from to mm after skips restore edges.
Watch Out For
Small data overfitting the transformer
Twelve layers on scans memorize scanner texture. The symptom is high train Dice with test drops. Freeze early CNN stages and augment heavily before blaming architecture.
The Quick Version
- TransUNet mixes CNN detail with bottleneck transformer context.
- Twelve layers on -pixel patches see whole-slice layout.
- Skips restore pixel edges after global mixing.
- Do not train transformers on tiny sets without freezing and augmentation.
- Global context fixes side flips that local U-Nets miss.