# Model answer: shape, activations and parameters

Subject: Deep Learning

Exam: TEE

Reader: https://deep-learning-study-room.vercel.app/#tee/read/7/tee-c7-s13

Canonical: https://deep-learning-study-room.vercel.app/read/dl/tee/section/tee-c7-s13/

## Question

**Question.** Distinguish a CNN layer's output shape, number of output activations and number of trainable parameters. Explain the formulas used to calculate them.

## Answer — step by step

Output shape tells how the produced values are arranged. The activation count tells how many values were produced for one input. Parameter count tells how many learned weights and biases define the layer. These are three different questions.

![Keep output shape, activation count and parameter count as three separate quantities.](https://deep-learning-study-room.vercel.app/assets/figures/v_parameters_activations.svg)

Diagram: Keep output shape, activation count and parameter count as three separate quantities.. Labels: Learned parameters are not output activations | Learned parameters are not output activations | Example: a 5 × 5 × 1 input with one 3 × 3 filter, stride 1, no padding. | Learned filter | 3 × 3 × 1 = 9 weights | Plus one bias | Total parameters = 10 | Output feature map | (5 − 3)/1 + 1 = 3 | Shape = 3 × 3 × 1 | Total activations = 9 | The same ten parameters are reused to calculate all nine output values.

Keep output shape, activation count and parameter count as three separate quantities. Tap the diagram to enlarge.

### Spatial output shape

For an ordinary convolution with dilation 1:



$$
N_{\mathrm{out}}=\left\lfloor\frac{N+2P-K}{S}\right\rfloor+1
$$



N is the incoming spatial size, P is padding on each side, K is kernel size and S is stride. Apply the rule independently to height and width. The number of output channels is the number of filters.

### Output activations



$$
A=H_{\mathrm{out}}W_{\mathrm{out}}C_{\mathrm{out}}
$$



This is the number of output values for one example, excluding any batch dimension.

### Trainable parameters



$$
P_{\mathrm{conv}}=(K_hK_wC_{\mathrm{in}}+1)C_{\mathrm{out}}
$$



Each filter spans every incoming channel. The +1 is one bias per filter. Remove it if biases are disabled. Spatial output dimensions do not appear here because filters share their weights across positions.

### Small example

A 7 × 7 × 3 input, two 3 × 3 filters, stride 2 and padding 1 gives output 4 × 4 × 2. It contains 32 activations but has (3 × 3 × 3 + 1) × 2 = 56 parameters. These counts do not need to match. In a multilayer question, the current layer's output channels become the next convolution's input channels.
