Problems
Loading...
Step 1 of 6
VGG Conv Block
Easy

Implement a VGG convolution block in NHWC layout. Apply every supplied same-padded convolution kernel and bias in order, followed by ReLU after each layer. All kernels use the same positive odd spatial size. Return the final activations as a float64 NumPy array.

Loading visualization...

Examples

Input: x = [[[[1],[-1]],[[2],[0.5]]]], kernels = [[[[[2,-1]]]]], biases = [[0,0.5]]

Output: [[[[2,0],[0,1.5]],[[4,0],[1,0]]]]

Explanation: The supplied kernel mixes input channels at every spatial position before ReLU.

Input: x = [[[[1,-1]]]], kernels = [[[[[1,0],[0.5,1]]]],[[[[0.5],[2]]]]], biases = [[0,0.1],[-0.2]]

Output: [[[[0.05]]]]

Input: x = [[[[1],[2],[3]],[[4],[5],[6]],[[7],[8],[9]]]], kernels = [[[[[0]],[[0]],[[0]]],[[[0]],[[1]],[[0]]],[[[0]],[[0]],[[0]]]]], biases = [[-5]]

Output: [[[[0],[0],[0]],[[0],[0],[1]],[[2],[3],[4]]]]

Hint 1

Pad height and width by kernel_size // 2.

Hint 2

Advance through kernels and biases together.

Hint 3

Use np.tensordot to contract each patch with its kernel.

Requirements

  • Use NumPy.
  • Apply kernels and biases in list order.
  • Use same zero padding.
  • Apply ReLU after every convolution.
  • Return a float64 NumPy array.

Constraints

  • x uses NHWC layout and dtype float64.
  • kernels and biases are nonempty lists with equal length.
  • Every kernel is square with positive odd spatial size.
  • Adjacent channel dimensions and bias lengths match.
  • Every supplied array has dtype float64.