def __init__(self, configer): super(asymmetric_non_local_network, self).__init__() self.configer = configer self.num_classes = self.configer.get('data', 'num_classes') self.backbone = ModuleHelper.get_backbone( backbone=self.configer.get('network.backbone'), pretrained=self.configer.get('network.pretrained') ) # low_in_channels, high_in_channels, out_channels, key_channels, value_channels, dropout self.fusion = AFNB(1024, 2048, 2048, 256, 256, dropout=0.05, sizes=([1]), norm_type=self.configer.get('network', 'norm_type')) # extra added layers self.context = nn.Sequential( nn.Conv2d(2048, 512, kernel_size=3, stride=1, padding=1), ModuleHelper.BNReLU(512, norm_type=self.configer.get('network', 'norm_type')), APNB(in_channels=512, out_channels=512, key_channels=256, value_channels=256, dropout=0.05, sizes=([1]), norm_type=self.configer.get('network', 'norm_type')) ) self.cls = nn.Conv2d(512, self.num_classes, kernel_size=1, stride=1, padding=0, bias=True) self.dsn = nn.Sequential( nn.Conv2d(1024, 512, kernel_size=3, stride=1, padding=1), ModuleHelper.BNReLU(512, norm_type=self.configer.get('network', 'norm_type')), nn.Dropout2d(0.05), nn.Conv2d(512, self.num_classes, kernel_size=1, stride=1, padding=0, bias=True) ) self.valid_loss_dict = configer.get('loss', 'loss_weights', configer.get('loss.loss_type'))
def __init__(self, configer): super(BaseModel, self).__init__() self.configer = configer self.net = ModuleHelper.get_backbone( backbone=configer.get('network.{}backbone'.format(self.flag)), pretrained=configer.get('network.{}pretrained'.format(self.flag))) self.valid_loss_dict = configer.get('loss.loss_weights', configer.get('loss.loss_type'))
def __init__(self, configer): super(OpenPose, self).__init__() self.configer = configer self.backbone = ModuleHelper.get_backbone( backbone=self.configer.get('network.backbone'), pretrained=self.configer.get('network.pretrained')) self.pose_model = PoseModel(configer, self.backbone.get_num_features()) self.valid_loss_dict = configer.get('loss', 'loss_weights', configer.get('loss.loss_type'))
def __init__(self, configer): super(DarkNetYolov3, self).__init__() self.configer = configer self.backbone = ModuleHelper.get_backbone( backbone=configer.get('network.backbone'), pretrained=configer.get('network.pretrained', default=None)) self.yolov3_head = Yolov3Head(configer, out_filters=self.backbone.num_features) self.yolo_detection_layer = YOLODetectionLayer(self.configer)
def __init__(self, configer): super(ResSFNet, self).__init__() self.configer = configer self.num_classes = self.configer.get('data', 'num_classes') base = ModuleHelper.get_backbone( backbone=self.configer.get('network.backbone'), pretrained=self.configer.get('network.pretrained')) self.stage1 = nn.Sequential(base.conv1, base.bn1, base.relu1, base.conv2, base.bn2, base.relu2, base.conv3, base.bn3, base.relu3, base.maxpool, base.layer1) self.stage2 = base.layer2 self.stage3 = base.layer3 self.stage4 = base.layer4 num_features = 512 if 'resnet18' in self.configer.get( 'network.backbone') else 2048 fpn_dim = max(num_features // 8, 128) self.head = AlignHead(num_features, fpn_dim=fpn_dim) self.dsn = nn.Sequential( nn.Conv2d(num_features // 2, max(num_features // 4, 256), kernel_size=3, stride=1, padding=1), ModuleHelper.BNReLU(max(num_features // 4, 256), norm_type="batchnorm"), nn.Dropout2d(0.1), nn.Conv2d(max(num_features // 4, 256), self.num_classes, kernel_size=1, stride=1, padding=0, bias=True)) self.conv_last = nn.Sequential( conv3x3_bn_relu(4 * fpn_dim, fpn_dim, 1), nn.Conv2d(fpn_dim, self.num_classes, kernel_size=1)) self.fpn_dsn = nn.ModuleList() for i in range(len([2, 4, 8])): self.fpn_dsn.append( nn.Sequential( nn.Conv2d(fpn_dim, fpn_dim, kernel_size=3, stride=1, padding=1), ModuleHelper.BNReLU(fpn_dim, norm_type="batchnorm"), nn.Dropout2d(0.1), nn.Conv2d(fpn_dim, self.num_classes, kernel_size=1, stride=1, padding=0, bias=True))) self.valid_loss_dict = configer.get('loss', 'loss_weights', configer.get('loss.loss_type'))
def __init__(self, configer): super(DenseASPP, self).__init__() self.configer = configer dropout0 = MODEL_CONFIG['dropout0'] dropout1 = MODEL_CONFIG['dropout1'] d_feature0 = MODEL_CONFIG['d_feature0'] d_feature1 = MODEL_CONFIG['d_feature1'] self.backbone = ModuleHelper.get_backbone( backbone=self.configer.get('network.backbone'), pretrained=self.configer.get('network.pretrained') ) num_features = self.backbone.get_num_features() self.trans = _Transition(num_input_features=self.num_features, num_output_features=self.num_features // 2, norm_type=self.configer.get('network', 'norm_type')) self.num_features = self.num_features // 2 self.ASPP_3 = _DenseAsppBlock(input_num=num_features, num1=d_feature0, num2=d_feature1, dilation_rate=3, drop_out=dropout0, norm_type=self.configer.get('network', 'norm_type')) self.ASPP_6 = _DenseAsppBlock(input_num=num_features + d_feature1 * 1, num1=d_feature0, num2=d_feature1, dilation_rate=6, drop_out=dropout0, norm_type=self.configer.get('network', 'norm_type')) self.ASPP_12 = _DenseAsppBlock(input_num=num_features + d_feature1 * 2, num1=d_feature0, num2=d_feature1, dilation_rate=12, drop_out=dropout0, norm_type=self.configer.get('network', 'norm_type')) self.ASPP_18 = _DenseAsppBlock(input_num=num_features + d_feature1 * 3, num1=d_feature0, num2=d_feature1, dilation_rate=18, drop_out=dropout0, norm_type=self.configer.get('network', 'norm_type')) self.ASPP_24 = _DenseAsppBlock(input_num=num_features + d_feature1 * 4, num1=d_feature0, num2=d_feature1, dilation_rate=24, drop_out=dropout0, norm_type=self.configer.get('network', 'norm_type')) num_features = num_features + 5 * d_feature1 self.classification = nn.Sequential( nn.Dropout2d(p=dropout1), nn.Conv2d(num_features, self.configer.get('data', 'num_classes'), kernel_size=1, padding=0) ) self.valid_loss_dict = configer.get('loss', 'loss_weights', configer.get('loss.loss_type'))
def __init__(self, configer): super(PSPNet, self).__init__() self.configer = configer self.num_classes = self.configer.get('data', 'num_classes') base = ModuleHelper.get_backbone( backbone=self.configer.get('network.backbone'), pretrained=self.configer.get('network.pretrained')) self.stage1 = nn.Sequential(base.conv1, base.bn1, base.relu1, base.conv2, base.bn2, base.relu2, base.conv3, base.bn3, base.relu3, base.maxpool, base.layer1, base.layer2, base.layer3) self.stage2 = base.layer4 num_features = 512 if 'resnet18' in self.configer.get( 'network.backbone') else 2048 self.dsn = nn.Sequential( _ConvBatchNormReluBlock(num_features // 2, num_features // 4, 3, 1, norm_type=self.configer.get( 'network', 'norm_type')), nn.Dropout2d(0.1), nn.Conv2d(num_features // 4, self.num_classes, 1, 1, 0)) self.ppm = PPMBilinearDeepsup(fc_dim=num_features, norm_type=self.configer.get( 'network', 'norm_type')) self.cls = nn.Sequential( nn.Conv2d(num_features + 4 * 512, 512, kernel_size=3, padding=1, bias=False), ModuleHelper.BNReLU(512, norm_type=self.configer.get( 'network', 'norm_type')), nn.Dropout2d(0.1), nn.Conv2d(512, self.num_classes, kernel_size=1)) self.valid_loss_dict = configer.get('loss', 'loss_weights', configer.get('loss.loss_type'))
def __init__(self, configer, loss_dict=None, flag=""): super(ClsModel, self).__init__() self.configer = configer self.flag = flag if len(flag) == 0 else "{}_".format(flag) self.backbone = ModuleHelper.get_backbone( backbone=configer.get('network.{}backbone'.format(self.flag)), pretrained=configer.get('network.{}pretrained'.format(self.flag))) self.reduction = None fc_dim_out = configer.get('network.{}fc_dim'.format(self.flag), default=None) fc_dim = self.backbone.num_features if fc_dim_out is not None: self.reduction = nn.Conv2d(self.backbone.num_features, fc_dim_out, 1) fc_dim = fc_dim_out self.linear_list = nn.ModuleList() linear_type = configer.get('network', '{}linear_type'.format(self.flag), default='linear') self.fc = LINEAR_DICT[linear_type](fc_dim, configer.get('data.num_classes')) self.embed = None if configer.get('network.{}embed'.format(self.flag), default=False): feat_dim = configer.get('network', '{}feat_dim'.format(self.flag)) self.embed = nn.Sequential(nn.Linear(fc_dim, feat_dim), nn.BatchNorm1d(feat_dim)) self.bn = None if configer.get('network.{}bn'.format(self.flag), default=False): self.bn = nn.BatchNorm1d(fc_dim) nn.init.zeros_(self.bn.bias) self.bn.bias.requires_grad = False self.valid_loss_dict = configer.get( 'loss.loss_weights', configer.get('loss.loss_type')) if loss_dict is None else loss_dict
def __init__(self, configer): self.inplanes = 128 super(DeepLabV3, self).__init__() self.configer = configer self.num_classes = self.configer.get('data', 'num_classes') base = ModuleHelper.get_backbone( backbone=self.configer.get('network.backbone'), pretrained=self.configer.get('network.pretrained')) self.stage1 = nn.Sequential(base.conv1, base.bn1, base.relu1, base.conv2, base.bn2, base.relu2, base.conv3, base.bn3, base.relu3, base.maxpool, base.layer1, base.layer2, base.layer3) self.stage2 = base.layer4 num_features = 512 if 'resnet18' in self.configer.get( 'network.backbone') else 2048 self.head = nn.Sequential( ASPPModule(num_features, norm_type=self.configer.get('network', 'norm_type')), nn.Conv2d(512, self.num_classes, kernel_size=1, stride=1, padding=0, bias=True)) self.dsn = nn.Sequential( nn.Conv2d(1024, 512, kernel_size=3, stride=1, padding=1), ModuleHelper.BNReLU(512, norm_type=self.configer.get( 'network', 'norm_type')), nn.Dropout2d(0.1), nn.Conv2d(512, self.num_classes, kernel_size=1, stride=1, padding=0, bias=True)) self.valid_loss_dict = configer.get('loss', 'loss_weights', configer.get('loss.loss_type'))