Explain the math behind the parameters shown by model.summary()

After TensorFlow model compilation, we often summarize the model with summary().

What is the math behind the parameter totals for the various layers in a compiled model, for example, here: tensorflow-1-public/C1_W4_Lab_3_compacted_images.ipynb at main · https-deeplearning-ai/tensorflow-1-public · GitHub .

Thanks,

G

Conv2D calculation example

Number of filters = 16
Dimension of a single filter = 3,3
Number of color channels = 3
Number of bias terms = 1 for a single filter (this is constant)
Number of parameters for Conv2D = number of filters * (filter_dimension_rows, filter_dimension_columns * number_color_channels + 1)
= 16 * (3 * 3 * 3 + 1)
= 448

For the 2nd filter, the number of channels is 16. So, you’ll have
32 * (3 * 3 * 16 + 1)
= 4640 parameters.

Maxpooiling and Flatten don’t have any parameters since they have nothing to learn.

Dense layer calculation example

A single node in the dense layer is connected to all inputs from previous layer and has a bias term.
So, When we connect the flattened output of 256 to a dense layer of 512, we’ll have
256 * 512 connections and 512 bias terms
= 256 * 512 + 512
= 131584 parameters

To know these details, you should consider taking the deep learning specialization.