Shapes

CNN layer shape & parameter calculator. Exact PyTorch arithmetic, fp32, in your browser.

Presets
Actions
Trainable params 0
Param memory 0 B params × 4 B
Activations 0 B sum of layer outputs × N × 4 B
Output —
In
InputN × C × H × W
—
    Add layer

    PyTorch

    only non-default kwargs; in_channels / in_features inferred

    Formulas

    Conv2d / pooling
    H_out = floor((H + 2p − d·(k−1) − 1) / s + 1), with ceil for pooling when ceil_mode=True (and the last window must start inside the input or left padding). Same for W.
    Conv2d params
    out · (in / groups) · kh · kw (+ out if bias)
    BatchNorm2d
    2 · C trainable (weight, bias). running_mean, running_var and num_batches_tracked are buffers, not counted.
    Linear
    in · out (+ out if bias). Needs a 1D input: put a Flatten after the last 4D layer.
    Memory
    Activation = output numel × N × 4 bytes (fp32), forward only. Param memory = params × 4 bytes.
    Warnings
    If H + 2p − d·(k−1) − 1 is not divisible by the stride, PyTorch floors silently and drops the last rows/columns. Shown as a warning; shape propagation continues. Errors stop it.

    Kernel, stride, padding and dilation take n or h,w (a dot also works as separator, for phone keypads). Pool stride left empty means stride = kernel_size. The model is stored in the URL, so links reproduce it.