Skip to content
StackDecode

Conv Shape Calculator

Track tensor shapes through stacked Conv2D, MaxPool and AvgPool layers.

NeweasyRuns in your browser

How it works

Each layer slides a window (the kernel) across the input. The output size along one spatial dimension is:

out=⌊in+2p−d (k−1)−1s⌋+1\text{out}=\left\lfloor\dfrac{\text{in}+2p-d\,(k-1)-1}{s}\right\rfloor+1
  • in: input height or width, k: kernel size, s: stride, p: padding on each side, d: dilation.
  • Height and width are computed independently, then rounded down: leftover pixels that don’t fill a full window are dropped.
  • Conv2D sets the channel count to out channels. MaxPool and AvgPool keep the channels unchanged.
  • Dilation inserts gaps in the kernel, making its effective size d·(k−1)+1. AvgPool has no dilation in PyTorch.
  • For pooling, PyTorch uses stride = kernel by default, so set the stride yourself if you rely on that.
  • If the effective kernel is larger than the padded input, the output would be empty and the tool reports an error instead of a shape.