Calculate Parameter Count for Grouped Convolutions
Implement a function to calculate the parameter count ratio between grouped convolutions and standard convolutions. Grouped convolutions are a technique used in ConvNext architectures to reduce computational costs by splitting input and output channels into groups, where each group operates on a subset of the channels.
This process can be broken down into the following steps:
- Determine the number of parameters in a standard convolution, given by .
- Calculate the number of parameters in a grouped convolution, where each of the groups operates on input channels producing output channels. The key formula for the ratio of parameters is
This technique is widely used in deep learning models for image classification tasks.
Example
K_W=3, K_H=3, C_in=256, C_out=256, G=4
0.25
- Inputs: a kernel (), input channels, output channels, and groups. Every weight connects one kernel position, one input channel and one output channel.
- Standard convolution: every output channel sees all input channels, so .
- One group: it sees only input channels and produces output channels, so it holds weights.
- All groups: .
- Ratio: , returned as a float
0.25. - Notice: both channel counts are divided by but only one factor of is multiplied back, so the kernel size and channel counts cancel and the ratio is . With you get
1.0(a standard convolution); with ,0.0625.
Constraints
- (kernel size)
- (channels)
- is a divisor of :