3.4.5 · D1Convolutional Neural Networks

Foundations — CNN architecture design

3,104 words14 min readBack to topic

Before you can read the parent architecture note, you need to own every symbol it throws at you. This page builds each one from nothing. Read top to bottom — each idea is a brick the next one stands on.


1. The image as a grid of numbers

Figure — CNN architecture design

Look at the figure. The height counts rows, the width counts columns, and the channel count counts how many grids are stacked. We write the whole thing as a shape:

  • (height) ::: number of rows of pixels — the picture is tall.
  • (width) ::: number of columns of pixels — the picture is wide.
  • (channels) ::: how many grids are stacked; 1 for gray, 3 for colour, and many more inside the network (each learned filter makes a new grid).

2. The filter (kernel) and the number

Figure — CNN architecture design

The little grid's side length is called (the kernel size). A filter has ; a filter has .

  • (kernel size) ::: the side length of the sliding filter grid; a filter has numbers inside it.

3. Stride , padding , and pooling — changing the grid size

Figure — CNN architecture design

In the figure, follow the coral filter box: with it lands on positions — every other spot — so half as many outputs come out along each direction.

Figure — CNN architecture design

Look at the pale border in the figure — those are the zero-pixels. With them, a filter centred on a corner still has neighbours to multiply, instead of hanging off the edge.

Figure — CNN architecture design

The figure shows a max-pool: each coloured block of the input collapses to a single output cell holding its largest value.

  • (stride) ::: the jump size of the sliding filter; larger makes a smaller output but throws away detail.
  • (padding) ::: extra pixels added on each side; keeps the grid from shrinking and lets corners be processed.

4. The receptive field — how much a neuron "sees"

Figure — CNN architecture design

Case A — stacked convs, stride 1, no shrinking. The parent uses:

  • What it says: start at (a single pixel sees itself), and each layer adds to the reach.
  • Why : a filter reaches one pixel left and one pixel right of centre, i.e. extra pixels of span.
  • What it looks like: in the figure, one output neuron (top) fans out through two layers until it touches a patch of the input (). ✓

5. Parameters and FLOPs — the two costs

The parent counts weights as . Adding the biases (one per output channel) gives the true total:

Read the weight term left to right: each of the output channels needs one filter; each filter is ( numbers) per input channel, and there are input channels — multiply them. Then add one bias for each of the outputs.

  • ::: the height and width of the output grid, from (and the same for ).
  • ::: channels going into and coming out of a layer — same as and .

6. The gradient and the "+1" trick

To reach an early weight, backprop multiplies many small rates together (the parent's long chain of ). Multiply many numbers below 1 and the product shrinks toward zero — that is the vanishing gradient problem.

Figure — CNN architecture design

7. Supporting cast (one line each)

  • Activation (ReLU) ::: a function applied after each layer; ReLU keeps positives, zeros negatives — adds the "nonlinearity" that lets stacked layers learn curved shapes.
  • Batch normalization ::: rescales each channel to a stable mean/variance during training so gradients behave.
  • Softmax ::: turns the final list of scores into probabilities that sum to 1.
  • FC (fully-connected) layer ::: every input connects to every output — used at the very end to make the class decision.
  • Concatenate (depth) ::: stack feature-grids from parallel branches into one taller stack (Inception uses this).

Prerequisite map

Image as grid H x W x C

Filter of size k

Cross-correlation slides the filter

Stride s Padding P and Pooling change grid size

Receptive field grows

Parameters equal k squared times channels plus bias

FLOPs cost per layer

Gradient flows backward

Vanishing gradient and the plus one skip

CNN Architecture Design


Equipment checklist

  • I can state what means for a picture ::: height rows, width columns, stacked grids (channels).
  • I know why channels grow inside a network ::: each learned filter produces one new feature-grid, so counts grids at that layer.
  • I can say what is and how many numbers a filter holds ::: is the filter's side; it holds numbers per input channel.
  • I know why CNN "convolution" is really cross-correlation ::: it slides the kernel without flipping it; learned weights absorb any flip.
  • I know two ways to shrink the grid and one way to keep it the same ::: stride or pooling shrink; padding (e.g. for ) keeps the size.
  • I can compute an output size from and name valid vs same padding ::: ; valid , same .
  • I know when pixels get dropped ::: when the floor discards leftover edge pixels.
  • I can define and compute for stacked stride-1 convs ::: = number of stacked conv layers; .
  • I can adjust RF for a stride or pool using the jump ::: , and multiplies by each stride.
  • I can state the parameter count of a conv layer with bias, defining and ::: , where are kernel/channels at layer .
  • I can derive the FLOPs formula (defining ) and why doubling channels balances pooling ::: cost per output number , times positions, times channels, plus bias adds.
  • I know what is ::: the channel count of the first stage (typically 64), doubled per stage as .
  • I know what means and why "+1" stops it vanishing ::: rate of change of error w.r.t. a weight; the skip path guarantees a nonzero gradient route.