📘
Calculate Output Volume
EasyDeep Learning
Problem Statement
Calculate the spatial dimensions of a convolutional layer output.
Background
The output size O of a convolutional layer is determined by input size I, filter size F, padding P, and stride S using the formula:
O=⌊SI−F+2P⌋+1
If the filter is larger than the padded input (i.e., I−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
Python 3.13.1
Test Results
0/0Run code to see test results.