Pyramid pooling module(PPM)

参考代码:https://blog.csdn.net/wd18508423052/article/details/93882113 

上采样问题可以参考:https://blog.csdn.net/zouxiaolv/article/details/106782442

 自适应池化nn.AdaptiveAvgPool2d(size)问题:size是指定变成的尺度size*size,且不改变batchsize,channel,

class PPM(nn.Module):
    def __init__(self,inchannel,outchannel,**kwargs):
        super(PPM,self).__init__()
        interchannel =int(inchannel/4)
        self.conv1 = nn.Conv2D(inchannel,interchannel,1,**kwargs)
        self.conv2 = nn.Conv2D(inchannel,interchannel,1,**kwargs)
        self.conv3 = nn.Conv2D(inchannel,interchannel,1,**kwargs)
        self.conv4 = nn.Conv2D(inchannel,interchannel,1,**kwargs)
        self.out = nn.Conv2D(inchannel*2 , outchannel,1)
    
    def pool(self,x,size):
        avge = nn.AdaptiveAvgPool2d(size)
        return avge(x)

    def upsample(self,x,size):
        return F.interpolate(x,size,mode ='bilinear', align_corners=True)

    def forward(self,x)
        size = x.size()[2:]
        interout1 = self.pool(x,1)
        interout2 = self.pool(x,2)
        interout3 = self.pool(x,3)
        interout6 = self.pool(x,6)

        out1 = self.conv1(interout1)
        out2  =self.conv2(interout2)
        out3  =self.conv3(interout3)
        out4  =self.conv4(interout6)

        out1_1 = self.upsample(out1)
        out2_1 = self.upsample(out2)
        out3_1 = self.upsample(out3)
        out6_1 = self.upsample(out6)

        out5 = torch.cat([x,out1_1,out2_1,out3_1,out6_1],dim = 1)
        out = self.out(out5)
        return out

 

你可能感兴趣的:(Pyramid pooling module(PPM))