MIT 6.790 — Lecture 14
Convolutional Neural Networks
§ Motivating Convolutional Neural Networks
Remark. These notes assume familiarity with convolutions, specifically for 2D images. See 6.300 for reference.
Suppose we want to build a neural network for classifying images. How many parameters would we need?
Problem. Suppose we take a image as the input to a neural network. If the first hidden layer has features, then how many parameters connect the input layer to the first hidden layer?
Solution: The input layer has nodes, and the hidden layer has nodes, so the neural network between the input layer and the first hidden layer appears like a graph. That's a total of parameters, one for each edge.
(And that's assuming the image is grayscale; adding color complicates things even more!)
That's too many to feasibly perform backpropagation on. The issue isn't the number of nodes in the layers—it's the number of parameters needed to describe the relationship between them.
Maybe we don't need the full graph, though. Or maybe we don't need a unique parameter for every edge connecting an input node to the pre-activation of a node in the next layer.
Maybe there's a meaningful subfamily of linear maps on 2D images that requires far fewer parameters to specify…
§ Convolutions and Pooling
Technically, these 2D images aren't really 2D. Most images have color channels, too—three of them (RGB), to be precise. So more generally, we should think of each layer of our NN as being a three-dimensional grid of nodes.
The input layer might be a grid, for example. Importantly, our hidden layers might also have more than one channel. So our maps between layers must be able to meaningfully accept three-dimensional tensors as input.
We now introduce our two maps from 3D tensors to 3D tensors: pooling and convolving.
Definition. Given an image, we apply pooling to downsample the image down to .

The image above depicts max pooling. There's also average pooling—you can probably imagine how that looks.
Remark. Pooling always treats each channel independently of every other. It may be more accurate to view pooling as a map from 2D tensors to smaller 2D tensors; to apply pooling on 3D tensors, simply apply pooling on each channel separately.
Definition. Given an image, we may convolve it using a filter (with zero-padding). By sliding the filter along the width and height of the image, the resulting output is an image.

(The figure above omits zero-padding, so its output is smaller than its input.)
Remark. There are many possible variations of tensor convolution that one might imagine. For example, when sliding the filter, you might take a stride of length (say) . Then the output image instead has dimensions .

Ordinary convolution, by default, uses strides of length .
If we want the output of convolution to have more than one channel, we can simply stack convolutions together.
Definition. Given an image, we may perform stacked convolution using a tensor of parameters. This tensor contains different filters stacked together. Applying each of the filters to the input image yields different results. Stacking all results together yields an output image.
§ Convolutional Neural Networks
We can now put stacked convolution and pooling together to make a CNN. Here's an example.

Let's walk through how this CNN works.
The input image is a image of a happy face.
To reach the hidden layer, we apply a stacked convolution using a tensor of parameters.
The hidden layer is then a image.
To reach the hidden layer, we apply max pooling to downsample the image to .
To reach the hidden layer, we apply a stacked convolution using a tensor of parameters.
The hidden layer is then a image.
To reach the hidden layer, we apply max pooling to downsample the image to .
To reach the hidden layer, we apply a stacked convolution using a tensor of parameters.
The hidden layer is then an image.
To reach the hidden layer, we apply average pooling to downsample the image to .
The effect of average pooling here is to replace every channel with the average of all of its pixel values.
Finally, we interpret the hidden layer simply as nodes, and finish with an ordinary dense NN.
Since the output layer has nodes, this is a bipartite graph with edges (hence parameters).
And that's how a CNN works!
§ Commentary on CNNs
Some miscellaneous additional notes on CNNs:
Each stacked convolution only affects the number of channels, whereas each pooling only affects the width and height.
It was left unstated earlier, but after each convolution, a bias should be added to each cell, then a ReLU (or similar activation).
Each channel gets a different bias that is added to every cell in that channel.
So the stacked convolution with a tensor of parameters also requires bias parameters.
Compare the CNN above with an ordinary dense NN.
In a dense NN, reaching the first layer would require parameters.
In this CNN, reaching the first layer only requires parameters.
Max pooling isn't implementable in an ordinary NN. And it requires zero parameters in this CNN.
… something something, sparse matrices, something something …
Backpropagation is performed in the same way in CNNs as with NNs.
The main difference is that each parameter now affects multiple pre-activations, not just one. But this just amounts to having to do more additions in the backwards pass.
In practice, here's what the learned filters for the first hidden layer might look like.

A lot of these filters should make sense from a signal processing perspective.
There are a lot more things that can be said about CNN architecture, including the endless possibilities for variations on the overall structure. Here's the structure of AlexNet—a highly-successful image classifier released in 2012—for example.

But we won't get into too much detail on that here.