Ravindra BagaleCourses & study guides मराठी Track your progress

47. Convolutional Neural Networks (CNNs) for Images

47.2 Convolution Intuition

Why. Convolution is the core verb — demystify it without heavy maths.

What. A filter (e.g. 3×3) multiplies a patch of pixels, sums them, and writes one number to a feature map. Sliding gives a whole map. Many filters → many maps.

How.

Mental demo

  1. Imagine a torch lighting a 3×3 patch of a shelf photo.
  2. Filter asks: “Is there a vertical edge here?”
  3. Move the torch across the image.
  4. Stack many filters for many questions.
import torch
import torch.nn as nn
conv = nn.Conv2d(in_channels=1, out_channels=4, kernel_size=3, padding=1)
x = torch.randn(2, 1, 28, 28) # 2 fake grayscale images
y = conv(x)
print(y.shape) # (2, 4, 28, 28) with padding=1

What you should see. Batch 2, 4 channels, spatial size kept with padding=1.