Upsampling
Upsampling increases the height and width of a feature map, usually by a factor of . It acts on each channel separately unless it is a learned convolution. Networks that output an image, such as segmentation and denoising networks, use it to undo the downsampling of their first half. There are four common methods:
- Duplication (nearest-neighbor upsampling) copies each value into a block.
- Max unpooling puts each value back at the position that won the matching max pool and fills the rest of the block with zeros.
- Bilinear interpolation fills the new positions with weighted averages of their nearest neighbors.
- Transposed convolution learns its upsampling weights.
In a transposed convolution, each input value multiplies a full copy of the kernel, and the copies are placed positions apart. Where copies overlap, their contributions add. Take 1D with stride and no padding, and index the input and kernel from . Input adds to output position :
With this is the full convolution .
Padding then removes positions from each end. An input of length gives an output of length
which inverts the size rule of an ordinary convolution. The input and output sizes swap places relative to a strided convolution with the same , and . Its weight matrix is the transpose of that convolution’s weight matrix, which gives the method its name. With channels it has weights, like an ordinary convolution.An equivalent recipe has three steps:
- Insert zeros between neighboring inputs.
- Pad with zeros on each side.
- Cross-correlate with the reversed kernel at stride , which is the same as convolving with .
Duplication, max unpooling and interpolation have no parameters. A transposed convolution is the only one that learns. None of them can recover detail that downsampling destroyed, which is why encoder-decoder networks add skip connections such as those of the U-Net.
Deconvolution Is Not an Inverse
Some papers call transposed convolutions “deconvolutions”. A transposed convolution is not the inverse of a convolution. It has the transposed shape and connectivity, not the inverse effect, and applying a convolution and then its transpose does not return the input.
Not Taught in Lecture
Lecture did not cover bilinear interpolation as an upsampling layer. The textbook treats it in section 10.4.2.
Intuition
A classifier can end with a single vector, but a segmentation network must label every pixel. It still needs the wide context that only a downsampled representation provides. A patch of shirt is easier to label when the network can see the whole person, so it shrinks the image and then grows it back. Growing a map is the mirror image of shrinking it. A stride-2 convolution collects three neighboring inputs into each output. A stride-2 transposed convolution sends each input out to three neighboring outputs, as the figure shows. The outputs at positions and receive two contributions each and add them.
\usepackage{tikz}
\begin{document}
\definecolor{hot}{HTML}{D9483B}
\definecolor{cold}{HTML}{2F80ED}
\definecolor{grn}{HTML}{2F9E44}
\begin{tikzpicture}[x=1.05cm,y=1cm,>=latex]
\node[circle,draw,minimum size=0.62cm,inner sep=0pt] (x1) at (2,2.4) {$x_1$};
\node[circle,draw,minimum size=0.62cm,inner sep=0pt] (x2) at (4,2.4) {$x_2$};
\node[circle,draw,minimum size=0.62cm,inner sep=0pt] (x3) at (6,2.4) {$x_3$};
\foreach \t in {1,...,7} \node[circle,draw,minimum size=0.62cm,inner sep=0pt] (y\t) at (\t,0) {$y_{\t}$};
\draw[->,cold,very thick] (x1) -- node[pos=0.65,left] {$\omega_1$} (y1);
\draw[->,cold,very thick] (x1) -- (y2);
\draw[->,cold,very thick] (x1) -- node[pos=0.7,right] {$\omega_3$} (y3);
\draw[->,hot,very thick] (x2) -- (y3);
\draw[->,hot,very thick] (x2) -- (y4);
\draw[->,hot,very thick] (x2) -- (y5);
\draw[->,grn,very thick] (x3) -- (y5);
\draw[->,grn,very thick] (x3) -- (y6);
\draw[->,grn,very thick] (x3) -- node[pos=0.65,right] {$\omega_3$} (y7);
\node[left] at (0.6,2.4) {input};
\node[left] at (0.6,0) {output};
\node at (4,-1.0) {stride $2$: copies of the kernel start every two positions and add where they overlap};
\end{tikzpicture}
\end{document}The fixed methods make simpler guesses. Duplication assumes the map is constant inside each block. Max unpooling assumes the feature sits exactly where the encoder last saw it. Interpolation assumes the map changes smoothly. A transposed convolution lets the network choose its own rule. All four face the same limit. Every halving of the resolution throws away the finest detail, and no upsampler can invent it again. The decoder can be sharp only if the encoder’s high-resolution maps are copied across to it.
\usepackage{tikz}
\begin{document}
\definecolor{hot}{HTML}{D9483B}
\definecolor{cold}{HTML}{2F80ED}
\begin{tikzpicture}[x=0.62cm,y=0.62cm,>=latex]
\foreach \v [count=\c from 0] in {3,1} \node[draw,minimum size=0.62cm] at (\c+0.5,-0.5) {$\v$};
\foreach \v [count=\c from 0] in {5,2} \node[draw,minimum size=0.62cm] at (\c+0.5,-1.5) {$\v$};
\node at (1,0.7) {input};
\draw[->,thick] (2.4,-0.6) -- (3.8,0.2);
\draw[->,thick] (2.4,-1.4) -- (3.8,-2.4);
\foreach \r/\row in {0/{3,3,1,1},1/{3,3,1,1},2/{5,5,2,2},3/{5,5,2,2}} {
\foreach \v [count=\c from 0] in \row \node[draw=cold,minimum size=0.62cm] at (4.5+\c,1.9-\r) {$\v$};
}
\node[right] at (8.3,0.4) {duplication};
\foreach \r/\row in {0/{0,0,0,1},1/{0,3,0,0},2/{5,0,0,0},3/{0,0,2,0}} {
\foreach \v [count=\c from 0] in \row \node[draw=hot,minimum size=0.62cm] at (4.5+\c,-2.5-\r) {$\v$};
}
\node[right] at (8.3,-4.0) {max unpooling};
\end{tikzpicture}
\end{document}Properties
(Transpose of the Downsampling Matrix) A transposed convolution multiplies by the transpose of the matrix that the matching strided convolution uses.
Consider a stride-2 convolution with and zero padding that maps inputs to outputs. It is a matrix in which each row holds the kernel. Each row starts two columns to the right of the row above, and the padding cuts the first row to . Its transpose is , and each column holds the kernel. Multiplying a length- vector by places a scaled copy of the kernel for each input, two rows apart, which is the scatter-and-add rule. The same fact explains backpropagation. The gradient of a convolution with respect to its input is times the upstream gradient, so the backward pass of every convolutional layer is a transposed convolution. Frameworks implement both with the same routine.
(Zero-Insertion View) A transposed convolution equals zero insertion followed by a cross-correlation with the reversed kernel.
Insert zeros between consecutive inputs, which gives a sequence of length . Pad it with zeros on each side and cross-correlate it with the reversed kernel at stride . The output length is , which matches the rule in the callout. Each output entry collects the same products as the scatter rule. For a symmetric kernel the reversal makes no difference. This view explains the old name “fractionally strided convolution”: the kernel moves of an input position per output.
(Fixed Upsamplers Are Special Cases) Duplication and linear interpolation are transposed convolutions with fixed kernels.
In 1D with , the kernel with copies each input into two outputs, which is duplication. The kernel with places each input at an odd position and half of it at each neighbor. The result is , which is linear interpolation. In 2D, bilinear interpolation uses the outer product of with itself, applied to each channel separately. A learned transposed convolution can therefore match any of these and improve on them when the data reward it. Max unpooling is not of this form, because the positions it writes to depend on the input.
(Checkerboard Artifacts) When the kernel size is not a multiple of the stride, some outputs receive more contributions than others.
Not Taught in Lecture
Lecture did not discuss checkerboard artifacts. The textbook’s chapter notes mention them.
With and , odd interior positions receive two contributions and even positions receive one. A constant input then produces an alternating output, and in 2D the pattern looks like a checkerboard. Training can learn to compensate, but the artifacts often survive in generated images. Choosing divisible by , such as with , gives every interior output the same number of contributions. Another fix replaces the transposed convolution by duplication or bilinear upsampling followed by an ordinary convolution.
(Max Unpooling Needs the Indices) Max unpooling reuses the positions recorded by an earlier max pool, so it only works in a network that pooled first.
During the forward pass, each max pool records which of its four inputs won. A max-unpooling layer at the matching resolution in the decoder writes each value back to that recorded position and fills the other three with zeros. The result is sparse, and convolutions after it fill in the gaps. Early segmentation networks paired every max pool in the encoder with a max unpool in the decoder for this reason. The recorded positions carry a little spatial detail from the encoder to the decoder, a weaker version of a skip connection.
Examples
(Easy) Duplication and Max Unpooling
A decoder receives the map . The matching max pool in the encoder recorded its winners at positions , , and of the map.
Upsample the map by duplication and by max unpooling. block. Max unpooling writes each value at its recorded position and zeros elsewhere: Both keep the same four values. Duplication spreads them evenly, and max unpooling puts them back where the encoder found them.
Duplication copies each value into its
(Medium) A 1D Transposed Convolution Two Ways
The input passes through a transposed convolution with kernel and stride .
Compute the output with by scattering, check it by zero insertion, and give the output for . Each input places a scaled kernel two positions after the previous one: at positions to , at positions to , and at positions to . Adding the overlaps at positions and gives with length . For the check, insert one zero between inputs to get , pad with zeros on each side, and cross-correlate with the reversed kernel . The first window gives , the third window gives , and the remaining windows reproduce . With one position is removed from each end, giving of length .
(Medium) A 2D Transposed Convolution
The input passes through a transposed convolution with kernel , stride and no padding.
Compute the output. Each input entry scales a copy of the kernel placed with its top-left corner at that entry's position. The entry contributes nothing, and the other three give The output size is in each direction. An ordinary convolution without padding would map a input back to , which confirms that the sizes have swapped.
(Hard) Spotting Uneven Overlap
Two decoders upsample the constant input with stride and no padding. One uses the kernel and the other uses .
Compute both outputs and explain which kernel shape avoids artifacts. Then give a kernel of size that turns stride-2 upsampling into linear interpolation. With the copies cover positions to , to , to and to , so the output is . A constant input produces an alternating pattern, because odd interior positions get two contributions and even positions get one. With the copies cover to , to , to and to , so the output is . Every interior position gets exactly two contributions, because is a multiple of the stride. The kernel with turns into . Its halved outer taps give the shared positions the same total weight as the others, so a constant input stays constant.
See Also
- 5.2.1. Convolutional Layer, whose backward pass is a transposed convolution.
- 5.2.2. Pooling, which max unpooling reverses.
- 5.2.4. CNNs, for encoder-decoder segmentation networks.
- 6.4. U-Net, which combines transposed convolutions with skip connections.
- 3.3. Image Interpolation and 2.3. Resampling, the image-processing view of upsampling.