Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs
Padding and stride are two simple knobs in convolutional layers that control output size and how much neighboring pixels influence each other. In this task, you’ll compute the output height/width of a 2D convolution given an input image size and conv settings.
Implement the function
Rules:
np.array([out_h, out_w]).Output:
| Argument | Type |
|---|---|
| h | int |
| w | int |
| k_h | int |
| k_w | int |
| stride | int |
| padding | int |
| Return Name | Type |
|---|---|
| value | np.ndarray |
Return NumPy array [out_h, out_w].
Use integer floor division (//), no convolution simulation.
Only NumPy and Python built-ins allowed.
Use the standard output-size formula separately for height and width: \n(\text{out} = \left\lfloor\frac{\text{in} + 2p - k}{s}\right\rfloor + 1).
In Python, floor division for non-negative integers is //, so compute:
out_h = (h + 2*padding - k_h) // stride + 1 and similarly for width.
Return as a NumPy array np.array([out_h, out_w]).