PIXELBANKv8.2.1
Menu

Calculate Output Volume

Problem Statement

Calculate the spatial dimensions of a convolutional layer output.

Background

The output size OO of a convolutional layer is determined by input size II, filter size FF, padding PP, and stride SS using the formula:

O=IF+2PS+1O = \lfloor \frac{I - F + 2P}{S} \rfloor + 1

If the filter is larger than the padded input (i.e., IF+2P<0I - F + 2P < 0), the configuration is invalid.

Your Task

Write a function conv_output_size(input_size, filter_size, padding, stride) that returns the output dimension. If the configuration is invalid (filter larger than padded input), return -1.

Output Format

Return an integer representing the output dimension, or -1 if invalid.

Example:

Input:
input_size=32, filter_size=3, padding=1, stride=1
Output:
32
Reasoning:

floor((32 - 3 + 2*1) / 1) + 1 = floor(32/1) + 1 = 32

Constraints:

  • 1 <= input_size <= 1000
  • 1 <= filter_size <= input_size
  • 0 <= padding <= 100
  • 1 <= stride <= input_size
Editor

Test Results

0/0
Run code to see test results.