Is this what you are looking for ?

  
      github.com
  
  
    filipradenovic/cnnimageretrieval-pytorch/blob/master/cirtorch/layers/functional.py#L22 26

# return F.adaptive_max_pool2d(x, (1,1)) # alternative


def spoc(x):
return F.avg_pool2d(x, (x.size(-2), x.size(-1)))
# return F.adaptive_avg_pool2d(x, (1,1)) # alternative


def gem(x, p=3, eps=1e-6):
return F.avg_pool2d(x.clamp(min=eps).pow(p), (x.size(-2), x.size(-1))).pow(1./p)
# return F.lp_pool2d(F.threshold(x, eps, eps), p, (x.size(-2), x.size(-1))) # alternative


def rmac(x, L=3, eps=1e-6):
ovr = 0.4 # desired overlap of neighboring regions
steps = torch.Tensor([2, 3, 4, 5, 6, 7]) # possible regions for the long dimension


W = x.size(3)
H = x.size(2)


w = min(W, H)
w2 = math.floor(w/2.0 - 1)


b = (max(H, W)-w)/(steps-1)