| 15 | |
| 16 | |
| 17 | class ASPP(nn.Module): |
| 18 | def __init__(self, in_channels, atrous_rates, out_channels): |
| 19 | super(ASPP, self).__init__() |
| 20 | modules = [] |
| 21 | modules.append( |
| 22 | nn.Sequential( |
| 23 | nn.Conv2d(in_channels, out_channels, 1, bias=False), |
| 24 | # nn.GroupNorm(32, out_channels), |
| 25 | nn.ReLU(), |
| 26 | ) |
| 27 | ) |
| 28 | |
| 29 | rate1, rate2, rate3 = tuple(atrous_rates) |
| 30 | modules.append(ASPPConv(in_channels, out_channels, rate1)) |
| 31 | modules.append(ASPPConv(in_channels, out_channels, rate2)) |
| 32 | modules.append(ASPPConv(in_channels, out_channels, rate3)) |
| 33 | |
| 34 | self.convs = nn.ModuleList(modules) |
| 35 | |
| 36 | self.project = nn.Sequential( |
| 37 | nn.Conv2d(4 * out_channels, out_channels, 1, bias=False), |
| 38 | # nn.BatchNorm2d(out_channels), |
| 39 | nn.ReLU() |
| 40 | # nn.Dropout(0.5) |
| 41 | ) |
| 42 | |
| 43 | def forward(self, x): |
| 44 | res = [] |
| 45 | for conv in self.convs: |
| 46 | res.append(conv(x)) |
| 47 | res = torch.cat(res, dim=1) |
| 48 | return self.project(res) |