def __init__(self, in_channel=3, n_class=1): super(Efficient_SIIMD, self).__init__() efficient = EfficientNet.from_pretrained('efficientnet-b0') self.block0 = nn.Sequential(efficient._conv_stem, efficient._bn0) print(len(efficient._blocks)) self.block1 = nn.Sequential(*efficient._blocks[:5]) self.block2 = nn.Sequential(*efficient._blocks[5:10]) self.block3 = nn.Sequential(*efficient._blocks[10:16]) self.avgpool = nn.AdaptiveAvgPool2d((1, 1)) self.classifier = Classifier( efficient._blocks[-1]._project_conv.out_channels, 128, n_class) # for para in self.block0.parameters(): # para.requires_grad = False # # for para in self.block1.parameters(): # para.requires_grad = False # # for para in self.block2.parameters(): # para.requires_grad = False # for para in self.block3.parameters(): # para.requires_grad = False for m in self.classifier.modules(): if isinstance(m, nn.Linear): init_weights(m, init_type='kaiming') elif isinstance(m, nn.BatchNorm1d): init_weights(m, init_type='kaiming')
def __init__(self, in_channel, mid_channel, n_class, dropout=0.5): super(Classifier, self).__init__() # solution 1 self.layer1 = nn.Dropout(0.5) self.layer2 = nn.Sequential(nn.Linear(in_channel, mid_channel), nn.BatchNorm1d(mid_channel), nn.ReLU()) self.layer3 = nn.Linear(mid_channel, n_class) for m in self.modules(): if isinstance(m, nn.Conv2d) or isinstance(m, nn.Linear): init_weights(m, init_type='kaiming') elif isinstance(m, nn.BatchNorm1d): init_weights(m, init_type='kaiming')
def __init__(self, in_channel=3, n_class=1): super(Regnet_SIIM, self).__init__() backbone = regnet_800M(pretrained=True) self.stem = list(list(backbone.children())[0].children())[0] self.feature = nn.Sequential(*list(list(backbone.children())[0].children())[1:-1]) self.avgpool = nn.AdaptiveAvgPool2d((1, 1)) self.classifier = Classifier(672, 320, n_class) for m in self.classifier.modules(): if isinstance(m, nn.Linear): init_weights(m, init_type='kaiming') elif isinstance(m, nn.BatchNorm1d): init_weights(m, init_type='kaiming')
def __init__(self, in_channel=3, n_class=1): super(ResNet_SIIM, self).__init__() resnet = models.resnet34(True) self.layer0 = nn.Sequential(resnet.conv1, resnet.bn1, resnet.maxpool) self.layer1 = resnet.layer1 self.layer2 = resnet.layer2 self.layer3 = resnet.layer3 self.layer4 = resnet.layer4 self.avgpool = resnet.avgpool self.fc_reduce = nn.Linear(resnet.fc.in_features, 32) # self.features = nn.Sequential(*list(resnet.children())[:-1]) self.classifier = Classifier(32, 32, n_class) for m in self.classifier.modules(): if isinstance(m, nn.Linear): init_weights(m, init_type='kaiming') elif isinstance(m, nn.BatchNorm1d): init_weights(m, init_type='kaiming')