示例#1
0
def get_senet154():
    model = senet154(pretrained=None)

    inplanes = 64
    layer0_modules = [
        ('conv1', nn.Conv2d(4, 64, 3, stride=2, padding=1, bias=False)),
        ('bn1', nn.BatchNorm2d(64)),
        ('relu1', nn.ReLU(inplace=True)),
        ('conv2', nn.Conv2d(64, 64, 3, stride=1, padding=1, bias=False)),
        ('bn2', nn.BatchNorm2d(64)),
        ('relu2', nn.ReLU(inplace=True)),
        ('conv3', nn.Conv2d(64, inplanes, 3, stride=1, padding=1, bias=False)),
        ('bn3', nn.BatchNorm2d(inplanes)),
        ('relu3', nn.ReLU(inplace=True)),
    ]
    layer0_modules.append(('pool', nn.MaxPool2d(3, stride=2, ceil_mode=True)))

    model.layer0 = nn.Sequential(OrderedDict(layer0_modules))

    model.avg_pool = nn.Sequential(nn.AvgPool2d(7,
                                                stride=1), nn.Dropout2d(0.3),
                                   nn.AvgPool2d(7, stride=1))

    model.last_linear = nn.Sequential(
        nn.Linear(model.last_linear.in_features, 768), nn.Dropout(),
        nn.Linear(768, 28))
    model = nn.DataParallel(model)
    load_if_exists(model, 'senet154_best.pth.tar')
    return model
示例#2
0
    def __init__(self, type, num_classes):
        super().__init__()

        if type == "seresnext50":
            self.senet = se_resnext50_32x4d(pretrained="imagenet")
            conv1 = nn.Conv2d(4,
                              64,
                              kernel_size=7,
                              stride=2,
                              padding=3,
                              bias=False)
        elif type == "senet154":
            self.senet = senet154(pretrained="imagenet")
            conv1 = nn.Conv2d(4, 64, 3, stride=2, padding=1, bias=False)
        else:
            raise Exception("Unsupported senet model type: '{}".format(type))

        senet_layer0_children = list(self.senet.layer0.children())
        conv1.weight.data[:, 0:3, :, :] = senet_layer0_children[0].weight.data
        self.senet.layer0 = nn.Sequential(*([conv1] +
                                            senet_layer0_children[1:]))

        self.senet.avg_pool = nn.AdaptiveAvgPool2d(output_size=1)
        self.senet.dropout = nn.Dropout(0.5)
        self.senet.last_linear = nn.Linear(2048, num_classes)
示例#3
0
 def __init__(self):
     super(SEnet154WithClassifier, self).__init__()
     self.senet154 = senet.senet154(pretrained="imagenet")
     self.senet154.avg_pool = torch.nn.AdaptiveAvgPool2d(1)
     self.senet154.last_linear = torch.nn.Linear(512 * 4, 2048)
     self.relu = torch.nn.ReLU()
     self.dropout = torch.nn.Dropout(0.5)
     self.linear = torch.nn.Linear(2048, 1103)
def get_senet_model(gpu):
    print("==>Loading SENet model...")
    model = senet154(num_classes=num_classes)
    # params_freezed_count=0
    # params_total_count=get_total_params(model)
    # for i,param in enumerate(model.parameters()):
    #     percentage_params=params_freezed_count/params_total_count
    #     if percentage_params>percentage_freeze:
    #         param.requires_grad = True
    #     else:
    #         params_freezed_count+=np.prod(param.size())
    #         param.requires_grad = False
    """
    children(), named_children() will get iterators which may be sequential or blocks as they are added.
    modules() will returns all the raw modules from inside the sequential. 
    """

    # modules=model.modules()
    # for mod in modules:
    #     pass
    return model, "senet_154_{}".format(gpu)
示例#5
0
    def __init__(self, pretrained=True):
        super(FurnitureSENet154_350, self).__init__()

        self.model = senet154(num_classes=1000, pretrained=pretrained)
        self.model.avg_pool = AdaptiveAvgPool2d(1)
        in_features = self.model.last_linear.in_features
        self.model.last_linear = Linear(in_features, 128)

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

        # create aliases:
        self.stem = ModuleList([
            self.model.layer0,
        ])
        self.features = ModuleList([
            self.model.layer1,
            self.model.layer2,
            self.model.layer3,
            self.model.layer4,
        ])
        self.classifier = self.model.last_linear
示例#6
0
 def __init__(self, config):
     super().__init__(config)
     self.freeze_num = 3
     self.model = senet.senet154(num_classes=1000, pretrained="imagenet")
     self.dropout = nn.Dropout2d(p=0.2)
     self.get_last_linear(in_features=2048)