def __init__(self, args, cfg=None, net='resnet', output_stride=32, num_classes=21, img_size=512, pretrained=True, freeze_bn=False): super(DSSD, self).__init__() self.args = args self.cfg = cfg self.net = net self.num_classes = num_classes self.image_size = img_size self.priorbox = PriorBox(cfg, net, output_stride) self.priors = self.priorbox().to(args.device) self.backbone = build_backbone(net, output_stride, pretrained) self.aspp = build_aspp(net, output_stride) self.decoder = build_decoder(net) self.head = build_head(inplances=self.decoder.plances, num_classes=num_classes, num_anchor=cfg.anchor_number) if freeze_bn: self.freeze_bn # For detect self.softmax = nn.Softmax(dim=-1) self.detect = Detect(self.args, self.cfg, self.num_classes)
def __init__(self, backbone='resnet', output_stride=16, num_classes=21, sync_bn=False, freeze_bn=False, mc_dropout=False): super(DeepLab, self).__init__() if backbone == 'drn': output_stride = 8 if sync_bn == True: BatchNorm = SynchronizedBatchNorm2d else: BatchNorm = nn.BatchNorm2d self.backbone = build_backbone(backbone, output_stride, BatchNorm, mc_dropout=mc_dropout) self.aspp = build_aspp(backbone, output_stride, BatchNorm) self.decoder = build_decoder(num_classes, backbone, BatchNorm) self.return_features = False if freeze_bn: self.freeze_bn()
def build(args): backbone = build_backbone(args) transformer = build_transformer(args) model = DETR(backbone, transformer, num_classes=args.classes, num_queries=args.num_queries, aux_loss=args.aux_loss) if args.masks: raise NotImplementedError('Segmentation model is not implemented yet.')
def __init__(self, args): super(DeepLab, self).__init__() if args.backbone == 'drn': output_stride = 8 else: output_stride = args.output_stride if args.sync_bn == True: BatchNorm = SynchronizedBatchNorm2d else: BatchNorm = nn.BatchNorm2d self.backbone = build_backbone(args.backbone, output_stride, BatchNorm) self.aspp = build_aspp(args.backbone, output_stride, BatchNorm) self.decoder = build_decoder(args.num_classes, args.backbone, BatchNorm) self.freeze_bn = args.freeze_bn
def __init__(self, backbone='resnst', sync_bn=False, num_classes=1000, freeze_bn=False, output_scale=16, pretrained=False): super(DeepLabV3Plus, self).__init__() if backbone == 'drn': output_scale = 8 self.backbone = build_backbone(backbone, output_scale, sync_bn, pretrained) self.aspp = ASPP(backbone, output_scale, sync_bn) self.decoder = Decoder(backbone, num_classes, sync_bn) if freeze_bn: for m in self.modules(): if isinstance(m, nn.BatchNorm2d): m.eval()
def __init__(self, num_blocks, num_classes, back_bone='resnet', pretrained=True): super(FPN, self).__init__() self.in_planes = 64 self.num_classes = num_classes self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, bias=False) self.bn1 = nn.BatchNorm2d(64) BatchNorm = nn.BatchNorm2d self.back_bone = build_backbone(back_bone) # Bottom-up layers self.layer1 = self._make_layer(Bottleneck, 64, num_blocks[0], stride=1) self.layer2 = self._make_layer(Bottleneck, 128, num_blocks[1], stride=2) self.layer3 = self._make_layer(Bottleneck, 256, num_blocks[2], stride=2) self.layer4 = self._make_layer(Bottleneck, 512, num_blocks[3], stride=2) # Top layer self.toplayer = nn.Conv2d(2048, 256, kernel_size=1, stride=1, padding=0) # Reduce channels # 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) self.smooth3 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) # Lateral layers self.latlayer1 = nn.Conv2d(1024, 256, kernel_size=1, stride=1, padding=0) self.latlayer2 = nn.Conv2d(512, 256, kernel_size=1, stride=1, padding=0) self.latlayer3 = nn.Conv2d(256, 256, kernel_size=1, stride=1, padding=0) # Semantic branch self.semantic_branch = nn.Conv2d(256, 128, kernel_size=3, stride=1, padding=1) self.conv2 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) self.conv3 = nn.Conv2d(128, self.num_classes, kernel_size=1, stride=1, padding=0) # num_groups, num_channels self.gn1 = nn.GroupNorm(128, 128) self.gn2 = nn.GroupNorm(256, 256)
def __init__(self, backbone='xception', num_classes=3): super(GNet, self).__init__() filters = [32, 64, 128, 256, 512] Norm_layer = nn.InstanceNorm3d self.backbone = build_backbone(backbone, filters, Norm_layer) self.decoder = build_decoder(num_classes, filters, Norm_layer)