Problems
Loading...
Step 2 of 6
VGG Max Pooling
Easy

Implement VGG max pooling on an NHWC tensor using non-overlapping 2 by 2 windows and stride two.

Yb,i,j,c=max⁡r,s∈{0,1}Xb,2i+r,2j+s,cY_{b,i,j,c} = \max_{r,s\in\{0,1\}} X_{b,2i+r,2j+s,c}

Here, bb indexes the batch, ii and jj index output position, and cc indexes channels. Return YY as a float64 NumPy array with shape (B,H/2,W/2,C)(B,H/2,W/2,C).

Loading visualization...

Examples

Input: x = [[[[1],[3],[2],[4]],[[5],[6],[7],[8]],[[9],[10],[11],[12]],[[13],[14],[15],[16]]]]

Output: [[[[6],[8]],[[14],[16]]]]

Explanation: Each output value is the maximum from its corresponding 2 by 2 spatial window.

Input: x = [[[[1,8],[3,2]],[[5,4],[0,7]]]]

Output: [[[[5,8]]]]

Input: x = [[[[-1],[-3]],[[-2],[-4]]],[[[-5],[-2]],[[-7],[-6]]]]

Output: [[[[-1]]],[[[-2]]]]

Hint 1

Reshape height and width into output and window axes.

Hint 2

Reduce the two window axes with max.

Requirements

  • Use NumPy.
  • Reduce each non-overlapping 2 by 2 spatial window with maximum.
  • Preserve batch and channel axes.
  • Return a float64 NumPy array.

Constraints

  • x has shape (B, H, W, C) and dtype float64.
  • H and W are positive even integers.
  • B and C are positive.