ASPP-based Segmentation network
| 65 | |
| 66 | |
| 67 | class ASPP(nn.Module): |
| 68 | """ |
| 69 | ASPP-based Segmentation network |
| 70 | """ |
| 71 | def __init__(self, num_classes, trunk='hrnetv2', criterion=None): |
| 72 | super(ASPP, self).__init__() |
| 73 | self.criterion = criterion |
| 74 | self.backbone, _, _, high_level_ch = get_trunk(trunk) |
| 75 | self.aspp, aspp_out_ch = get_aspp(high_level_ch, |
| 76 | bottleneck_ch=cfg.MODEL.ASPP_BOT_CH, |
| 77 | output_stride=8) |
| 78 | self.bot_aspp = nn.Conv2d(aspp_out_ch, 256, kernel_size=1, bias=False) |
| 79 | self.final = make_seg_head(in_ch=256, |
| 80 | out_ch=num_classes) |
| 81 | |
| 82 | initialize_weights(self.final, self.bot_aspp, self.aspp) |
| 83 | |
| 84 | def forward(self, inputs): |
| 85 | x = inputs['images'] |
| 86 | x_size = x.size() |
| 87 | |
| 88 | _, _, final_features = self.backbone(x) |
| 89 | aspp = self.aspp(final_features) |
| 90 | aspp = self.bot_aspp(aspp) |
| 91 | pred = self.final(aspp) |
| 92 | pred = Upsample(pred, x_size[2:]) |
| 93 | |
| 94 | if self.training: |
| 95 | assert 'gts' in inputs |
| 96 | gts = inputs['gts'] |
| 97 | loss = self.criterion(pred, gts) |
| 98 | return loss |
| 99 | else: |
| 100 | output_dict = {'pred': pred} |
| 101 | return output_dict |
| 102 | |
| 103 | |
| 104 | def HRNet(num_classes, criterion, s2s4=None): |