← 返回 tesla 的题目列表Implement Conv2D Forward Pass with Unit Test
类型:online_judge
Implement a 2D convolution layer forward pass function. The function should take input feature maps and filter parameters, and output the convolution result. Ensure that the code passes the provided unit tests. Requirements:
Input: a grayscale image (represented by a 2D array) and a convolution kernel (also a 2D array), with image size MxM, and kernel size NxN (N <= M).
Output: a 2D array resulting from the convolution operation.
Use zero padding.
Stride is 1.
Provide the following test cases:
Input image: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], Kernel: [[1, 0], [0, -1]], Output: [[1, 2], [3, 0]].
Input image: [[1, 0, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]], Kernel: [[0, 1], [1, 0]], Output: [[5, 7, 9], [13, 15, 17], [21, 23, 25]].
Input image: [[3, 2, 3], [0, 1, 2], [1, 0, 1]], Kernel: [[1, 1], [1, 1]], Output: [[6, 8], [2, 4]].
Example
Input
[[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[1, 0], [0, -1]]