Problems
Loading...
Step 4 of 6
U-Net Bottleneck
Easy

Implement the numerical U-Net bottleneck in NHWC layout. Apply two supplied same-padded convolutions, adding the corresponding bias and applying ReLU after each convolution.

Y=ReLU⁡(Conv⁡K2(ReLU⁡(Conv⁡K1(X))))Y = \operatorname{ReLU}\left(\operatorname{Conv}_{K_2}(\operatorname{ReLU}(\operatorname{Conv}_{K_1}(X)))\right)

Here, XX is the lowest-resolution encoder tensor and K1K_1 and K2K_2 are odd-sized convolution kernels. Same zero padding preserves height and width. Return YY as a float64 NumPy array.

Loading visualization...

Examples

Input: x = [[[[1,-2]]]], kernel1 = [[[[1],[0.5]]]], bias1 = [0.2], kernel2 = [[[[2,-1]]]], bias2 = [0,0.5]

Output: [[[[0.4,0.3]]]]

Explanation: The bottleneck applies two learned convolution stages without pooling or upsampling.

Input: x = [[[[1],[-1]],[[0.5],[2]]]], kernel1 = [[[[2]]]], bias1 = [-0.5], kernel2 = [[[[0.25]]]], bias2 = [0.1]

Output: [[[[0.475],[0.1]],[[0.225],[0.975]]]]

Input: x = [[[[0,0]]]], kernel1 = [[[[1,-1],[0.5,2]]]], bias1 = [0.3,-0.2], kernel2 = [[[[1],[-1]]]], bias2 = [0.1]

Output: [[[[0.4]]]]

Hint 1

Pad the two spatial axes by kernel_size // 2.

Hint 2

Apply ReLU after adding each convolution bias.

Requirements

  • Use NumPy.
  • Apply both supplied convolutions in order.
  • Add each supplied bias before its ReLU.
  • Use same zero padding.
  • Return a float64 NumPy array.

Constraints

  • x has NHWC layout and dtype float64.
  • Both kernels are square with a positive odd spatial size.
  • Kernel channels and bias lengths match adjacent tensors.
  • All kernels and biases have dtype float64.