Search

Search papers and lessons

Densely Connected Convolutional Networks

Gao Huang, Zhuang Liu, Laurens van der Maaten et al. · 2016

DenseNet gives every layer the feature maps of all earlier layers in its block, joined by concatenation, which eases gradient flow, reuses features and needs fewer parameters than ResNets.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Neural network basics
  • Linear algebra
  • Probability
  • Architectures
  • ReadReady to readNot yet

TL;DR

DenseNet is a convolutional network in which each layer receives the feature maps of every earlier layer in its block, stacked side by side rather than added together. Each layer adds only a few new maps, so features are reused and every layer has a short path to the loss. The paper reports lower error than the previous best on most CIFAR and SVHN settings, and ImageNet accuracy on par with ResNets using fewer parameters.

Builds on: Convolutional Neural Network, Residual Connection, Batch Normalization, Rectified Linear Unit (ReLU) · Leads to: no node yet; the idea of reusing every earlier feature map by concatenation

Why it mattered

The paper is the standard reference for dense connectivity in image classifiers, and its benchmark numbers were a yardstick for the architectures that followed. Three concrete places where it mattered:

  • ImageNet. The authors kept the public Torch ResNet training code and changed only the network, so the comparison is fair. A DenseNet-201 with about 20M parameters reaches a validation error similar to a 101-layer ResNet with more than 40M parameters.
  • CIFAR and SVHN. On CIFAR-10 with augmentation, the 190-layer DenseNet-BC with growth rate 40 reaches 3.46% error. The paper's best wide ResNet comparison, a 28-layer model with 36.5M parameters, reaches 4.17%. On CIFAR-100 with augmentation the same DenseNet reaches 17.18%, against 20.50% for that wide ResNet.
  • GPU memory. The authors note that a naive DenseNet implementation can waste memory, and they point to a separate memory-efficient implementation report (Pleiss et al., arXiv:1707.06990). With dense concatenation, memory use can become the practical limit even when the parameter count is small.

The problem

As networks get deeper, the signal from the input and the gradient from the loss can fade as they pass through many layers. The paper calls this a "wash out" problem. Vanishing gradients are the training-time form of it: the learning signal reaching early layers becomes very small.

Earlier architectures attacked this by creating short paths from early layers to late ones. ResNets add the block input back to its output. Highway networks use gated bypasses, stochastic depth drops layers during training, and FractalNets combine parallel paths. The paper's observation is that all of these share one property: they create short paths.

ResNets do this with a sum, and the paper argues the sum can impede information flow, because the layer output and the carried signal are blended into one tensor. The question the paper asks is how to connect layers so that every layer sees everything before it, without that blending.

How it works

Take a tiny dense block. Its input has 8 feature maps, and the growth rate is k = 4, meaning each layer produces 4 new maps. A feature map is one channel of a grid of numbers. "Concatenation" means stacking the channels of two tensors, so 8 maps and 4 maps become 12 maps. Nothing is added together.

  1. The input x0 has 8 feature maps. Layer 1 reads those 8 maps and produces 4 new maps, x1. Check: 8 in, 4 out.
  2. Layer 2 reads x0 and x1 stacked together: 8 + 4 = 12 maps. It produces 4 new maps, x2. Check: the input count is the block input plus the outputs of the earlier layers.
  3. Layer 3 reads x0, x1 and x2: 8 + 4 + 4 = 16 maps. It produces 4 new maps, x3. Check: 16 = 8 + 2 × 4.
  4. Layer 4 reads x0 through x3: 8 + 4 + 4 + 4 = 20 maps. It produces 4 new maps, x4. Check: 20 = 8 + 3 × 4.
  5. The block's output is all the maps stacked together: 8 + 4 × 4 = 24 maps. Later layers, and the transition to the next block, read this full stack.

The growth rate is the number of new maps each layer contributes to the shared stack. Each layer's function is a composite of three operations: batch normalization, then a ReLU, then a 3 × 3 Convolution. The paper calls this H.

flowchart LR
  x0["x0 (8 maps)"] --> L1["layer 1 (+4)"]
  x0 --> L2["layer 2 (+4)"]
  L1 --> L2
  x0 --> L3["layer 3 (+4)"]
  L1 --> L3
  L2 --> L3
  x0 --> L4["layer 4 (+4)"]
  L1 --> L4
  L2 --> L4
  L3 --> L4

Every arrow in the diagram is a direct connection. A plain stack of the same four layers would have only three arrows between them.

Blocks are separated by transition layers. Concatenation only works when the feature-map size is fixed, so the network is split into several dense blocks, and each transition layer (batch normalization, a 1 × 1 convolution, then 2 × 2 average pooling) halves the spatial size before the next block.

The math

Definition: Dense connectivity

Layer ℓ of a dense block computes its output xℓ\mathbf{x}_{\ell} from the concatenation of the outputs of all earlier layers, x0\mathbf{x}_0 up to xℓ−1\mathbf{x}_{\ell-1}, where x0\mathbf{x}_0 is the block input. Square brackets denote concatenation along the channel axis.

Step 1 in symbols: the layer

The output of layer ℓ is

xℓ=Hℓ([x0,x1,…,xℓ−1])\mathbf{x}_{\ell} = H_{\ell}\big([\mathbf{x}_0, \mathbf{x}_1, \ldots, \mathbf{x}_{\ell-1}]\big)

The bold letters are tensors, here stacks of feature maps. H_ℓ is batch normalization, then ReLU, then a 3 × 3 convolution. Compare the ResNet rule, where the layer reads only xℓ−1\mathbf{x}_{\ell-1} and the output is added back: xℓ=Hℓ(xℓ−1)+xℓ−1\mathbf{x}_{\ell} = H_{\ell}(\mathbf{x}_{\ell-1}) + \mathbf{x}_{\ell-1}.

Step 2 in symbols: counting the input channels

If every H_ℓ produces k maps, layer ℓ receives

k0+k(ℓ−1)k_0 + k(\ell - 1)

input maps, where k_0 is the number of input channels. In the tiny block (k_0 = 8, k = 4), layer 4 has 8 + 4 × 3 = 20 inputs, as in step 4 of the walkthrough.

Step 3 in symbols: counting connections

Layer ℓ takes ℓ inputs (x_0 up to x_(ℓ-1)), so an L-layer block has the sum of 1 through L direct input connections:

∑ℓ=1Lℓ=L(L+1)2\sum_{\ell=1}^{L} \ell = \frac{L(L+1)}{2}

A plain feed-forward network has only L connections, one from each layer to the next. For L = 5 the dense count is 15 and the plain count is 5. The dense count grows with L squared, while the plain count grows linearly.

24681012020406080L (layers in the block)direct connections
  • dense: L(L+1)/2
  • plain: L
The dense count grows quadratically. At L = 5 the dense block has 15 connections against 5 for a plain stack.

Beyond the walkthrough: bottleneck and compression

The tiny block above skips two refinements that the paper uses in its larger networks. The layer produces k maps but reads many more, so the paper's DenseNet-B form puts a 1 × 1 convolution with 4k output maps in front of each 3 × 3 convolution. Between blocks, a transition layer with compression factor θ, where 0 < θ ≤ 1, outputs ⌊θm⌋ maps when the preceding block has m maps. The paper uses θ = 0.5. A network with both the bottleneck and compression is called DenseNet-BC.

For example, a block with k = 12 and 6 layers, starting from 24 input maps, ends with 24 + 12 × 6 = 96 maps. The transition outputs ⌊0.5 × 96⌋ = 48 maps, so the next block starts from 48 rather than 96.

Results

All numbers below are copied from the paper's Tables 2 and 3 and its text. Error rates are percentages, and parameter counts are the paper's.

  • CIFAR-10 with augmentation (C10+). DenseNet-BC with L = 190 and k = 40 reaches 3.46% error with 25.6M parameters. The wide ResNet with depth 28 in the table reaches 4.17% with 36.5M parameters.
  • CIFAR-100 with augmentation (C100+). The same DenseNet-BC reaches 17.18%, against 20.50% for that wide ResNet.
  • CIFAR without augmentation. DenseNet-BC with L = 250 and k = 24 reaches 5.19% on C10 and 19.64% on C100, against 7.33% and 28.20% for FractalNet with dropout and drop-path. The paper says its improvements over prior work are particularly pronounced on datasets without augmentation.
  • SVHN. A DenseNet with L = 100 and k = 24, trained with dropout, reaches 1.59%, against 1.64% for a wide ResNet with dropout.
  • Capacity. Without compression or bottleneck, error on C10+ falls from 5.24% (1.0M parameters, L = 40, k = 12) to 4.10% (7.0M, L = 100, k = 12) to 3.74% (27.2M, L = 100, k = 24).
  • Parameter efficiency. DenseNet-BC with L = 100 and k = 12 reaches 4.51% on C10+ with 0.8M parameters. The 1001-layer pre-activation ResNet reaches 4.62% with 10.2M parameters. The paper describes this as "90% fewer parameters".
  • ImageNet. The paper reports that a DenseNet that requires as much computation as a ResNet-50 performs on par with a ResNet-101, which needs about twice as much computation.

Limits the paper states or implies: the 250-layer model does not improve on the 100-layer model on SVHN, which the authors attribute to overfitting on an easier task. Each task and setting was evaluated once. The ImageNet experiments used hyperparameters tuned for ResNets, so DenseNet results may be conservative. A naive implementation can be memory-hungry.

Reading guide

The paper's sections, in order, with the lessons they lean on:

Check yourself

QuestionHow many direct connections does a dense block with L layers have, in total, and how many does a plain stack of L layers have?Show answer

The dense block has L(L+1)/2 direct connections, because layer ℓ takes ℓ inputs and the sum of 1 through L is L(L+1)/2. A plain stack has L, one from each layer to the next. For L = 5 that is 15 against 5.

QuestionA dense block has input k_0 = 10 maps and growth rate k = 8. How many input maps does layer 7 receive?Show answer

Layer ℓ receives k_0 + k(ℓ − 1) = 10 + 8 × 6 = 58 maps. The answer is 58.

QuestionWhy does DenseNet concatenate feature maps instead of adding them as ResNet does, and what does it cost?Show answer

Concatenation keeps every earlier feature map separate and available to later layers, so the network can reuse features and no information is blended away by a sum. The cost is that the stack grows with every layer, which uses more memory during training. The paper's memory-efficient implementation exists for that reason.

QuestionA small dataset must be classified under a strict parameter budget, but the GPU memory is limited. Would you choose DenseNet-BC or a ResNet, and why?Show answer

DenseNet-BC suits a tight parameter budget, because the paper reports that it reaches comparable accuracy with far fewer parameters, and that the bottleneck and compression layers counter overfitting. GPU memory is the risk, because the concatenated stack grows with depth. A good answer names that tradeoff and suggests measuring memory with an efficient implementation before committing.

Sources

Read the full paper

Gao Huang, Zhuang Liu, Laurens van der Maaten et al., 2016. arXiv:1608.06993