Convolution Operation
In deep learning, convolution operations transform inputs into spatial feature maps using a sliding window and parameterized filter kernels. Explore the interactive demonstration below to master receptive fields, Sobel edge detectors, and Frobenius inner products in real time.
Technical Overview: 2D Convolution Operations in Convolutional Neural Networks (CNNs)
A convolution operation in deep learning is a spatial mathematical transformation where a learnable matrix of weights called a filter kernel (such as 3×3 or 5×5) slides across an input image. At each step, it computes the Frobenius inner product (sum of element-wise products) between the kernel and the local input receptive field window:
S(i, j) = (I * K)(i, j) = ∑m ∑n I(i·s
+ m, j·s + n) K(m, n) + b
This produces an output feature map highlighting visual structures like horizontal edges, vertical boundaries, ridges, and textures.
Output Feature Map Dimension Formula
Given an input spatial dimension W, kernel size K, padding P, and stride S, the output
feature map dimension O is calculated by:
O = ⌊(W - K + 2P) / S⌋ + 1
Valid (0) vs. Same (1) Padding Modes
- Valid Padding (P = 0): No border zeros are added. Output shrinks from 28×28 to 26×26 with a 3×3 filter and stride 1.
- Same Padding (P = 1): A 1-pixel border of zeros surrounds the input. Output preserves spatial resolution at 28×28 with a 3×3 filter and stride 1.
Common 3×3 Convolution Kernels
- Sobel Horizontal (X):
[[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]— Detects vertical intensity transitions with central smoothing. - Sobel Vertical (Y):
[[-1, -2, -1], [0, 0, 0], [1, 2, 1]]— Detects horizontal intensity transitions. - Prewitt Horizontal (X):
[[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]]— Uniform edge detection. - Laplacian Ridge / Edge Detector:
[[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]]— Omnidirectional edge detector highlighting high-frequency curvature. - Gaussian Blur:
[[1/16, 2/16, 1/16], [2/16, 4/16, 2/16], [1/16, 2/16, 1/16]]— Low-pass smoothing filter removing high-frequency noise.