예제 #1
0
    def __init__(self, pretrained=True):
        super(FurnitureInceptionResNet299, self).__init__()

        self.model = inceptionresnetv2(num_classes=1000, pretrained=pretrained)
        self.model.last_linear = Linear(1536, 128)

        for m in self.model.last_linear.modules():
            if isinstance(m, Linear):
                normal_(m.weight, 0, 0.01)
                constant_(m.bias, 0.0)

        # create aliases:
        self.stem = ModuleList([
            self.model.conv2d_1a,
            self.model.conv2d_2a,
            self.model.conv2d_2b,
            self.model.conv2d_3b,
            self.model.conv2d_4a,
        ])
        self.features = ModuleList([
            self.model.mixed_5b, self.model.repeat, self.model.mixed_6a,
            self.model.repeat_1, self.model.mixed_7a, self.model.repeat_2,
            self.model.block8, self.model.conv2d_7b
        ])
        self.classifier = self.model.last_linear
예제 #2
0
    def __init__(self, pretrained):
        super(FPN350, self).__init__()

        model = inceptionresnetv2(pretrained=pretrained)
        self.low_features = nn.Sequential(model.conv2d_1a, model.conv2d_2a,
                                          model.conv2d_2b, model.maxpool_3a,
                                          model.conv2d_3b, model.conv2d_4a,
                                          model.maxpool_5a, model.mixed_5b,
                                          model.repeat, model.mixed_6a,
                                          model.repeat_1)

        self.mid_features = nn.Sequential(model.mixed_7a, model.repeat_2,
                                          model.block8)

        self.top_features = nn.Sequential(
            model.conv2d_7b,
            model.avgpool_1a,
        )
        self.smooth1 = nn.Conv2d(1088, 256, kernel_size=3, stride=1, padding=1)
        self.smooth2 = nn.Conv2d(2080, 320, kernel_size=3, stride=1, padding=1)
        self.top_smooth = nn.Conv2d(1536,
                                    256,
                                    kernel_size=1,
                                    stride=1,
                                    padding=0)

        # Alias
        self.smooth_layers = nn.ModuleList([
            self.smooth1,
            self.smooth2,
            self.top_smooth,
        ])
예제 #3
0
    def __init__(self, pretrained=True, n_cls_layers=1024):
        super(FurnitureInceptionResNetOnFiveCrops, self).__init__()

        self.model = inceptionresnetv2(num_classes=1000, pretrained=pretrained)
        self.model.avgpool_1a = AdaptiveAvgPool2d(1)

        n_crops = 5
        self.crop_classifiers = []
        for i in range(n_crops):
            self.crop_classifiers.append(Linear(1536, n_cls_layers))
            for m in self.crop_classifiers[-1].modules():
                if isinstance(m, Linear):
                    normal_(m.weight, 0, 0.01)
                    constant_(m.bias, 0.0)

        # create aliases:
        self.stem = ModuleList([
            self.model.conv2d_1a,
            self.model.conv2d_2a,
            self.model.conv2d_2b,
        ])
        self.low_features = ModuleList([
            self.model.mixed_5b, self.model.repeat, self.model.mixed_6a,
            self.model.repeat_1
        ])
        self.features = ModuleList([
            self.model.mixed_7a, self.model.repeat_2, self.model.block8,
            self.model.conv2d_7b
        ])
        self.crop_classifiers = ModuleList(self.crop_classifiers)

        self.drop = Dropout(p=0.45)
        self.relu = ReLU(inplace=True)

        self.final_classifier = Linear(n_cls_layers, 128)
        for m in self.final_classifier.modules():
            normal_(m.weight, mean=0.0, std=0.01)
            if m.bias is not None:
                constant_(m.bias, 0.0)
    def __init__(self, pretrained):
        super(InceptionResnetFPN350, self).__init__()

        model = inceptionresnetv2(pretrained=pretrained)
        self.stem = nn.Sequential(
            model.conv2d_1a,
            model.conv2d_2a,
            model.conv2d_2b,
            model.maxpool_3a,
            model.conv2d_3b,
            model.conv2d_4a,
            model.maxpool_5a,
        )

        self.low_features = nn.Sequential(
            model.mixed_5b,
            model.repeat,
        )

        self.layer3 = nn.Sequential(model.mixed_6a, model.repeat_1)

        self.layer4 = nn.Sequential(
            model.mixed_7a,
            model.repeat_2,
            model.block8,
            model.conv2d_7b,
        )

        self.conv6 = nn.Conv2d(1536, 256, kernel_size=3, stride=2, padding=1)
        self.conv7 = nn.Conv2d(256, 256, kernel_size=3, stride=2, padding=1)

        # Top-down layers
        self.toplayer = nn.Conv2d(1536,
                                  256,
                                  kernel_size=1,
                                  stride=1,
                                  padding=0)

        # Lateral layers
        self.latlayer1 = nn.Conv2d(1088,
                                   256,
                                   kernel_size=1,
                                   stride=1,
                                   padding=0)
        self.latlayer2 = nn.Conv2d(320,
                                   256,
                                   kernel_size=1,
                                   stride=1,
                                   padding=0)

        # Smooth layers
        self.smooth1 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1)
        self.smooth2 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1)

        # Aliases
        self.mid_features = nn.ModuleList([
            self.layer3,
            self.layer4,
        ])

        self.top_features = nn.ModuleList([
            self.conv6, self.conv7, self.toplayer, self.latlayer1,
            self.latlayer2, self.smooth1, self.smooth2
        ])