C.W.K.
Stream
Lesson 01 of 06 · published

Conv2D Explained — Filters, Strides, Padding

~13 min · conv2d, filter, stride, padding

Level 0Level 0
0 XP0/78 lessons0/17 achievements
0/100 XP to next level100 XP to go0% complete

The single layer that changed computer vision

A convolutional layer is the fundamental building block of image processing networks. Forget matrix multiplication for a moment — think about sliding a small window across an image.

A filter (kernel) is a small matrix — typically 3×3 or 5×5 — that slides across the input. At each position, it does element-wise multiplication with the local patch and sums the results. Sliding across the entire image produces a 2D feature map. A Conv2D layer with 32 filters applies 32 different filters, producing 32 feature maps stacked.

The key insight: weight sharing. The same 3×3 filter is applied at every position. This gives CNNs translation invariance (a cat detector works whether the cat is top-left or bottom-right) and extreme parameter efficiency. A Conv2D(64, 3) layer on 3-channel input has just (3×3×3 + 1) × 64 = 1,792 parameters — far fewer than a Dense layer touching the same spatial data.

Padding rules: 'same' zero-pads so output spatial size equals input. 'valid' doesn't pad, so output shrinks by kernel_size - 1.

Code

Conv2D 전체 시그니처·python
from keras import layers

conv = layers.Conv2D(
    filters=64,                # number of output feature maps
    kernel_size=3,             # 3x3, or (3, 5) for rectangular
    strides=(1, 1),
    padding='same',            # 'same' (preserve) or 'valid' (shrink)
    activation='relu',
    dilation_rate=(1, 1),      # >1 for atrous/dilated conv
    groups=1,                  # = input_channels for depthwise conv
    use_bias=True,
    kernel_initializer='glorot_uniform',
    kernel_regularizer=None,
)

# Shape rules:
# Input:  (batch, height, width, channels) — channels_last
# Output: (batch, new_h, new_w, filters)
# 'same' + stride=1: new_h = input_h
# 'same' + stride=2: new_h = ceil(input_h / 2)
# 'valid' + stride=1: new_h = input_h - kernel_size + 1

External links

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.