Count Parameters in Conv Layer
Problem Statement
Calculate the number of learnable parameters in a Conv2d layer.
Background
A convolutional layer's parameters consist of weights and biases:
- For filters of size applied to an input with channels
- Weight parameters:
- Bias parameters: (one per filter)
Your Task
Write a function count_conv_params(filter_size, in_channels, out_channels) returning the total parameter count (weights + biases).
Output Format
Return an integer representing the total number of learnable parameters.
Example
filter_size=3, in_channels=1, out_channels=10
100
- Inputs:
filter_sizemeans each filter is a window;in_channelsmeans the input has a single channel;out_channelsmeans the layer learns 10 separate filters. - Weights per filter: a filter must cover the whole window in every input channel, so it holds weights.
- All weights: 10 independent filters give weights.
- Biases: each filter adds one scalar offset to its output map, so there are biases, independent of and .
- Output:
100, a single integer. - Notice that the weight count grows with the square of the filter size and linearly in both channel counts: with and the same filters already need parameters. The image's height and width never enter the count.
Constraints
- 1 <= filter_size <= 11
- 1 <= in_channels <= 512
- 1 <= out_channels <= 512