What Does Conv2d Output with 32×32 Input and Kernel 5?

Conv2d with 32×32 input, kernel_size=5, stride=1, padding=0 outputs 28×28. Formula: (32 - 5 + 0) / 1 + 1 = 28. Without padding, the kernel can't reach the edges.

Formula Breakdown

output_size = (input_size - kernel_size + 2 * padding) / stride + 1

Plugging in the values:

output = (32 - 5 + 2*0) / 1 + 1
output = (32 - 5 + 0) / 1 + 1
output = 27 / 1 + 1
output = 28

PyTorch Code

import torch
import torch.nn as nn

# Classic LeNet-style first conv on CIFAR-10
conv = nn.Conv2d(3, 6, kernel_size=5) # default stride=1, padding=0
x = torch.randn(1, 3, 32, 32)
output = conv(x)
print(output.shape) # torch.Size([1, 6, 28, 28])

Where This Appears

This configuration is the classic LeNet-5 first layer used with CIFAR-10 (32×32 images). Without padding, a 5×5 kernel loses 2 pixels on each side, shrinking 32 to 28. If you want to preserve the spatial size, add padding=2: output = (32 - 5 + 2×2) / 1 + 1 = 32.

Try the Conv2d Calculator

TENSOR PREFLIGHT · DOWNLOADABLE PYTORCH TOOLKIT

Take the next step in your own PyTorch model.

Trace a local forward pass, inspect tensor shapes in an HTML report, and turn a repair into a regression check. Includes eight broken-and-fixed workflows, source code and setup instructions.

Is this toolkit right for my problem?

Use the free calculator for a layer formula or a quick shape check.

Consider Tensor Preflight when you have a local PyTorch model and want a forward-pass report plus repeatable checks. Python 3.9+ and PyTorch 2.8+ are required. It does not run your model in this website or automatically repair it.

Open the sample report before buying to check the output format.

Python 3.9+ · PyTorch 2.8+ · Runs locally

Get Tensor Preflight — $29 One-time payment · ZIP download See a sample report
By the same builder: GitHub, theluckystrike BeLikeNative, Grammar AI EarlyThunder, Dev Blog Bug Bounty Reality Zovo, AI Dev Tools