A convolutional layer applies learned filters across an input image or tensor to extract spatial patterns and produce feature maps. Unlike a dense layer that connects every input value to every output, it reuses the same filter weights as the filter moves across different areas. section 4.2.1 section 4.5.1
In PyTorch, nn.Conv2d configures the input channels, output channels, kernel size, stride, padding, and optionally bias. Input channels describe the image data; output channels describe how many feature types the layer can extract. section 4.2.1 section 4.5.1
A two-by-two filter over a three-by-three image
Represent a grayscale image as shape (1, 1, 3, 3), then create nn.Conv2d(in_channels=1, out_channels=1, kernel_size=2, stride=1). Setting the layer weights to [[1, 2], [3, 4]] with zero bias produces a 2-by-2 output. Each output value comes from element-wise multiplication of the filter and the current image patch, followed by summation.
Tune the layer by changing these arguments:
- Set in_channels to 1 for grayscale input or 3 for RGB input. section 4.2.1
- Set out_channels to choose how many learned feature maps the layer produces. section 4.2.1
- Increase stride to move the filter farther between positions and downsample the image; use padding to control border handling. section 7.4.1 section 4.5.1
Convolutional layers commonly appear in image classifiers and generative models. A DCGAN discriminator stacks them with batch normalization and LeakyReLU, while a VAE encoder uses them to compress images into latent vectors. Transposed convolutional layers reverse this spatial progression when a decoder or generator reconstructs images. section 4.5.1 section 7.4.1













