Implement VGG max pooling on an NHWC tensor using non-overlapping 2 by 2 windows and stride two.
Yb,i,j,c=r,s∈{0,1}maxXb,2i+r,2j+s,cHere, b indexes the batch, i and j index output position, and c indexes channels. Return Y as a float64 NumPy array with shape (B,H/2,W/2,C).
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.
All steps in VGG
Accepts: array
VGG Max Pooling
Implement VGG max pooling on an NHWC tensor using non-overlapping 2 by 2 windows and stride two.
Yb,i,j,c=r,s∈{0,1}maxXb,2i+r,2j+s,cHere, b indexes the batch, i and j index output position, and c indexes channels. Return Y as a float64 NumPy array with shape (B,H/2,W/2,C).
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.
All steps in VGG
Accepts: array