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 1000 px×1000 px1000\,\mathrm{px} \times 1000\,\mathrm{px} image as the input to a neural network. If the first hidden layer has 10001000 features, then how many parameters connect the input layer to the first hidden layer?

Solution: The input layer has 10610^6 nodes, and the hidden layer has 10310^3 nodes, so the neural network between the input layer and the first hidden layer appears like a K106,103K_{10^6, 10^3} graph. That's a total of 109\boxed{10^9} 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 K106,103K_{10^6, 10^3} 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 H×W×CH \times W \times C grid of nodes.

The input layer might be a 1000×1000×31000 \times 1000 \times 3 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 H×W×CH \times W \times C image, we apply pooling to downsample the image down to H′×W′×CH' \times W' \times C.

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 H×W×CH \times W \times C image, we may convolve it using a Y×X×CY \times X \times C filter (with zero-padding). By sliding the filter along the width and height of the image, the resulting output is an H×W×1H \times W \times 1 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) 22. Then the output image instead has dimensions H2×W2×1\frac{H}{2} \times \frac{W}{2} \times 1.

Ordinary convolution, by default, uses strides of length 11.

If we want the output of convolution to have more than one channel, we can simply stack convolutions together.

Definition. Given an H×W×CH \times W \times C image, we may perform stacked convolution using a Y×X×C×C′Y \times X \times C \times C' tensor of parameters. This tensor contains C′C' different Y×X×CY \times X \times C filters stacked together. Applying each of the C′C' filters to the input H×W×CH \times W \times C image yields C′C' different H×W×1H \times W \times 1 results. Stacking all C′C' results together yields an H×W×C′H \times W \times C' 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.

And that's how a CNN works!

§ Commentary on CNNs

Some miscellaneous additional notes on CNNs:

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.