Why segmentation needs a different shape
A classifier collapses an image to one label, so throwing away spatial detail is free. Segmentation has to return a label per pixel, so the detail has to come back.
The output is the same size as the input, with one channel per class rather than three colours.
That forces an architecture that goes down and then comes back up, which is where the U in the name comes from.
The two halves
The encoder is an ordinary convolutional stack. Each stage convolves twice and pools once, halving the resolution and doubling the channels.
The decoder mirrors it. Each stage upsamples, halves the channels, and convolves twice.
The skip connection is the part that matters: before convolving, the decoder concatenates the encoder's map from the same resolution onto its own.
What the skip connections carry
The encoder's deep layers know what is in the image and have lost where, because five poolings reduced 256 pixels to 8.
Its early layers know exactly where every edge is and almost nothing about what they belong to.
The decoder needs both at once, and concatenation gives it both rather than forcing one path to carry them.
Concatenation rather than addition is deliberate. Adding would force the two to share a representation, while concatenating lets the following convolution learn how to weigh them.
One pass, in order
- Two 3 by 3 convolutions with ReLU, then store the result for the skip.
- Pool, and repeat for each encoder stage.
- At the bottom, two convolutions on the smallest map.
- Upsample, concatenate the stored map from that resolution, then two convolutions.
- Repeat for each decoder stage.
- A final 1 by 1 convolution mapping channels to classes, then softmax over the class axis.
The loss, and the imbalance behind it
Pixelwise cross-entropy treats every pixel as its own classification problem, which works and is badly imbalanced when the object is small.
Dice loss measures overlap instead, so it is insensitive to how much background there is, and it is the standard choice in medical imaging for that reason.
The two are usually summed, because Dice alone has an unstable gradient when the prediction is almost empty and cross-entropy alone ignores the shape.
Why it survived
U-Net was published in 2015 for cell images with about 30 training examples, and it still wins on small datasets.
The reason is the skip connections and heavy augmentation rather than depth.
The same shape now sits inside every diffusion model, where the noise predictor is a U-Net with attention added.