I’m looking for an efficient way to do a pyramidal pooling, as it is done in this paper:

  
      arxiv.org
  
  
    
1406.4729.pdf 17

3.97 MB

  
  
    
    
  
  


It’s nicely represented in Figure 3).
In their implementations the authors are doing something like this:

  
      github.com
  
  
    yueruchen/sppnet-pytorch/blob/master/spp_layer.py 16
import math
def spatial_pyramid_pool(self,previous_conv, num_sample, previous_conv_size, out_pool_size):
    '''
    previous_conv: a tensor vector of previous convolution layer
    num_sample: an int number of image in the batch
    previous_conv_size: an int vector [height, width] of the matrix features size of previous convolution layer
    out_pool_size: a int vector of expected output size of max pooling layer
    
    returns: a tensor vector with shape [1 x n] is the concentration of multi-level pooling
    '''    
    # print(previous_conv.size())
    for i in range(len(out_pool_size)):
        # print(previous_conv_size)
        h_wid = int(math.ceil(previous_conv_size[0] / out_pool_size[i]))
        w_wid = int(math.ceil(previous_conv_size[1] / out_pool_size[i]))
        h_pad = (h_wid*out_pool_size[i] - previous_conv_size[0] + 1)/2
        w_pad = (w_wid*out_pool_size[i] - previous_conv_size[1] + 1)/2
        maxpool = nn.MaxPool2d((h_wid, w_wid), stride=(h_wid, w_wid), padding=(h_pad, w_pad))
        x = maxpool(previous_conv)
        if(i == 0):


  This file has been truncated. show original

  
  
    
    
  
  


And I was wondering whether there is a more efficient way to do it?