步幅、填充与池化
控制输出大小并进行下采样
步幅、填充与池化 是 CoddyKit 上的免费 Deep Learning Academy 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Deep Learning Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Deep Learning Academy 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Output Shrinks by Default
When a 3x3 kernel slides over an image, the edges have no room. So the output feature map comes out a little smaller than the input.
Padding Adds a Border
Padding wraps the image in a ring of zeros so the kernel can reach the corners. Now the output can stay the same size as the input.
Same Padding in Code
For a 3x3 kernel, padding of 1 keeps the spatial size unchanged. People call this same padding.
conv = nn.Conv2d(3, 16, kernel_size=3, padding=1)Stride Sets the Step Size
Stride is how far the kernel jumps each move. A stride of 1 visits every position; a larger stride skips ahead.
Stride 2 Halves the Map
With stride 2 the kernel hops two pixels at a time, so the output is roughly half the width and height. It is a cheap way to downsample. ⬇️
Stride and Padding Together
Combine them to control the exact output size. Here stride 2 with padding 1 downsamples while keeping the corners covered.
conv = nn.Conv2d(16, 32, 3, stride=2, padding=1)Why Downsample at All?
Shrinking the maps cuts computation and lets later layers see a wider region of the original image with each kernel.
Pooling: Another Way to Shrink
Pooling downsamples too, but with no learned weights. It just summarizes each small patch into a single value.
Max Pooling Keeps the Strongest
Max pooling takes the largest value in each 2x2 patch. It keeps the strongest signal and quietly drops the rest.
pool = nn.MaxPool2d(kernel_size=2)Average Pooling Smooths
Average pooling takes the mean of each patch instead of the max, giving a smoother, gentler summary of the region.
pool = nn.AvgPool2d(kernel_size=2)Pooling Adds Small Invariance
Because pooling summarizes a patch, a tiny shift in the input barely changes the output. This gives a touch of translation invariance.
Quick Check
Let us test what padding actually does for a convolution.
Recap: Control the Shape
You learned that padding preserves size, stride sets the step and downsamples, and pooling shrinks maps while adding a little shift tolerance. 🎯
常见问题解答
「步幅、填充与池化」课时是免费的吗?
是的 — 「步幅、填充与池化」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Deep Learning Academy 课程的其余内容,请升级到 CoddyKit PRO。 Deep Learning Academy 课程共包含 4 节课。
「步幅、填充与池化」这节课中我会学到什么?
控制输出大小并进行下采样 你通过在浏览器中直接运行的动手代码来练习 Deep Learning Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Deep Learning Academy 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Deep Learning Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。
「步幅、填充与池化」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Deep Learning Academy 课中编写并运行代码吗?
能。每节 Deep Learning Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。