Stack the layers of a convolutional neural network (CNN) and compute each layer's output size, the number of trainable parameters and the multiply-accumulate operations needed for inference. Check the output-size formula and how parameters are counted with worked examples.
Favorites and recently used calculators are stored only in this browser (localStorage).
Results
Output of the last layer
–
Total parameters
–
Total multiply-accumulates
–
Fractional heights and widths are rounded down. The MAC count is the number of multiply-add pairs for inference on one input; it excludes bias additions, activation functions and pooling.
See it as a graph
Other inputs stay at their current values while the chosen input varies from 1/4 to 4 times its current value. The red dot is the current value.
The output size formula
The output height (and likewise the width) of a convolution or pooling layer is ⌊(input + 2 × padding − kernel) ÷ stride⌋ + 1. It counts how many positions the kernel can take without sticking out as it slides over the input in steps of the stride. In the example "5×5 convolution and 2×2 pooling on a 28×28 image", (28 − 5) ÷ 1 + 1 = 24 gives 24×24, and the following 2×2 pooling with stride 2 gives (24 − 2) ÷ 2 + 1 = 12, so 12×12. A 3×3 kernel with padding 1 and stride 1 keeps the height and width unchanged.
Counting parameters
A convolution layer has kernel × kernel × input-channel weights for each output channel, plus one bias per output channel. The first layer of "LeNet-5" has 5 × 5 × 1 × 6 + 6 = 156. A fully connected layer has inputs × outputs + outputs, so the layer that connects 16 × 5 × 5 = 400 values to 120 has 400 × 120 + 120 = 48,120. Pooling and flatten have no parameters. LeNet-5 has 61,706 in total.
Multiply-accumulates and compute
In a convolution layer, each output value needs kernel × kernel × input-channel multiply-accumulates, repeated for every output position and channel. In the example "First VGG block", just two 3×3, 64-channel convolutions on a 224×224 image take about 1.9 billion MACs. Typically most parameters sit in the fully connected layers, while most compute sits in the early, high-resolution convolution layers.
Why convolution needs fewer parameters than full connection
A fully connected layer links every input value to every output value, so connecting a 32×32 image fully to six 28×28 outputs would need about 4.8 million weights. A convolution layer reuses the same small kernel at every position (weight sharing) and needs only 156. Locality, which looks at relationships between nearby pixels, and the ability to find the same feature wherever it appears are why CNNs suit images.
A fully connected layer has one weight for every pair of an input and an output, so there are 64 × 32 = 2048 weights. Adding the 32 biases, one per output, gives 2048 + 32 = 2080 parameters. In general, a fully connected layer with n inputs and m outputs has (n + 1) × m parameters. A convolutional layer reuses the same filter over the whole image, so it has far fewer parameters than a fully connected layer for an input of the same size.
The output size of a convolution is (N + 2P − F) ÷ S + 1, where N is the input size, F the filter size, P the padding and S the stride. (28 + 0 − 5) ÷ 1 + 1 = 24, so the output after convolution is 24×24. 2×2 max pooling with stride 2 keeps one maximum for each 2×2 region, halving the height and width to 12×12. Pooling has no trainable parameters; it shrinks the data to reduce computation and makes the network less sensitive to small shifts in position.
FAQ
What are padding and stride for?
Padding fills the border of the input with zeros or similar, so the output does not shrink too fast and edge pixels are used as often as central ones. Stride is the step by which the kernel moves; a stride of 2 roughly halves the height and width and is used instead of pooling to reduce resolution.
What happens when it does not divide evenly?
The fraction in the formula is rounded down. For example, pooling a height of 7 with kernel 2 and stride 2 gives (7 − 2) ÷ 2 + 1 = 3.5, so the output is 3 and the last row is not used. Some frameworks offer rounding up, or a "same" padding mode that pads automatically so the output is input ÷ stride.
Does the MAC count tell me the inference time?
It is a rough guide. One MAC is often counted as two operations (FLOPs), so 1.9 billion MACs is about 3.9 GFLOPs. Actual time depends strongly on how much data is read from and written to memory for weights and intermediate results, and on the parallelism of the hardware.
How does this appear in exams and courses?
Deep learning courses, interviews and certification exams often ask you to compute the output size from the input size, kernel, stride and padding, or to count the parameters of convolution and fully connected layers.