The PReLU-net architectures put a spatial pyramid pooling (SPP) layer between the last convolution and the first fully connected layer. It max-pools the feature map into a fixed grid of bins at several levels, so the fully connected layer receives the same number of features whatever the map's height and width. Implement it.
spp(fmap, levels=(7, 3, 2, 1)) -> np.ndarray
fmap: float array of shape (C, H, W) with H,W≥1.
levels: the pyramid; level n divides the map into n×n bins. The default has 49+9+4+1=63 bins.
- Bin (i,j) of level n covers rows ⌊iH/n⌋ to ⌈(i+1)H/n⌉−1 and columns ⌊jW/n⌋ to ⌈(j+1)W/n⌉−1 (inclusive). Its value for each channel is the maximum over those positions.
- Return a 1-D float array of length C∑nn2: for each level in the given order, the
(C, n, n) array of bin maxima flattened in channel, row, column order; the levels are concatenated.
Notes
- With these boundaries every bin is non-empty, even when n>H; neighbouring bins may overlap.
- Values can be negative.