PIXELBANKv9.1.0
Menu

Implement a calculation for the output dimensions of a 2D convolution operation, a fundamental component in Convolutional Neural Networks (CNNs). This operation is crucial for image processing tasks, where understanding the output size is essential for subsequent layers.

In CNNs, the 2D convolution operation involves sliding a kernel over an input image, performing a dot product at each position to generate a feature map. The output size of this operation depends on several factors, including the input size HinH_{in} and WinW_{in}, the kernel size KK, the padding PP, and the stride SS.

To calculate the output dimensions, follow these steps:

  1. Determine the input size HinH_{in} and WinW_{in}.
  2. Specify the kernel size KK, padding PP, and stride SS.
  3. Apply the formula to both height and width.
Hout=⌊Hin+2Pβˆ’KSβŒ‹+1H_{out} = \lfloor\frac{H_{in} + 2P - K}{S}\rfloor + 1

This technique is widely used in image classification tasks.

Example:

Input:
conv_output_size(32, 32, 3, 1, 1)
Output:
(32, 32)
Reasoning:
  • Input: Hin=32H_{in} = 32, Win=32W_{in} = 32, K=3K = 3, P=1P = 1, S=1S = 1.
  • Apply the height formula:
    Hout=⌊32+2β‹…1βˆ’31βŒ‹+1=⌊31βŒ‹+1=32H_{out} = \left\lfloor \dfrac{32 + 2\cdot1 - 3}{1} \right\rfloor + 1 = \lfloor 31 \rfloor + 1 = 32.
  • Apply the width formula similarly:
    Wout=⌊32+2β‹…1βˆ’31βŒ‹+1=32W_{out} = \left\lfloor \dfrac{32 + 2\cdot1 - 3}{1} \right\rfloor + 1 = 32.
  • So the final output dimensions are (32,32)(32, 32).

Constraints:

  • Return (H_out, W_out)
solution.py

Test Results

0/0
Run code to see test results.
Conv2D Output Size - Easy | PixelBank