The key to DenseNet is making the input of each layer the concatenation of the outputs of all preceding layers.
Let x0β be the image entering the network, Hββ(β
) the transformation of the β-th layer, and xββ its output. In an ordinary CNN and in ResNet, each layer computes:
xββ=Hββ(xββ1β)(ordinaryΒ CNN)
xββ=Hββ(xββ1β)+xββ1β(ResNet)
ResNet adds the identity mapping so that gradients flow directly to earlier layers, but the paper points out that mixing by summation may impede the flow of information. A DenseNet layer computes:
xββ=Hββ([x0β,x1β,β¦,xββ1β])
[β
] denotes concatenation along channels. The feature maps of earlier layers reach all later layers as they are, without being mixed by addition.
One layer computes as follows:
- Concatenate the outputs of all preceding layers along the channel dimension.
- Apply batch normalization (BN), ReLU and a 3Γ3 convolution, in that order (following the pre-activation variant of ResNet).
- Pass the k output feature maps on to later layers.
Growth rate
The number of feature maps k produced by each layer is called the growth rate. If k0β feature maps enter a block, the input of the β-th layer has k0β+kΓ(ββ1) feature maps, growing by k per layer.
The paper views the whole set of feature maps as the network's "collective knowledge (global state)". Each layer merely appends its own k feature maps and leaves the rest unchanged. Once written, information can be read by any layer, so it does not have to be copied from layer to layer. This is why even narrow layers such as k=12 give sufficient accuracy.
Blocks and transition layers
Feature maps cannot be concatenated if their height and width differ, so the network is divided into several dense blocks. Inside a block, the height and width stay the same (3Γ3 convolutions use one pixel of zero padding on each side), and transition layers between blocks reduce them. A transition layer consists of BN, a 1Γ1 convolution and 2Γ2 average pooling.
DenseNet-B: bottleneck layers
Although each layer outputs only k feature maps, its input grows for later layers. A 1Γ1 convolution is therefore inserted before the 3Γ3 convolution to reduce the input to 4k feature maps before the 3Γ3 convolution (BN-ReLU-1Γ1 conv-BN-ReLU-3Γ3 conv). This is called DenseNet-B.
DenseNet-C: compression in transition layers
When a block outputs m feature maps, the 1Γ1 convolution in the transition layer reduces them to βΞΈmβ. ΞΈ (0<ΞΈβ€1) is called the compression factor, and the paper uses ΞΈ=0.5. A model with ΞΈ<1 is called DenseNet-C, and one that uses both bottleneck layers and compression is called DenseNet-BC.