def __init__(self, backbone='resnet18', pretrained_base=True, norm_layer=nn.BatchNorm2d, **kwargs): super(ContextPath, self).__init__() if backbone == 'resnet18': pretrained = resnet18(pretrained=pretrained_base, **kwargs) else: raise RuntimeError('unknown backbone: {}'.format(backbone)) self.conv1 = pretrained.conv1 self.bn1 = pretrained.bn1 self.relu = pretrained.relu self.maxpool = pretrained.maxpool self.layer1 = pretrained.layer1 self.layer2 = pretrained.layer2 self.layer3 = pretrained.layer3 self.layer4 = pretrained.layer4 inter_channels = 128 self.global_context = _GlobalAvgPooling(512, inter_channels, norm_layer) self.arms = nn.ModuleList( [AttentionRefinmentModule(512, inter_channels, norm_layer, **kwargs), AttentionRefinmentModule(256, inter_channels, norm_layer, **kwargs)] ) self.refines = nn.ModuleList( [_ConvBNReLU(inter_channels, inter_channels, 3, 1, 1, norm_layer=norm_layer), _ConvBNReLU(inter_channels, inter_channels, 3, 1, 1, norm_layer=norm_layer)] )
def __init__(self, nclass, aux, backbone='resnet50', jpu=False, pretrained_base=True, **kwargs): super(SegBaseModel, self).__init__() dilated = False if jpu else True self.aux = aux self.nclass = nclass if backbone == 'resnet50': self.pretrained = resnet50_v1s(pretrained=pretrained_base, dilated=dilated, **kwargs) elif backbone == 'resnet18': self.pretrained = resnet18(pretrained=pretrained_base, **kwargs) elif backbone == 'resnet101': self.pretrained = resnet101_v1s(pretrained=pretrained_base, dilated=dilated, **kwargs) elif backbone == 'resnet152': self.pretrained = resnet152_v1s(pretrained=pretrained_base, dilated=dilated, **kwargs) else: raise RuntimeError('unknown backbone: {}'.format(backbone)) self.jpu = JPU([512, 1024, 2048], width=512, **kwargs) if jpu else None
def __init__(self, backbone='resnet18', pretrained_base=True, norm_layer=nn.BatchNorm2d, **kwargs): super(ContextPath, self).__init__() self.backbone = backbone if backbone == 'resnet18': pretrained = resnet18(pretrained=pretrained_base, **kwargs) elif backbone == 'resnet50': pretrained = resnet50(pretrained=pretrained_base, **kwargs) elif backbone == 'xception': pretrained = get_xception_71(pretrained=pretrained_base, **kwargs) elif backbone == 'mobilenet': pretrained = get_mobilenet_v2(pretrained=pretrained_base, **kwargs) else: raise RuntimeError('unknown backbone: {}'.format(backbone)) if backbone == 'xception': self.conv1 = pretrained.conv1 self.bn1 = pretrained.bn1 self.relu = pretrained.relu self.conv2 = pretrained.conv2 self.bn2 = pretrained.bn2 self.block1 = pretrained.block1 self.block2_1 = pretrained.block2_1 self.block2_2 = pretrained.block2_2 self.block2 = pretrained.block2 self.block3 = pretrained.block3 self.midflow = pretrained.midflow self.block20 = pretrained.block20 self.conv3 = pretrained.conv3 self.bn3 = pretrained.bn3 self.conv4 = pretrained.conv4 self.bn4 = pretrained.bn4 self.conv5 = pretrained.conv5 self.bn5 = pretrained.bn5 self.avgpool = pretrained.avgpool self.fc = pretrained.fc elif backbone == 'mobilenet': self.down8 = pretrained.down8 self.down16 = pretrained.down16 self.down32 = pretrained.down32 else : self.conv1 = pretrained.conv1 self.bn1 = pretrained.bn1 self.relu = pretrained.relu self.maxpool = pretrained.maxpool self.layer1 = pretrained.layer1 self.layer2 = pretrained.layer2 self.layer3 = pretrained.layer3 self.layer4 = pretrained.layer4 inter_channels = 128 in_channels = 512 second_in_channels = 256 third_in_channels = 728 if backbone == 'resnet50' or backbone == 'xception': in_channels = 2048 second_in_channels = 728 elif backbone == 'mobilenet': in_channels = 1280 second_in_channels = 96 self.global_context = _GlobalAvgPooling(in_channels, inter_channels, norm_layer) self.arms = nn.ModuleList( [AttentionRefinmentModule(in_channels, inter_channels, norm_layer, **kwargs), AttentionRefinmentModule(second_in_channels, inter_channels, norm_layer, **kwargs), AttentionRefinmentModule(third_in_channels, inter_channels, norm_layer, **kwargs)] ) self.refines = nn.ModuleList( [_ConvBNReLU(inter_channels, inter_channels, 3, 1, 1, norm_layer=norm_layer), _ConvBNReLU(inter_channels, inter_channels, 3, 1, 1, norm_layer=norm_layer), _ConvBNReLU(inter_channels, inter_channels, 3, 1, 1, norm_layer=norm_layer)] )