10/12/26: Lect-07
Overview
Joseph Zambreno explains how convolutional neural networks address the parameter cost and lack of translation handling in MLP-based image classification by applying small, shared filters across local image regions. He develops the mechanics of convolution and cross-correlation, learned kernels, channels, padding, stride, pooling, and backpropagation, then connects them to PyTorch examples and the LeNet architecture for 28×28 grayscale MNIST images.
Key takeaways
- CNNs reduce the parameter burden of image classification by reusing a small kernel across spatial locations instead of learning separate weights for every input-output pixel pair.
- A convolutional layer's kernel values are learned through backpropagation, which lets the network discover useful image features rather than relying only on handcrafted edge or blur filters.
- Stacking local convolutional layers increases the effective receptive field, letting deeper features incorporate broader image context without starting with a fully connected image-wide layer.
- Padding, kernel size, and stride jointly determine feature-map dimensions; for a 5×5 kernel at stride 1, PyTorch padding 2 preserves the input height and width.
- Pooling has no learned weights: max pooling retains the strongest local activation, while average pooling smooths local responses, and either can downsample feature maps.
Chapters
- An MLP over image pixels does not naturally handle an object appearing at different locations.
- Using every pixel from a large image creates a model with many parameters and substantial data requirements.
- A sliding window applies the same detector across local regions, then combines the region-level results.
- Traditional image processing applies handcrafted filters for tasks such as blurring, sharpening, and edge detection.
- Building a face detector from manually designed oval, eye, and nose filters becomes increasingly complex and fragile.
- Handcrafted features remain useful when the relevant image properties are already known; CNNs learn filters when they are not.
- A fully connected image layer can assign a separate weight to every input-output pixel relationship, represented as a fourth-order tensor in the lecture's notation.
- Restricting outputs to a local neighborhood replaces that large set of connections with a compact kernel.
- The main distinction from traditional filters is that CNN kernel values are learned through backpropagation rather than set by hand.
- A convolutional kernel typically covers a small neighborhood, such as 3×3, 5×5, or 7×7 pixels.
- The same kernel is applied at multiple image locations, so its weights receive training signals from across the image.
- Stacking convolutional layers expands the effective receptive field, allowing later layers to combine information from larger regions.
- The signal-processing definition of convolution flips a filter, while the operation used in the lecture applies weights without that flip.
- This operation is technically cross-correlation, but learned weights can adapt to the chosen orientation.
- For image data, the continuous integral becomes a discrete multiply-and-accumulate operation over two spatial dimensions.
- A color image adds an input-channel dimension, such as three channels for RGB.
- A convolution can produce multiple output feature maps, with output depth D independent of input channel count C.
- The learned kernel becomes a fourth-order tensor spanning kernel height, kernel width, input channels, and output channels.
- For a 3×3 input and a 2×2 kernel, each output value is the sum of elementwise products within the current window.
- The first window computes 0×0 + 1×1 + 3×2 + 4×3 = 19.
- Scanning the kernel across the input produces a 2×2 output when no padding is applied.
- A 1×2 kernel with weights [1, -1] subtracts neighboring pixels and responds to horizontal changes.
- On a 6×8 binary image with a vertical black bar, the filter highlights transitions between white and black regions.
- Without padding, applying this kernel produces a 6×7 output; applying it to the transposed image yields no response to the unchanged direction.
- PyTorch convolution inputs include batch and channel dimensions, even for a single 6×8 grayscale sample.
- A Conv2d layer with one output channel, a 1×2 kernel, and no bias can be trained to reproduce the edge-filter output.
- The example uses a squared-error loss and gradient descent updates to learn weights close to the intended [1, -1] filter.
- Because the same kernel is reused across image locations, its gradient sums contributions from every window that affects the loss.
- The lecture calls the relevant input regions receptive fields and relates the term to visual responses in the brain.
- CNN gradients can still vanish or explode; small kernels, sensible initialization, and normalized inputs help manage the risk.
- Without padding, convolution outputs shrink, and border pixels contribute to fewer output values than central pixels.
- Padding adds a border, commonly zeros, before convolution so the output can retain the input's spatial dimensions.
- For a 3×3 kernel, PyTorch padding of 1 adds one pixel on each side; some textbook notation calls the total added border 2.
- Stride sets how many pixels the window advances between applications, rather than requiring a one-pixel step.
- A larger stride reduces computation and can downsample a feature map, such as turning a 512×512 representation into a smaller one.
- The worked example combines padding with horizontal stride 2 and vertical stride 3 to show how window positions determine outputs.
- Pooling applies a window to intermediate feature maps and reduces each region to one value without learning kernel weights.
- Max pooling preserves the strongest activation in each region, useful for checking whether a detector responded anywhere nearby.
- Average pooling smooths local activations, and both pooling and stride can reduce later-layer computation.
- A PyTorch MaxPool2d example reshapes values 0 through 15 into a 4×4 input and uses a 3×3 window, padding 1, and stride 2.
- The first window returns 5, and the next horizontal window returns 7 because each output is the largest value in its window.
- Drawing the window positions helps track how padding and stride jointly determine which input values contribute.
- A common CNN pattern alternates convolution, nonlinear activation, and optional pooling so stacked layers do not collapse into one linear operation.
- LeNet is introduced for 28×28 grayscale MNIST images, with a first convolution producing six feature maps.
- A 5×5 kernel with stride 1 preserves a 28×28 output when PyTorch padding is 2 on each side; the lecture leaves this padding calculation as a check for the next class.
Transcript excerpt
0:00 That's right. We can go ahead and get started. So, where we left off uh last week, we were starting to talk about kind of the limits of just our MLPS for doing larger scale image classification here. Can someone just quickly, if they can, summarize what's the issue with just using MLPS? Why is for our flower classification task, why can't we just take a look at what we' previously done and just apply to that task at hand? What what's one of multiple limiting problems with that? Right. So by default if we train an MLP it's not going to be location kind of invariant here. That's one big one. What else? There's others. What was our motivating example? The image we started with last week. There was the tiny little emnest image and then what was the other one? Kind of
0:47 funny gargoyle that I liked. What's the issue with that? Applying this approach of MLPs to the funny gargoyle image. Sure. In the back too large. >> Yep. Well, and and so right too large. If we said just take every uh input pixel of that as an input feature to our MLP, it is feasible. It's kind of on the border of feasibility. And even if one could build an MLP of that size just to do the classification, you still have the invariance shift invariance issue. And then you actually have enough data to train a model of that size because that's that's kind of our limiting factor. It's not quite as simple as saying as you need like you know one unique data input for every parameter you want to train but it's roughly on that order of magnitude that you want to have enough distinguishing things in your data set to be able to train your
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Joseph Zambreno.