Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs
Feature maps are the intermediate outputs of convolutional neural networks (CNNs), and you often need to predict their spatial dimensions to design architectures correctly. In this question, you’ll compute the output height/width of a 2D convolution feature map given input size, kernel size, stride, and padding.
The feature map size is defined as:
Implement the function
Rules:
Output:
| Argument | Type |
|---|---|
| k | int |
| p | int |
| s | int |
| h_in | int |
| w_in | int |
| Return Name | Type |
|---|---|
| value | np.ndarray |
Return np.ndarray of shape (2,).
Use floor division (//).
No deep learning frameworks.
Start by writing the given formulas for both height and width; they are identical except for h_in vs w_in.
Use Python’s integer floor division // to match the (\lfloor\cdot\rfloor) in the formula: (h_in + 2*p - k) // s + 1.
Return the two computed integers as a list [h_out, w_out] and sanity-check with the example (32,32,k=3,s=1,p=1) which should return [32, 32].