induwara.lk
induwara.lkAI / Deep Learning

CNN Output Size Calculator — Conv, Pooling & Transposed Conv

Work out the exact output size of any Conv2d, pooling or ConvTranspose2d layer. Enter the input size, kernel, stride, padding and dilation to get H×W, the full (N, C, H, W) shape, parameters and FLOPs — plus a copy-ready PyTorch/Keras snippet. Uses the official PyTorch formulas, runs entirely in your browser.

By Induwara AshinsanaUpdated Jul 4, 2026
CNN layer output size
PyTorch-verified
Layer type
Presets

number, "same" or "valid"

Output size (H × W)
112 × 112
Tensor shape (N,C,H,W)
(1, 64, 112, 112)
Parameters
9.47K
9,472 (9,408 w/o bias)
Compute (MACs)
118.01M
≈ 236.03M FLOPs · per sample
Receptive field
7 px
Effective kernel: 7
Padding applied / side
3
H × W, per side
PyTorch
nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, dilation=1)
Keras / TensorFlow
layers.Conv2D(64, kernel_size=7, strides=2, padding="same", dilation_rate=1, use_bias=True)

Stack mode

No layers stacked yet. Configure a layer above and press Add layer to chain it. The chain starts from your input size (224×224×3).

Formulas from the official PyTorch Conv2d, ConvTranspose2d and MaxPool2ddocs, plus Dumoulin & Visin (arXiv:1603.07285). Sources cited in full below the tool. v1 assumes groups=1 and a square kernel.

How it works

Every convolution slides a kernel across the input and records one value per valid window position. The number of positions that fit is the output size. This tool implements the formulas exactly as published in the PyTorch layer documentation — nothing is estimated.

Convolution and pooling share one formula, applied independently to height and width:

H_out = floor( (H_in + 2·padding − dilation·(kernel − 1) − 1) / stride + 1 )

The dilation·(kernel − 1) term is the effective (dilated) kernel span. Pooling uses dilation 1 and keeps the channel count unchanged (C_out = C_in), while convolution sets C_out to the number of filters. With a pooling layer's ceil_mode on, the floor becomes a ceil; the calculator also applies PyTorch's rule that drops a trailing window which would start entirely inside the right-hand padding.

"same" and "valid" padding follow Keras/TensorFlow semantics. valid means no padding. same keeps the output equal to the input at stride 1 (padding = dilation·(kernel − 1) / 2) and gives ceil(H_in / stride) at larger strides. When the required total padding is odd, TensorFlow pads one side more than the other; the tool reports the correct output size and flags the asymmetry.

Transposed convolution (also called deconvolution or fractionally-strided convolution) reverses the spatial mapping and is used to upsample in GAN decoders and U-Net expansive paths:

H_out = (H_in − 1)·stride − 2·padding + dilation·(kernel − 1) + output_padding + 1

Parameters (groups = 1) are C_out·(C_in·kH·kW) + C_out, where the final term is the optional bias. Compute is reported as MACs (multiply-accumulates): for Conv2d, H_out·W_out·C_out·C_in·kH·kW per sample, with FLOPs ≈ 2 × MACs. Transposed conv is input-driven, so its MACs use H_in·W_in. The single-layer receptive fieldis dilation·(kernel − 1) + 1, and stack mode composes it across layers using the jump/receptive-field recurrence from Dumoulin & Visin.

Worked examples

ResNet-50 stem convolution

Conv2d(3 → 64, k=7, s=2, p=3) on a 224×224 image

  1. Effective kernel: 1·(7−1) + 1 = 7
  2. H_out = floor((224 + 2·3 − 7)/2 + 1) = floor(223/2 + 1) = 112
  3. Shape: (1, 64, 112, 112)
  4. Params: 64·(3·7·7) + 64 = 9,472 (9,408 without bias)
  5. MACs: 112·112·64·147 = 118,013,952 ≈ 118.0M (~236M FLOPs)

ResNet max-pool after the stem

MaxPool2d(k=3, s=2, p=1) on the 112×112×64 feature map

  1. Effective kernel: 3 (pooling uses dilation 1)
  2. H_out = floor((112 + 2·1 − 3)/2 + 1) = floor(111/2 + 1) = 56
  3. Shape: (1, 64, 56, 56) — channels unchanged
  4. Params: 0 (pooling has no learnable weights)
  5. This is the classic 56×56 map every ResNet paper opens with.

DCGAN decoder upsample (transposed conv)

ConvTranspose2d(256 → 128, k=4, s=2, p=1, output_padding=0) on 7×7

  1. H_out = (7−1)·2 − 2·1 + 1·(4−1) + 0 + 1
  2. = 12 − 2 + 3 + 1 = 14
  3. Shape: (1, 128, 14, 14) — a 2× upsample
  4. Params: 128·(256·4·4) + 128 = 524,416

Edge case — kernel larger than the input

Conv2d(k=7, s=1, p=0) on a 5×5 map

  1. H_out = floor((5 + 0 − 7)/1 + 1) = floor(−2 + 1) = −1
  2. Output ≤ 0, so no valid window fits.
  3. The tool flags this instead of returning NaN.
  4. Fix: add padding (p ≥ 1), shrink the kernel, or use a larger input.

Frequently asked questions

Sources & references

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] — most fixes ship within 24 hours.