Search

Search papers and lessons

U-Net: Convolutional Networks for Biomedical Image Segmentation

Olaf Ronneberger, Philipp Fischer, Thomas Brox · 2015

Ronneberger et al. (2015) present a U-shaped convolutional network that segments biomedical images pixel by pixel from only a few dozen annotated images.

On this page

  • Colour = topic mix
  • Calculus
  • Architectures
  • Neural network basics
  • Linear algebra
  • Losses & regularization
  • Discrete math
  • Sign in to see your progress

TL;DR

Olaf Ronneberger, Philipp Fischer and Thomas Brox designed a network that labels every pixel of a biomedical image, and trained it on very few annotated images. The network is a U shape. A contracting path captures context by downsampling, and an expanding path rebuilds the resolution. Skip connections copy the fine detail from the contracting path into the expanding one, so the output is both precise and aware of context. Heavy elastic-deformation augmentation and a weighted loss let it separate touching cells. It won the ISBI cell tracking challenge 2015 in two categories and beat the previous best method on electron microscopy neuron segmentation.

Where you'll see it: medical image segmentation tools, and as the denoising backbone of many image diffusion models.

The problem

Classification networks output one label for a whole image. Biomedical work often needs a label for every pixel, such as which pixels belong to a cell or to a membrane. Two things made that hard in 2015.

The first was data. Annotating medical images takes expert time, so a project might have 30 or 35 training images. The paper's abstract says successful training of deep networks is widely believed to need many thousand annotated samples, and its introduction recalls that the eight-layer network of Krizhevsky et al. was trained on ImageNet's million training images.

The second was the trade-off between localization and context. Ciresan et al. won the ISBI 2012 electron microscopy challenge with a sliding-window network. It classified each pixel from the patch of pixels around it. That gave a lot of training samples, because every patch is one. But the method is slow, since the network runs once per patch and the patches overlap heavily. It also forces a choice. Large patches give context but need more pooling, which blurs the exact location. Small patches keep the location but see little context.

Key idea

The paper takes the fully convolutional idea of Long et al. and makes the expanding path as large as the contracting path. The contracting path looks at context. At each pooling step the network sees a coarser picture, so each output unit sees a wider region. The expanding path then upsamples back to full resolution, and at every step it concatenates the matching high-resolution feature map from the contracting path. The fine position information that pooling discarded comes back through these copies. A convolution after each concatenation learns to combine the two.

Pictured on the page, the network has a left arm that goes down, a right arm that goes up, and horizontal arrows that copy features across. That shape is the name.

The second idea is about data. Because only a few images exist, the training images are deformed in smooth random ways so that the network sees many versions of each cell. The network learns invariance to deformations without ever being shown real deformations in the annotations.

The method

Architecture

The contracting path repeats two 3×33 \times 3 convolutions, each followed by a ReLU, then a 2×22 \times 2 max-pooling with stride 2. At each downsampling step the number of feature channels doubles.

The expanding path repeats three operations. First, an upsampling step with a 2×22 \times 2 up-convolution halves the number of channels. Second, the result is concatenated with the matching feature map from the contracting path, cropped to the same size. Third, two 3×33 \times 3 convolutions, each followed by a ReLU, reduce the channels again. A final 1×11 \times 1 convolution maps each 64-channel feature vector to the number of classes. The network has 23 convolutional layers and no fully connected layers.

Two details matter for tiling. The convolutions are unpadded, so the output is smaller than the input by a fixed border. The authors use the output tile to predict only the pixels whose full context lies inside the input, and they mirror the input to fill the missing context at the image edge. The input tile size is chosen so that every 2×22 \times 2 pooling sees an even width and height, which lets output tiles fit together without seams. This is the overlap-tile strategy. It lets the network segment images of any size, limited only by GPU memory per tile.

The up-convolution is a learned upsampling, the same family as Transposed Convolution. The overall shape is the encoder-decoder pattern with skip connections.

The loss

The final feature map gives a score ak(x)a_k(\mathbf{x}) for each class kk at each pixel x\mathbf{x}. A pixel-wise Softmax turns these into probabilities,

pk(x)=exp⁡(ak(x))∑k′=1Kexp⁡(ak′(x)),p_{k}(\mathbf{x}) = \frac{\exp\big(a_{k}(\mathbf{x})\big)}{\sum_{k'=1}^{K} \exp\big(a_{k'}(\mathbf{x})\big)},

where KK is the number of classes. The cross-entropy term looks at the probability of the true class ℓ(x)\ell(\mathbf{x}) at each pixel. The paper writes the weighted energy as

E=∑x∈Ωw(x)log⁡(pℓ(x)(x)).E = \sum_{\mathbf{x} \in \Omega} w(\mathbf{x}) \log\big(p_{\ell(\mathbf{x})}(\mathbf{x})\big).

Here Ω\Omega is the set of pixels, ℓ\ell gives the true class, and ww is a weight map. The energy as written is the weighted log-probability of the correct class, which is negative and largest when the network is right. The paper says the cross entropy "penalizes" deviation of pℓ(x)p_{\ell(\mathbf{x})} from 1, so the equation as printed is missing a minus sign: the quantity to minimize is −E-E, which is the usual weighted Cross-Entropy Loss.

The weight map does two jobs. First, it balances the classes by frequency. Second, and more interesting, it gives extra weight to the thin background gaps between touching cells:

w(x)=wc(x)+w0exp⁡(−(d1(x)+d2(x))22σ2).w(\mathbf{x}) = w_{c}(\mathbf{x}) + w_{0} \exp\left(-\frac{\big(d_{1}(\mathbf{x}) + d_{2}(\mathbf{x})\big)^{2}}{2\sigma^{2}}\right).

Here wcw_c balances the classes, and d1d_1 and d2d_2 are the distances from a pixel to the borders of its nearest and second-nearest cells. The paper uses w0=10w_0 = 10 and σ≈5\sigma \approx 5 pixels. A background pixel squeezed between two cells has both distances small, so the exponential term is close to w0w_0. For example, if both distances are 5 pixels, the sum is 10 and the extra weight is 10exp⁡(−100/50)=10e−2≈1.3510 \exp(-100/50) = 10 e^{-2} \approx 1.35, and if both are 1 pixel it is 10exp⁡(−4/50)≈9.210 \exp(-4/50) \approx 9.2. The network is pushed to learn the separating border instead of merging the cells.

Initialization and optimization

The paper says that in a deep network with many paths, a good start matters: otherwise some parts give huge activations while others never contribute. The authors want each feature map to have roughly unit variance. For an architecture of alternating convolutions and ReLUs they draw the weights from a Gaussian with standard deviation 2/N\sqrt{2/N}, where NN is the number of incoming connections. They cite He et al. for this rule. For a 3×33 \times 3 convolution with 64 input channels, N=9×64=576N = 9 \times 64 = 576. This is the rule covered in He (Kaiming) Initialization.

Training uses stochastic gradient descent in the Caffe framework. Because the input tiles are large, the batch size is one image. To make up for the noisy single-image updates the authors use a high Momentum of 0.99, so each update is mostly driven by many earlier samples.

Data augmentation

The augmentation is the core of the training recipe. Microscopy images need shift and rotation invariance, robustness to deformation, and robustness to changes in grey level. The authors use smooth elastic deformations. They place random displacement vectors on a coarse 3×33 \times 3 grid, sampled from a Gaussian with a standard deviation of 10 pixels, and interpolate them to a displacement for every pixel with bicubic interpolation. Dropout layers at the end of the contracting path add a little more implicit augmentation. See Data Augmentation for the general idea.

Results

Neuron segmentation in electron microscopy

The first task is the EM segmentation challenge from ISBI 2012. The training set has 30 images of 512×512512 \times 512 pixels from a Drosophila larva nerve cord, with ground truth for cells and membranes. The test labels are held by the organizers, who score predicted membrane maps with three metrics: warping error, Rand error and pixel error.

The U-Net, averaged over seven rotated copies of the input, reaches a warping error of 0.0003529 with no pre- or post-processing. It was the best warping error on the leaderboard of 6 March 2015 (Table 1 in the paper), ahead of the sliding-window network of Ciresan et al. (IDSIA), whose best entry had 0.000420 warping error and 0.0504 Rand error. The margin over the runner-up is tiny, though: DIVE-SCI had a warping error of 0.000355 against the U-Net's 0.000353. The human reference values in the paper are 0.000005 for warping error and 0.0021 for Rand error.

EntryWarping errorRand errorPixel error
U-Net0.0003530.03820.0611
DIVE-SCI0.0003550.03050.0584
IDSIA (Ciresan et al.)0.0004200.05040.0613
DIVE0.0004300.05450.0582
IDSIA-SCI0.0006530.01890.1027

So the U-Net is best only on warping error. Other entries have lower Rand error and pixel error. The text says the only algorithms with a better Rand error use highly dataset-specific post-processing of the Ciresan et al. probability map, and a footnote says the authors of "this algorithm" submitted 78 different solutions; the table itself does not say which entries those are, so treat that claim as the authors' word.

Cell tracking

The second task is light microscopy from the ISBI cell tracking challenge 2015. Performance is measured by intersection over union (IOU), the overlap between the predicted and the true mask divided by their union.

DatasetTraining imagesSecond-best IOUU-Net IOU
PhC-U373 (phase contrast)350.830.9203
DIC-HeLa (differential interference contrast)200.460.7756

Both datasets have only partially annotated training images. The authors describe the gap as large. The text says "92%" for the first dataset and "77.5%" for the second, while Table 2 gives 0.9203 and 0.7756 (which rounds to 77.6%), so the text truncates slightly. The "second-best 2015" row of the table is 0.83 and 0.46, the values the text quotes; the three named 2014 entries below it are earlier submissions. The paper reports these as wins in the 2015 challenge in both categories.

Speed and cost

The abstract states that segmenting a 512×512512 \times 512 image takes less than a second on a recent GPU. The conclusion reports about 10 hours of training on an NVIDIA Titan with 6 GB of memory.

Why it mattered

The U-Net became one of the most reused architectures in computer vision. Its pattern, a downsampling path, an upsampling path, and skip connections that carry fine detail across, appears in segmentation models for medical imaging, satellite imagery, and many other domains. In diffusion models the same U shape is the denoiser that predicts noise at each step.

The paper also set a template for working with small datasets. Elastic deformation as augmentation, a loss weight map that targets the hard pixels, and a training setup that treats one large tile as a batch all became standard tools. Its overlap-tile inference gave a practical way to segment images much larger than the network's input.

The paper leaves some questions open. It shows results on three datasets from electron microscopy and two kinds of light microscopy (the text of Section 4 says "three different segmentation tasks", while the introduction mentions two applications). The authors note the design is not tied to them, but the claim that it "can be applied easily to many more tasks" was a hope in 2015 rather than a result. Later architectures added attention, residual blocks, and normalization to the basic design.

Reading guide

Read the paper in this order. The lessons listed are the prerequisites for each part.

  1. Section 1, Introduction. Needs Image Segmentation, Convolutional Neural Network and Max Pooling. The sliding-window argument also assumes the idea of a patch-based classifier.
  2. Section 2, Network architecture. Needs U-Net for the overall shape, Rectified Linear Unit (ReLU), Max Pooling, and Transposed Convolution for the up-convolution. The skip connections are an instance of Encoder-Decoder Architecture.
  3. Section 3, Training, loss. Needs Softmax and Cross-Entropy Loss. The weight map adds nothing new beyond that.
  4. Section 3, Training, optimization. Needs Stochastic Gradient Descent and Momentum, and He (Kaiming) Initialization for the initialization rule that the paper cites.
  5. Section 3.1, Data augmentation. Needs Data Augmentation. The Gaussian displacement grid is a simple use of Gaussian (Normal) Distribution.
  6. Section 4, Experiments. Needs the metrics only. IOU is the overlap of two masks divided by their union. Warping error and Rand error are specific to the EM benchmark, and the paper defines them in the challenge documentation.
  7. Section 5, Conclusion. Nothing new.

Check yourself

QuestionIn the U-Net, what happens to the number of channels in the contracting path at each max-pooling step, and what happens to it in the expanding path at each up-convolution?Show answer

In the contracting path the number of channels doubles at each downsampling step, so the network trades spatial size for more feature channels. In the expanding path the up-convolution halves the number of channels, and the concatenation with the skip features brings back the high-resolution detail before two more convolutions.

QuestionA pixel's softmax probabilities for three classes are 0.7, 0.2 and 0.1, and the true class is the second one. What is the unweighted log-probability term for that pixel, and what does the training objective do with it?Show answer

The term is log⁡0.2≈−1.609\log 0.2 \approx -1.609. The loss to minimize is the negative weighted sum −E-E (the paper prints EE without the minus sign), so with weight ww this pixel contributes −wlog⁡0.2≈1.609 w-w \log 0.2 \approx 1.609\,w. Minimizing it pushes log⁡p\log p up toward zero, which means raising the probability of the true class.

QuestionFor a 3 by 3 convolution with 128 input channels, what standard deviation does the paper's initialization give to the weights?Show answer

The number of incoming connections is N=9×128=1152N = 9 \times 128 = 1152. The standard deviation is 2/1152=0.001736≈0.0417\sqrt{2/1152} = \sqrt{0.001736} \approx 0.0417.

QuestionWhy does the weight map ww use a term that depends on d1+d2d_1 + d_2, and what happens to that term for a background pixel that sits between two touching cells?Show answer

The term d1+d2d_1 + d_2 is the sum of distances from a pixel to the borders of its nearest and second-nearest cells. A background pixel squeezed between two touching cells has both distances small, so the sum is small, the exponential is close to 1, and the weight is close to w0=10w_0 = 10. The loss then penalizes mistakes on those pixels much more than on background far from any cell, which teaches the network to keep the thin separation between cells.

QuestionWhy does the authors' choice of a batch of one image with a momentum of 0.99 make sense for this setup?Show answer

Large input tiles fill the GPU memory, so a batch of more than one image does not fit. A batch of one gives noisy gradients, and a high momentum averages them over many earlier updates. With momentum 0.99 each step is dominated by the accumulated direction of the previous many samples, which smooths out the noise from the single image.

Sources

Read the full paper

Olaf Ronneberger, Philipp Fischer, Thomas Brox, 2015. arXiv:1505.04597