Ejemplo n.º 1
0
    def __init__(self, version='mobile', feature_levels=(3, 4, 5), pretrained=True, **kwargs):
        super().__init__()
        _check_levels(feature_levels)
        self.forward_levels = tuple(range(1, feature_levels[-1] + 1))
        self.feature_levels = feature_levels
        name = 'proxylessnas_%s' % version
        backbone = ptcv_get_model(name, pretrained=pretrained)
        del backbone.output
        features = backbone.features

        self.layer1 = nn.Sequential(
            features.init_block,
            features.stage1,
            features.stage2.unit1.body.bc_conv,
        )
        self.layer2 = nn.Sequential(
            features.stage2.unit1.body.dw_conv,
            features.stage2.unit1.body.pw_conv,
            features.stage2[1:],
            features.stage3.unit1.body.bc_conv,
        )
        self.layer3 = nn.Sequential(
            features.stage3.unit1.body.dw_conv,
            features.stage3.unit1.body.pw_conv,
            features.stage3[1:],
            features.stage4.unit1.body.bc_conv,
        )
        self.layer4 = nn.Sequential(
            features.stage4.unit1.body.dw_conv,
            features.stage4.unit1.body.pw_conv,
            features.stage4[1:],
            features.stage5.unit1.body.bc_conv,
        )
        self.layer5 = nn.Sequential(
            features.stage5.unit1.body.dw_conv,
            features.stage5.unit1.body.pw_conv,
            features.stage5[1:],
            features.final_block
        )

        self.out_channels = [
            get_out_channels(getattr(self, ("layer%d" % i)))
            for i in feature_levels
        ]
Ejemplo n.º 2
0
    def __init__(self, mult=1.0, feature_levels=(3, 4, 5), pretrained=True, **kwargs):
        super().__init__()
        _check_levels(feature_levels)
        self.forward_levels = tuple(range(1, feature_levels[-1] + 1))
        self.feature_levels = feature_levels

        net = ptcv_get_model(self.mult2name[float(mult)], pretrained=pretrained)
        del net.output
        net = net.features
        self.layer1 = nn.Sequential(
            net.init_block,
            net.stage1,
            net.stage2.unit1.conv1,
        )
        self.layer2 = nn.Sequential(
            net.stage2.unit1.conv2,
            net.stage2.unit1.conv3,
            net.stage2.unit2,
            net.stage3.unit1.conv1,
        )
        self.layer3 = nn.Sequential(
            net.stage3.unit1.conv2,
            net.stage3.unit1.conv3,
            *net.stage3[1:],
            net.stage4.unit1.conv1,
        )
        self.layer4 = nn.Sequential(
            net.stage4.unit1.conv2,
            net.stage4.unit1.conv3,
            *net.stage4[1:],
            net.stage5.unit1.conv1,
        )
        self.layer5 = nn.Sequential(
            net.stage5.unit1.conv2,
            net.stage5.unit1.conv3,
            *net.stage5[1:],
            net.final_block,
        )

        self.out_channels = [
            get_out_channels(getattr(self, ("layer%d" % i)))
            for i in feature_levels
        ]
Ejemplo n.º 3
0
    def __init__(self, feature_levels=(3, 4, 5), pretrained=True, **kwargs):
        super().__init__()
        _check_levels(feature_levels)
        self.forward_levels = tuple(range(1, feature_levels[-1] + 1))
        self.feature_levels = feature_levels
        net = ptcv_get_model("darknet53", pretrained=pretrained)
        del net.output
        net = net.features
        self.layer1 = nn.Sequential(
            net.init_block,
            net.stage1,
        )
        self.layer2 = net.stage2
        self.layer3 = net.stage3
        self.layer4 = net.stage4
        self.layer5 = net.stage5

        self.out_channels = [
            get_out_channels(getattr(self, ("layer%d" % i)))
            for i in feature_levels
        ]
Ejemplo n.º 4
0
    def __init__(self, name, feature_levels=(3, 4, 5), pretrained=True):
        super().__init__()
        _check_levels(feature_levels)
        self.forward_levels = tuple(range(1, feature_levels[-1] + 1))
        self.feature_levels = feature_levels
        from torchvision.models import resnet18
        net = resnet18(pretrained=pretrained)
        del net.fc
        self.layer1 = nn.Sequential(
            net.conv1,
            net.bn1,
            net.relu,
        )
        self.layer2 = net.maxpool
        self.layer3 = net.stage2
        self.layer4 = net.stage3
        self.layer5 = net.layer4

        self.out_channels = [
            calc_out_channels(getattr(self, ("layer%d" % i)))
            for i in feature_levels
        ]
Ejemplo n.º 5
0
 def __init__(self, name, feature_levels=(3, 4, 5), pretrained=True):
     super().__init__()
     _check_levels(feature_levels)
     self.forward_levels = tuple(range(1, feature_levels[-1] + 1))
     self.feature_levels = feature_levels
     net = torch.hub.load('zhanghang1989/ResNeSt', name, pretrained=pretrained)
     del net.fc
     self.layer1 = nn.Sequential(
         net.conv1,
         net.bn1,
         net.relu,
     )
     self.layer2 = nn.Sequential(
         net.maxpool,
         net.layer1,
     )
     self.layer3 = net.layer2
     self.layer4 = net.layer3
     self.layer5 = net.layer4
     self.out_channels = np.array([
         get_out_channels(getattr(self, ("layer%d" % i)))
         for i in feature_levels
     ])
Ejemplo n.º 6
0
    def __init__(self,
                 version=27,
                 feature_levels=(3, 4, 5),
                 pretrained=True,
                 no_down=0,
                 atrous=False,
                 **kwargs):
        super().__init__()
        _check_levels(feature_levels)
        self.forward_levels = tuple(range(1, feature_levels[-1] + 1))
        self.feature_levels = feature_levels

        if no_down != 0:
            assert feature_levels == (3, 4) and no_down == -1

        backbone = self.version2name[version](pretrained=pretrained)
        del backbone.classifier
        self.layer1 = backbone.stem[:6]
        self.layer2 = nn.Sequential(
            backbone.stem[6:],
            backbone.stage2,
        )
        self.layer3 = backbone.stage3

        if no_down:
            del backbone.stage5.Pooling
            if atrous:
                conv_to_atrous(backbone.stage5, rate=2)
            self.layer4 = nn.Sequential(backbone.stage4, backbone.stage5)
        else:
            self.layer4 = backbone.stage4
            self.layer5 = backbone.stage5

        self.out_channels = [
            get_out_channels(getattr(self, ("layer%d" % i)))
            for i in feature_levels
        ]