Convolutional Neural Networks


Convolutional Neural Networks

Hope
Welcome back, Michael! Today we're diving into convolutional neural networks, the heart of this class. Ready to explore?

Michael
Absolutely! I remember last lecture we talked about stacking linear layers with non-linearities to form neural networks. Now we're adding convolutions to preserve spatial structure—that's fascinating.

Hope
Exactly. Before we jump into the mechanics, let's set the stage. The history of neural networks goes back to 1957 with Frank Rosenblatt's Mark I Perceptron—basically a linear score function with a step output.

Michael
Right, but they didn't have backpropagation back then. It wasn't until 1986 that Rumelhart introduced backprop, giving us a principled way to train these networks. Even then, scaling was tough until around 2006.

Hope
Yes, and in 2012, Alex Krizhevsky's AlexNet really kicked things off for image recognition with ConvNets on ImageNet. But the inspiration came much earlier from Hubel and Wiesel's experiments on cats in the 1950s.

Michael
Oh, I remember that! They found a topographic mapping from the retina to the visual cortex, and a hierarchical organization: simple cells responded to edges, complex cells to orientation and movement, and hypercomplex cells to corners and endpoints.

Hope
That directly inspired Fukushima's neocognitron in 1980, which had alternating simple and complex cell layers. Then Yann LeCun in 1998 applied backprop to train ConvNets for digit recognition—zip codes, actually.

Michael
And AlexNet scaled that up with more data and GPUs. Since then, ConvNets are everywhere: face recognition, self-driving cars, medical image diagnosis, even generating art like DeepDream and neural style transfer.

Hope
The core idea is simple: instead of flattening an image into a vector like in a fully connected layer, we keep the spatial structure. We slide small filters—say 5x5x3—over the image, computing dot products at each location.

Michael
So each filter produces an activation map that shows where certain patterns appear. If we have multiple filters, we stack them, resulting in an output volume of depth equal to the number of filters. That preserves spatial information.

Hope
And just like in neural networks, we stack layers: Conv, ReLU, then often a pooling layer to downsample. The filters learn hierarchies: first edges, then textures, then parts, then objects.

Michael
Let's talk about the dimensions. If we have a 7x7 input and a 3x3 filter with stride 1, the output size is (7-3)/1+1 = 5x5. But with stride 2, it becomes (7-3)/2+1 = 3x3. And if it doesn't divide evenly, we usually zero-pad.

Hope
Padding helps maintain spatial size and handles corners. A common choice is to pad so that output size equals input size: for a 3x3 filter, pad 1; for 5x5, pad 2; for 7x7, pad 3. That way you don't shrink too fast.

Michael
And the number of parameters? For 10 filters of size 5x5x3, plus a bias per filter, that's (5*5*3 + 1)*10 = 760 parameters. That's far fewer than a fully connected layer with the same input size!

Hope
Exactly. And the same filter weights are shared across all spatial positions—that's weight sharing, which makes ConvNets efficient and translation invariant. You can also have 1x1 convolutions, which just do a dot product across depth.

Michael
Now, pooling layers like max pooling downsample spatially. With a 2x2 filter and stride 2, the output size is halved. Max pooling takes the maximum in each region, giving some invariance to small shifts.

Hope
People sometimes use average pooling too, but max pooling is more common because it captures the strongest activation. And recently, some architectures use strided convolutions instead of pooling to downsample.

Michael
At the end of the ConvNet stack, we flatten the final volume and add one or more fully connected layers, followed by a softmax for classification. The final activations represent high-level concepts.

Hope
To summarize: ConvNets are stacks of Conv, ReLU, and Pool layers, then FC layers. Trends include smaller filters (3x3), deeper architectures, and sometimes removing pooling or FC layers entirely. Think ResNet and GoogLeNet.

Michael
Great overview. I'm excited to see how these architectures evolve and what we can do with them in our projects.

Hope
Absolutely—let your imagination go wild. Next time we'll dive into case studies of famous ConvNets. See you then!

Ask anything
We've read this whole study set, so questions about it get the best answers.