A convolutional neural network processes an image by applying small grids of numbers, called
kernels or filters, to local pixel neighborhoods. Draw on the 32×32 canvas, choose a 3×3 kernel,
and inspect the multiply-and-sum operation that creates each output value.
What the operation does
Center the 3×3 kernel on an input location, multiply each of its nine entries by the aligned
pixel value, and add the products. The sum becomes one output value. Then move the window and
repeat. Most deep-learning libraries implement this operation as cross-correlation
because the kernel is not flipped; it is commonly called convolution in CNN practice.
The Sobel-X kernel estimates change in the horizontal coordinate. It responds strongly where
brightness changes from left to right, so it highlights mostly vertical edges. Positive and
negative responses represent opposite edge directions.
An edge map begins with local arithmetic, not object recognition. The kernel produces a large
magnitude when the pattern of nearby pixel values aligns with the differences encoded in its weights.
Absolute value and ReLU
Taking an absolute value discards response direction and keeps magnitude, so both light-to-dark
and dark-to-light transitions appear bright. ReLU instead replaces negative values with zero.
Many CNN blocks use an activation after a convolution, but architectures vary. One learned channel
may preserve a response orientation while another channel learns a complementary filter; no single
ReLU channel should be assumed to preserve all information.
Pooling and receptive fields
- Convolution plus 2×2 max pooling: each 2×2 output region is reduced to its
numerically largest value, not necessarily the value with largest magnitude when signed responses are present. Resolution is halved, computation falls, and small translations may affect the
pooled representation less.
- Two stacked 3×3 convolutions: with stride one and suitable padding, each
final output depends on a 5×5 region of the original input. Stacking
n such layers
gives a theoretical receptive-field width of 2n + 1.
Small kernels are common because stacking them expands the receptive field while inserting
nonlinear transformations between layers. Two 3×3 kernels use 18 spatial weights versus 25 for
one 5×5 kernel per input-output channel pair, before biases and channel counts are considered.
VGG popularized this design, although modern architectures also use 1×1, 5×5, 7×7, dilated, and
larger depthwise kernels when useful.
From one kernel to many channels
A real CNN layer applies multiple learned kernels across all input channels. Each kernel produces
an output feature map, and the stack of maps becomes the next layer's representation. Early
features often resemble oriented edges or color contrasts; later features can combine simpler
patterns into textures, parts, and task-relevant structures. These interpretations are tendencies,
not fixed labels assigned to every channel.
What this model leaves out
Practical CNNs use kernels with height, width, and channel dimensions; learned biases; padding and
stride choices; normalization; residual connections; and backpropagation through all operations.
The applet isolates the local computation and the distinction between hand-designed and learned filters.
For teachers
Curriculum: Cross-correlation as multiply-and-sum, kernels, feature maps,
edge direction, activation functions, pooling, receptive fields, and learned filters.
Pre-exploration prompts:
- How could nine numbers detect a local brightness change?
- Why might one filter respond to vertical edges and another to horizontal edges?
- What information is lost when a response is replaced by its absolute value or clipped by ReLU?
Post-exploration prompts:
- Draw vertical and horizontal lines, then compare Sobel-X and Sobel-Y.
- Inspect one output location and verify every multiplication before revealing the sum.
- Compare convolution followed by pooling with two stacked convolutions. Which quantities change?
- Use the learner-versus-target view. Why can one example fail to determine a unique kernel?
Misconceptions to test: the operation already recognizes objects; Sobel-X
detects horizontal edges because of its name; every convolution must be followed by ReLU;
modern networks use only 3×3 kernels.
卷积神经网络通过把称为卷积核或滤波器的小型数字网格应用到局部像素邻域来处理图像。你可以在 32×32 画布上绘图,选择 3×3 卷积核,并检查生成每个输出值的乘加过程。
这一运算做了什么
把 3×3 卷积核对准一个输入位置,将九个核值分别与对应像素相乘,再把乘积相加。这个和成为一个输出值。随后移动窗口并重复。多数深度学习库实际执行的是互相关,因为卷积核没有翻转;在 CNN 语境中仍通常称为卷积。
Sobel-X 核估计水平方向坐标上的变化。它对亮度从左向右的变化反应强烈,因此主要突出垂直边缘。正响应与负响应表示相反的边缘方向。
边缘图首先来自局部算术,而不是物体识别。当邻近像素模式与卷积核权重编码的差分结构一致时,输出幅度就会较大。
绝对值与 ReLU
取绝对值会丢弃响应方向并保留幅度,因此由亮到暗和由暗到亮的变化都会显示为明亮边缘。ReLU 则把负值替换为零。许多 CNN 模块会在卷积后使用激活函数,但架构并不完全相同。一个学习到的通道可能保留某一方向响应,另一个通道可能学习互补滤波器;不能假设单个经过 ReLU 的通道保留了全部信息。
池化与感受野
- 卷积加 2×2 最大池化:每个 2×2 输出区域只保留最大值。分辨率减半,计算量降低,小幅平移对池化表示的影响也可能减小。
- 两个堆叠的 3×3 卷积:在步幅为一并使用适当填充时,最终每个输出依赖原始输入中的 5×5 区域。堆叠
n 个此类层会得到宽度为 2n + 1 的理论感受野。
小卷积核很常见,因为堆叠可以扩大感受野,并在层之间插入非线性变换。对每一对输入和输出通道而言,两个 3×3 核使用 18 个空间权重,一个 5×5 核使用 25 个,尚未计入偏置和通道数量。VGG 推广了这种设计,不过现代架构也会按需要使用 1×1、5×5、7×7、空洞卷积和更大的深度卷积核。
从一个卷积核到多个通道
真实 CNN 层会在所有输入通道上应用多个学习到的卷积核。每个核产生一个输出特征图,多个特征图组成下一层表示。早期特征常类似有方向的边缘或颜色对比,后期特征可把简单模式组合为纹理、局部部件和任务相关结构。这些是常见趋势,并不是每个通道都具有固定的人类标签。
这个模型省略了什么
实际 CNN 使用具有高度、宽度和通道维度的卷积核、学习到的偏置、不同填充与步幅、归一化、残差连接,以及穿过全部运算的反向传播。本工具集中呈现局部计算,以及手工滤波器与学习滤波器的区别。
教师指导
课程目标:把互相关理解为乘加、卷积核、特征图、边缘方向、激活函数、池化、感受野和学习滤波器。
探索前问题:
- 九个数字如何检测局部亮度变化?
- 为什么一个滤波器可能响应垂直边缘,另一个响应水平边缘?
- 取绝对值或用 ReLU 截断时会丢失什么信息?
探索后问题:
- 绘制垂直线和水平线,再比较 Sobel-X 与 Sobel-Y。
- 检查一个输出位置,在显示总和前验证每一次乘法。
- 比较卷积后池化与两个堆叠卷积。哪些量发生变化?
- 使用学习者与目标视图。为什么一个样本无法确定唯一卷积核?
需要检验的误解:该运算已经在识别物体;Sobel-X 因名称而检测水平边缘;每个卷积后都必须使用 ReLU;现代网络只使用 3×3 卷积核。