Debug School

rakesh kumar
rakesh kumar

Posted on

Numericals to calculate convolution layer output size,filter,padding,stride

Formulla

1.Output size after one convolutional layer:

Image description

2.Output size with padding and stride:

Image description

  1. Max pooling layer output size:

    Image description

  2. Average pooling layer output size:


Image description

  1. Number of parameters in a convolutional layer:

Image description

  1. Same padding convolution output size:

Image description

7.Number of parameters in convolution:

Image description

8.Output size after multiple convolution layers:

Image description

9.Convolution followed by pooling output size:

Image description

10.Fully connected layer input size:

Image description

11.Stride and padding convolution output size:

Image description

12.3D Convolution output size:

Image description

13.Depthwise separable convolution parameters:
Depthwise Parameters

Image description

  1. Fully connected layer parameters:

Image description

  1. Dilated convolution output size:

Image description

Numericals

1.Given a 5x7 input matrix (m x n) and a 3x3 filter matrix (f x f), perform a valid convolution operation. Calculate the size of the output matrix.

Image description

Input details:
Input matrix size (m x n): 5x7
Filter matrix size (f x f): 3x3
Padding: 0 (valid padding, meaning no padding is applied)
Stride: 1
Solution:
Formula to calculate the output size:

Image description

Output width=n−f+1=7−3+1=5
So, the output matrix will be of size 3x5.

Explanation:

The convolution process involves sliding the 3x3 filter over the 5x7 input matrix. Since it's a valid convolution (no padding), the filter only fits entirely within the matrix a certain number of times based on the stride (which is 1 here). This results in an output matrix of size 3x5.
This is a typical example of performing convolution in a CNN with valid padding, where the output shrinks based on the size of the filter and stride.

2.Given a 7x9 input matrix (m x n) and a 3x3 filter matrix (f x f), perform a convolution operation with same padding and calculate the size of the output matrix.

Image description

Input details:
Input matrix size (m x n): 7x9
Filter matrix size (f x f): 3x3
Padding: 1 (same padding)
Stride: 1
Solution:
Formula to calculate the output size:

Explanation:
The "same" padding ensures that the output matrix retains dimensions close to the input size by padding the input with a border of zeros.
After applying the 3x3 filter, the resulting output dimensions are 5x7, as calculated.

  1. Calculate the output size of a convolutional layer: Input size: 32x32 Filter size: 3x3 Padding: 0 (no padding) Stride: 1 Solution:

Image description

  1. Calculate the output size of a convolutional layer with padding: Input size: 28x28 Filter size: 5x5 Padding: 2 Stride: 1 Solution:

Image description

  1. **Calculate the output size with stride greater than **1:
    Input size: 32x32
    Filter size: 3x3
    Padding: 0
    Stride: 2
    Solution:

  2. Max Pooling layer output size:
    Input size: 16x16
    Pool size: 2x2
    Stride: 2
    Solution:

Image description

  1. Average Pooling layer output size: Input size: 14x14 Pool size: 2x2 Stride: 2 Solution:

Image description

  1. Output size with different stride: Input size: 32x32 Filter size: 5x5 Padding: 0 Stride: 1 Solution:

Image description

  1. Calculate convolution with same padding: Input size: 28x28 Filter size: 3x3 Padding: "same" (equivalent to padding = 1) Stride: 1 Solution:

Image description

  1. Calculate convolution with valid padding: Input size: 32x32 Filter size: 3x3 Padding: "valid" (no padding) Stride: 1 Solution:

Image description

  1. Stride and padding combination: Input size: 64x64 Filter size: 5x5 Padding: 2 Stride: 2 Solution:

Image description

  1. 3D convolution (height, width, depth): Input size: 28x28x3 Filter size: 3x3 Padding: 1 Stride: 1 Solution:

Image description

  1. Max Pooling for 3D input: Input size: 32x32x3 Pool size: 2x2 Stride: 2 Solution:

Image description

  1. Output size for convolution with non-square input: Input size: 64x32 Filter size: 5x5 Padding: 0 Stride: 2 Solution:

Output size:

Image description

  1. Calculate output with dilation: Input size: 32x32 Filter size: 3x3 Padding: 1 Stride: 1 Dilation: 2 Solution:

Output size:

Image description

  1. Depthwise convolution output: Input size: 64x64x3 Filter size: 3x3 Padding: 1 Stride: 1 Solution:

Image description

  1. Calculate the output size of average pooling with padding: Input size: 28x28 Pool size: 2x2 Padding: 1 Stride: 2 Solution:

Output size:

Image description

Image description

Top comments (0)