Guys I implemented Spatial Pyramid Pooling as follows but it seems to be so slow. Do you have any suggestion ?
class SPPLayer(nn.Module):
def __init__(self, num_levels, pool_type='max_pool'):
super(SPPLayer, self).__init__()
self.num_levels = num_levels
self.pool_type = pool_type
def forward(self, x):
bs, c, h, w = x.size()
pooling_layers = []
for i in range(self.num_levels):
kernel_size = h // (2 ** i)
if self.pool_type == 'max_pool':
tensor = F.max_pool2d(x, kernel_size=kernel_size,
stride=kernel_size).view(bs, -1)
else:
tensor = F.avg_pool2d(x, kernel_size=kernel_size,
stride=kernel_size).view(bs, -1)
pooling_layers.append(tensor)
x = th.cat(pooling_layers, dim=-1)
return x