Implement two-dimensional max pooling for an NHWC tensor. A square window of width K moves by stride s, and each output keeps the largest value independently in every batch item and channel.
Yn,i,j,c=0≤u,v<KmaxXn,is+u,js+v,c.Here, n is the batch index, (i,j) is the output location, and c is the channel. AlexNet used windows larger than their stride, so neighboring windows overlap. Return the pooled values as a float64 NumPy array with shape (B,Hout,Wout,C).
Examples
Input: x = [[[[1],[2],[3],[4]],[[5],[6],[7],[8]],[[9],[10],[11],[12]],[[13],[14],[15],[16]]]], kernel_size = 3, stride = 1
Output: [[[[11],[12]],[[15],[16]]]]
Explanation: Each three-by-three window contributes its maximum value, and stride one makes adjacent windows overlap.
Input: x = [[[[1,8],[2,7]],[[3,6],[4,5]]]], kernel_size = 2, stride = 1
Output: [[[[4,8]]]]
Input: x = [[[[1],[5],[2],[4]],[[3],[0],[7],[6]],[[8],[2],[9],[1]],[[4],[3],[5],[0]]]], kernel_size = 2, stride = 2
Output: [[[[5],[7]],[[8],[9]]]]
Hint 1
Slice each window with row * stride and column * stride as its top-left corner.
Hint 2
np.max(window, axis=(1, 2)) preserves the batch and channel axes.
Requirements
- Compute the maximum value in every valid spatial window.
- Pool each batch item and channel independently.
- Do not pad the input.
- Return a new float64 NumPy array.
Constraints
- x has shape (B,H,W,C).
- kernel_size and stride are positive integers.
- kernel_size is no larger than the input height or width.
- Output sizes are Hout=⌊(H−K)/s⌋+1 and Wout=⌊(W−K)/s⌋+1.
All steps in AlexNet
Accepts: array
Accepts: number
Accepts: number
Overlapping Max Pooling
Implement two-dimensional max pooling for an NHWC tensor. A square window of width K moves by stride s, and each output keeps the largest value independently in every batch item and channel.
Yn,i,j,c=0≤u,v<KmaxXn,is+u,js+v,c.Here, n is the batch index, (i,j) is the output location, and c is the channel. AlexNet used windows larger than their stride, so neighboring windows overlap. Return the pooled values as a float64 NumPy array with shape (B,Hout,Wout,C).
Examples
Input: x = [[[[1],[2],[3],[4]],[[5],[6],[7],[8]],[[9],[10],[11],[12]],[[13],[14],[15],[16]]]], kernel_size = 3, stride = 1
Output: [[[[11],[12]],[[15],[16]]]]
Explanation: Each three-by-three window contributes its maximum value, and stride one makes adjacent windows overlap.
Input: x = [[[[1,8],[2,7]],[[3,6],[4,5]]]], kernel_size = 2, stride = 1
Output: [[[[4,8]]]]
Input: x = [[[[1],[5],[2],[4]],[[3],[0],[7],[6]],[[8],[2],[9],[1]],[[4],[3],[5],[0]]]], kernel_size = 2, stride = 2
Output: [[[[5],[7]],[[8],[9]]]]
Hint 1
Slice each window with row * stride and column * stride as its top-left corner.
Hint 2
np.max(window, axis=(1, 2)) preserves the batch and channel axes.
Requirements
- Compute the maximum value in every valid spatial window.
- Pool each batch item and channel independently.
- Do not pad the input.
- Return a new float64 NumPy array.
Constraints
- x has shape (B,H,W,C).
- kernel_size and stride are positive integers.
- kernel_size is no larger than the input height or width.
- Output sizes are Hout=⌊(H−K)/s⌋+1 and Wout=⌊(W−K)/s⌋+1.
All steps in AlexNet
Accepts: array
Accepts: number
Accepts: number