def features(self): resnet101 = resnet.resnet101(pretrained=self._pretrained) # list(resnet101.children()) consists of following modules # [0] = Conv2d, [1] = BatchNorm2d, [2] = ReLU, [3] = MaxPool2d, # [4] = Sequential(Bottleneck...), [5] = Sequential(Bottleneck...), # [6] = Sequential(Bottleneck...), [7] = Sequential(Bottleneck...), # [8] = AvgPool2d, [9] = Linear features_base = list( resnet101.children())[0:7] # give base features till res4 features_top = list(resnet101.children())[7:8] # give res5 to top for parameters in [ feature.parameters() for i, feature in enumerate(features_base) if i <= 4 ]: # Fix features till res2 for parameter in parameters: parameter.requires_grad = False # features.append(nn.ConvTranspose2d(in_channels=2048, out_channels=512, kernel_size=3, stride=2, padding=1)) # features.append(nn.ReLU()) features_base = nn.Sequential(*features_base) features_top = nn.Sequential(*features_top) return features_base, features_top
def __init__(self, num_classes, fpn_features=256, ratios=None, scales=None, backbone='resnet50'): super(RetinaNet, self).__init__() self.anchor_ratios = [0.5, 1, 2] if ratios == None else ratios self.anchor_scales = [2**0, 2**(1.0 / 3.0), 2**(2.0 / 3.0) ] if scales == None else scales num_anchors = len(self.anchor_ratios) * len(self.anchor_scales) self.num_classes = num_classes if backbone == 'resnet50': self.backbone = resnet50() if backbone == 'resnet101': self.backbone = resnet101() if backbone == 'resnet50_cbam': self.backbone = resnet50_cbam() if backbone == 'resnet101_cbam': self.backbone = resnet101_cbam() self.fpn = FPN(features=fpn_features) self.classifier = Classifier(in_channels=fpn_features, num_anchors=num_anchors, num_classes=num_classes) self.regressor = Regressor(in_channels=fpn_features, num_anchors=num_anchors) self.anchors = Anchor()
def __init__(self, num_classes=21, output_stride=16, pretrained=True): super(PSPNet, self).__init__() self.backbone = resnet101(output_stride=output_stride) self.layer5a = PyramidPool(2048, 512, 1) self.layer5b = PyramidPool(2048, 512, 2) self.layer5c = PyramidPool(2048, 512, 3) self.layer5d = PyramidPool(2048, 512, 6) self.final_conv = nn.Sequential( nn.Conv(4096, 512, 3, padding=1, bias=False), nn.BatchNorm(512), nn.ReLU(), nn.Dropout(.3), nn.Conv(512, num_classes, 1), )
def __init__(self, num_classes=21, output_stride=16, pretrained=True): super(ANNNet, self).__init__() self.backbone = resnet101(output_stride=output_stride) self.layer5a = PyramidPool(1) self.layer5b = PyramidPool(3) self.layer5c = PyramidPool(6) self.layer5d = PyramidPool(8) self.conv_0 = nn.Conv(2048, 2048, kernel_size=1) self.conv_1 = nn.Conv(2048, 2048, kernel_size=1) self.conv_2 = nn.Conv(2048, 2048, kernel_size=1) self.final_conv = nn.Sequential( nn.Conv(2048, 512, 3, padding=1, bias=False), nn.BatchNorm(512), nn.ReLU(), nn.Dropout(.3), nn.Conv(512, num_classes, 1), )
def __init__(self, num_classes=21, output_stride=16): super(OCRNet, self).__init__() self.num_classes = num_classes in_channels = [1024, 2048] self.backbone = resnet101(output_stride) self.head = OCRHead(512, num_classes) self.get_context = nn.Sequential( nn.Conv(in_channels[0], 512, kernel_size=3, stride=1, padding=1), nn.BatchNorm(512), nn.ReLU(), nn.Dropout(0.05), nn.Conv(512, self.num_classes, kernel_size=1, stride=1, padding=0, bias=True)) self.conv_3x3 = nn.Sequential( nn.Conv(in_channels[1], 512, kernel_size=3, stride=1, padding=1), nn.BatchNorm(512), nn.ReLU(), )
def __init__(self, num_classes=21, output_stride=16): super(DANet, self).__init__() self.backbone = resnet101(output_stride) self.head = DANetHead(2048, num_classes)
def __init__(self, output_stride=16, num_classes=21): super(DeepLab, self).__init__() self.backbone = resnet101(output_stride=output_stride) #self.backbone = mobilenet(output_stride=output_stride) self.aspp = ASPP(output_stride) self.decoder = Decoder(num_classes)