S1428 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

S14 · Lesson 28 · Regularization and convolutional networks

Weight decay, early stopping, dropout and data augmentation as ways to control a network's effective complexity, then convolutional layers with shared weights, their output sizes, parameter counts, operation counts and receptive fields

A network with millions of weights can memorize its training set, noise and all. Some cures are familiar from lesson 9, like penalizing large weights; others are specific to networks, like stopping early or randomly switching units off. The most effective cure, though, is building knowledge of the problem into the architecture. An image classifier shouldn't need to learn separately that an edge is an edge in every corner of the picture. A convolutional layer shares one small filter across all positions, which cuts the weights by orders of magnitude and makes the network's features shift along with the image. It's the FIR filter of DSP, learned from data.

  • A one-dimensional convolutional layer with a three-tap kernel (a, b, c) applied to a signal containing a rectangular pulse: y[n]=ax[n−1]+bx[n]+cx[n+1].
  • With (−1, 0, 1) it's an edge detector, firing at both edges with opposite signs, wherever the pulse sits. With (1, 1, 1)/3 it smooths.
  • The same three weights serve every position: that's weight sharing.

Predict

A 32 × 32 color image (3 channels) feeds a layer of 16 filters, each 5 × 5, with padding so the output is also 32 × 32. How many weights does the layer have?

Name it

Regularizing networks

  • Weight decay adds λ2‖𝐰‖2 to the error, so each step also shrinks the weights by a factor 1−ηλ: lesson 9's ridge penalty.
  • Early stopping halts training when the error on a validation set starts to rise. Weights start small and grow during training, so stopping early acts like a penalty on their size.
  • Dropout sets each hidden unit to zero with probability p during training, so units can't rely on one another. In the usual "inverted" form, surviving units are scaled by 1/(1 − p) during training so nothing changes at test time.
  • Data augmentation adds shifted, flipped or noisy copies of training examples, teaching the invariances directly.

Convolutional layers

A convolutional layer slides F filters of size K × K × C over an input with C channels. Each output is a weighted sum of a K × K patch plus a bias, and every position uses the same weights.

  • Parameters: K2CF+F, independent of the image size.
  • Output size along each dimension, with padding P and stride S: ⌊(N−K+2P)/S⌋+1.
  • Cost: each output value takes K2C multiply-accumulates.
  • Receptive field: stacking L layers of K × K with stride 1 lets each output see L(K−1)+1 inputs across; strides and pooling make it grow faster.

Pooling (max or average over a window) shrinks the maps and adds tolerance to small shifts.

Worked example

Count the parameters and multiply-accumulates of the predict question's layer, and the output size of a 3 × 3, stride-2 layer with no padding on the 32 × 32 output.

Show the solution
  1. Parameters. 5×5×3×16+16=1,216
  2. Multiply-accumulates. 32 × 32 × 16 outputs, 75 each: 32×32×16×75=1,228,800
  3. Stride-2 layer. Along each side: ⌊(32−3)/2⌋+1=15
  4. A first layer. 7 × 7 filters, stride 2 and padding 3 on a 224-pixel image give ⌊(224−7+6)/2⌋+1=112

Answer 1,216 parameters and 1,228,800 multiply-accumulates; the stride-2 layer's output is 15 × 15.

Worked example

How far does weight decay alone shrink a weight over 1000 steps with η = 0.01 and λ = 0.1? And what receptive field do five stacked 3 × 3 layers have?

Show the solution
  1. Weight decay. (1−0.001)1000=0.368≈e−1 A weight that the data don't support fades over about 1/(ηλ) steps.
  2. Receptive field. 5×2+1=11pixels across, the same as one 11 × 11 filter.
  3. Weights. The stack uses 5×9=45 weights per channel pair instead of 121.

Answer weight decay shrinks the weight to 0.368 of its value, and five 3 × 3 layers see 11 pixels across.

Worked example

A 3 × 3 convolution maps 256 channels to 256. How many weights does it have, and how many does a depthwise separable version (a 3 × 3 filter per channel, then a 1 × 1 convolution) need?

Show the solution
  1. Standard layer. 3×3×256×256=589,824
  2. Depthwise separable. depthwise=3×3×256=2,304pointwise=256×256=65,536 a total of 67,840.
  3. Ratio. 589,824/67,840=8.7 and the multiply-accumulates per output pixel fall by the same factor.
  4. Where it's used. Mobile networks are built from such layers, trading a little accuracy for nearly an order of magnitude less computation.

Answer the standard layer has 589,824 weights and the separable version 67,840, 8.7 times fewer.

Check

A 3 × 3 convolution with padding 2 and stride 2 is applied to a 32 × 32 input. How wide is the output?

Check

A layer has 512 filters of size 3 × 3 over 3 input channels. How many parameters does it have, with biases?

Check

A convolutional layer produces a 56 × 56 × 256 output with 3 × 3 filters over 128 input channels. How many multiply-accumulates does it take?

Check

5 convolutional layers of 3 × 3 filters with stride 1 are stacked. How wide is each final output's receptive field?

Check

Inverted dropout drops units with probability 0.2 during training. By what factor must surviving units be scaled?

Check

With learning rate 0.05 and weight decay λ = 0.001, what fraction of a weight remains after 60000 steps if the data's gradient on it is zero?

Check

A 5 × 5 convolution maps 32 channels to 256.

(a)

How many weights does a depthwise separable version need (no biases)?

(b)

By what factor does it cut the weights?

Check

A weight w with loss gradient g is updated by gradient descent with rate η and an L2 penalty λ2w2.

Step 1

What is the updated weight?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

Why do convolutional layers work so well for images, compared with fully connected layers?

Practice

Keep practicing

10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.