Panoptic DeepLab-style semantic segmentation network stride8 only
| 361 | |
| 362 | |
| 363 | class MscaleDeeper(MscaleBase): |
| 364 | """ |
| 365 | Panoptic DeepLab-style semantic segmentation network |
| 366 | stride8 only |
| 367 | """ |
| 368 | def __init__(self, num_classes, trunk='wrn38', criterion=None, |
| 369 | fuse_aspp=False, attn_2b=False): |
| 370 | super(MscaleDeeper, self).__init__() |
| 371 | self.criterion = criterion |
| 372 | self.fuse_aspp = fuse_aspp |
| 373 | self.attn_2b = attn_2b |
| 374 | self.backbone, s2_ch, s4_ch, high_level_ch = get_trunk( |
| 375 | trunk_name=trunk, output_stride=8) |
| 376 | self.aspp, aspp_out_ch = get_aspp(high_level_ch, bottleneck_ch=256, |
| 377 | output_stride=8) |
| 378 | |
| 379 | self.convs2 = nn.Conv2d(s2_ch, 32, kernel_size=1, bias=False) |
| 380 | self.convs4 = nn.Conv2d(s4_ch, 64, kernel_size=1, bias=False) |
| 381 | self.conv_up1 = nn.Conv2d(aspp_out_ch, 256, kernel_size=1, bias=False) |
| 382 | self.conv_up2 = ConvBnRelu(256 + 64, 256, kernel_size=5, padding=2) |
| 383 | self.conv_up3 = ConvBnRelu(256 + 32, 256, kernel_size=5, padding=2) |
| 384 | self.conv_up5 = nn.Conv2d(256, num_classes, kernel_size=1, bias=False) |
| 385 | |
| 386 | # Scale-attention prediction head |
| 387 | if self.attn_2b: |
| 388 | attn_ch = 2 |
| 389 | else: |
| 390 | attn_ch = 1 |
| 391 | self.scale_attn = make_attn_head(in_ch=256, |
| 392 | out_ch=attn_ch) |
| 393 | |
| 394 | if cfg.OPTIONS.INIT_DECODER: |
| 395 | initialize_weights(self.convs2, self.convs4, self.conv_up1, |
| 396 | self.conv_up2, self.conv_up3, self.conv_up5, |
| 397 | self.scale_attn) |
| 398 | |
| 399 | def _fwd(self, x, aspp_lo=None, aspp_attn=None): |
| 400 | s2_features, s4_features, final_features = self.backbone(x) |
| 401 | s2_features = self.convs2(s2_features) |
| 402 | s4_features = self.convs4(s4_features) |
| 403 | aspp = self.aspp(final_features) |
| 404 | |
| 405 | if self.fuse_aspp and \ |
| 406 | aspp_lo is not None and aspp_attn is not None: |
| 407 | aspp_attn = scale_as(aspp_attn, aspp) |
| 408 | aspp_lo = scale_as(aspp_lo, aspp) |
| 409 | aspp = aspp_attn * aspp_lo + (1 - aspp_attn) * aspp |
| 410 | |
| 411 | x = self.conv_up1(aspp) |
| 412 | x = Upsample2(x) |
| 413 | x = torch.cat([x, s4_features], 1) |
| 414 | x = self.conv_up2(x) |
| 415 | x = Upsample2(x) |
| 416 | x = torch.cat([x, s2_features], 1) |
| 417 | up3 = self.conv_up3(x) |
| 418 | |
| 419 | out = self.conv_up5(up3) |
| 420 | out = Upsample2(out) |
no outgoing calls
no test coverage detected