Reference: Zhao, Hengshuang, et al. *"Pyramid scene parsing network."*
| 5 | from blocks import ConvBnAct,SEModule |
| 6 | |
| 7 | class PSPModule(nn.Module): |
| 8 | """ |
| 9 | Reference: |
| 10 | Zhao, Hengshuang, et al. *"Pyramid scene parsing network."* |
| 11 | """ |
| 12 | def __init__(self, in_channels, out_channels=128, sizes=(1, 2, 3, 6)): |
| 13 | super(PSPModule, self).__init__() |
| 14 | |
| 15 | convs = [] |
| 16 | for size in sizes: |
| 17 | convs.append( |
| 18 | nn.Sequential( |
| 19 | nn.AdaptiveAvgPool2d(output_size=(size, size)), |
| 20 | ConvBnAct(in_channels,out_channels,apply_act=False) |
| 21 | ) |
| 22 | ) |
| 23 | self.stages=nn.ModuleList(convs) |
| 24 | self.bottleneck=ConvBnAct(in_channels+len(sizes)*out_channels,out_channels) |
| 25 | self.dropout=nn.Dropout2d(0.1) |
| 26 | |
| 27 | def forward(self, x): |
| 28 | y=[x] |
| 29 | for stage in self.stages: |
| 30 | z=stage(x) |
| 31 | z=F.interpolate(z,size=x.shape[-2:],align_corners=False,mode="bilinear") |
| 32 | y.append(z) |
| 33 | x=torch.cat(y,1) |
| 34 | x = self.bottleneck(x) |
| 35 | return x |
| 36 | class AlignedModule(nn.Module): |
| 37 | #SFNet-DFNet |
| 38 | def __init__(self, inplane, outplane): |