Ch 1 ▸ Why not a dense layer? ▸ Module 3/4
Counting parameters.
🔒 This module is locked
It builds on Dense layers. Pass that module’s knowledge check to unlock it, or skip ahead if you already know the material.
Every output of a dense layer has one weight per input and one bias. So a dense layer with inputs and outputs has
For an image, is the number of pixels, which grows with the square of the width. Double the width and there are four times as many pixels, so four times as many weights.
Real sizes
A 32×32 image has 1,024 pixels. A dense layer with 1,000 outputs on it has parameters.
Many image networks work on images 224 pixels on a side. That’s 50,176 pixels, and the same layer has parameters.
A phone photo is about 4,000 by 3,000 pixels, 12 million in all. A dense layer with 1,000 outputs on it has 12,000,001,000 parameters. Computers usually store each one in 4 bytes, so this one layer takes 48 gigabytes, more memory than most computers have. Using it means 12 billion multiplications for every photo. And this counts only grayscale, and only the first layer.
32×32 = 1,024 inputs × 1,000 outputs + 1,000 biases
1,025,000 PARAMETERS
4.1 MB TO STORE, AT 4 BYTES PER NUMBER · EACH OUTPUT ALONE HAS 1,024 WEIGHTS
Each mark is 1,000 times the one before it.
The convolution’s count
The rest of this book is about a different kind of layer, the convolution. Chapter 2 describes it in full; here is the part that matters for counting. A convolution has a small grid of weights, usually 3×3, and slides it across the image, computing one output at every position. The same nine weights are used at every position.
So a 3×3 convolution has 9 weights and 1 bias, 10 parameters, whatever the size of the image. It still produces one output per position, as many as there are pixels.
For a fair comparison, give a dense layer the same job: a 16×16 image in, 256 outputs out. It has parameters. The convolution does it with 10.
The convolution can get away with so few because it gives up something the dense layer has: each output reads only a small patch of the image, not all of it. The next module shows why that’s not a loss.
Knowledge check ▸ 4 questions
Before you move on.
Answer every question correctly to unlock the next module. A wrong answer gets a hint, and you can try again as many times as you like.
1A dense layer reads a flattened 64×64 image and has 10 outputs. How many parameters does it have?
2A dense layer reads a flattened 28×28 image and has 100 outputs. How many parameters does it have?
3How many parameters does one 3×3 convolution with one bias have when it runs on a 1000×1000 image?
4A dense layer turns a flattened 16×16 image into 256 outputs, one per pixel, like a convolution would. How many parameters does it have?