| 7 | # https://github.com/hszhao/semseg |
| 8 | |
| 9 | class PPM(nn.Module): |
| 10 | def __init__(self, in_dim, reduction_dim, bins, BatchNorm): |
| 11 | super(PPM, self).__init__() |
| 12 | self.features = [] |
| 13 | for bin in bins: |
| 14 | self.features.append(nn.Sequential( |
| 15 | nn.AdaptiveAvgPool2d(bin), |
| 16 | nn.Conv2d(in_dim, reduction_dim, kernel_size=1, bias=False), |
| 17 | BatchNorm(reduction_dim), |
| 18 | nn.ReLU(inplace=True) |
| 19 | )) |
| 20 | self.features = nn.ModuleList(self.features) |
| 21 | |
| 22 | def forward(self, x): |
| 23 | x_size = x.size() |
| 24 | out = [x] |
| 25 | for f in self.features: |
| 26 | out.append(F.interpolate(f(x), x_size[2:], mode='bilinear', align_corners=True)) |
| 27 | return torch.cat(out, 1) |
| 28 | |
| 29 | |
| 30 | class PSPNet(nn.Module): |