Exemplo n.º 1
0
    def __init__(self,
                 num_stages,
                 backbone,
                 neck=None,
                 shared_head=None,
                 rpn_head=None,
                 bbox_roi_extractor=None,
                 bbox_head=None,
                 count_head=None,
                 similar_head=None,
                 mask_roi_extractor=None,
                 mask_head=None,
                 pretrained=None,
                 train_cfg=None,
                 test_cfg=None):
        super(CaSe_CascadeRCNN, self).__init__()
        self.num_stages = num_stages
        self.backbone = builder.build_backbone(backbone)

        if neck is not None:
            self.neck = builder.build_neck(neck)

        if shared_head is not None:
            self.shared_head = builder.build_shared_head(shared_head)

        if rpn_head is not None:
            self.rpn_head = builder.build_head(rpn_head)

        if count_head is not None:
            self.count_head = builder.build_head(count_head)

        if similar_head is not None:
            self.similar_head = builder.build_head(similar_head)

        if bbox_head is not None:
            self.bbox_roi_extractor = nn.ModuleList()
            self.bbox_head = nn.ModuleList()
            if not isinstance(bbox_roi_extractor, list):
                bbox_roi_extractor = [
                    bbox_roi_extractor for _ in range(num_stages)
                ]
            if not isinstance(bbox_head, list):
                bbox_head = [bbox_head for _ in range(num_stages)]
            assert len(bbox_roi_extractor) == len(bbox_head) == self.num_stages
            for roi_extractor, head in zip(bbox_roi_extractor, bbox_head):
                self.bbox_roi_extractor.append(
                    builder.build_roi_extractor(roi_extractor))
                self.bbox_head.append(builder.build_head(head))

        if mask_head is not None:
            self.mask_roi_extractor = builder.build_roi_extractor(
                mask_roi_extractor)
            self.mask_head = builder.build_head(mask_head)

        self.train_cfg = train_cfg
        self.test_cfg = test_cfg
Exemplo n.º 2
0
    def __init__(self,
                 backbone,
                 neck=None,
                 shared_head=None,
                 rpn_head=None,
                 bbox_roi_extractor=None,
                 bbox_head=None,
                 mask_roi_extractor=None,
                 mask_head=None,
                 train_cfg=None,
                 test_cfg=None,
                 pretrained=None,
                 seg_cfg=None,
                 cap_cfg=None,
                 seg_scales=[0.5, 0.75],
                 ):
        super(EncoderDecoder, self).__init__()
        self.backbone = builder.build_backbone(backbone)

        if neck is not None:
            self.neck = builder.build_neck(neck)

        if shared_head is not None:
            self.shared_head = builder.build_shared_head(shared_head)

        if rpn_head is not None:
            self.rpn_head = builder.build_head(rpn_head)

        if bbox_head is not None:
            self.bbox_roi_extractor = builder.build_roi_extractor(
                bbox_roi_extractor)
            self.bbox_head = builder.build_head(bbox_head)

        if mask_head is not None:
            if mask_roi_extractor is not None:
                self.mask_roi_extractor = builder.build_roi_extractor(
                    mask_roi_extractor)
                self.share_roi_extractor = False
            else:
                self.share_roi_extractor = True
                self.mask_roi_extractor = self.bbox_roi_extractor
            self.mask_head = builder.build_head(mask_head)

        if seg_cfg is not None:
            self.seg_decoder = DeeplabDecoder(**seg_cfg)
            self.seg_scales = seg_scales
        if cap_cfg is not None:
            self.cap_decoder = CapDecoder(**cap_cfg)

        self.train_cfg = train_cfg
        self.test_cfg = test_cfg

        self.init_weights(pretrained=pretrained)
Exemplo n.º 3
0
 def __init__(self,
             num_classes,
             base_size,
             rroi_extractor):
     super(Blender, self).__init__()
     self.num_classes = num_classes
     self.base_size = base_size
     self.rroi_extractor = builder.build_roi_extractor(rroi_extractor)
 def init_mask_head(self, mask_roi_extractor, mask_head):
     """Initialize ``mask_head``"""
     if mask_roi_extractor is not None:
         self.mask_roi_extractor = build_roi_extractor(mask_roi_extractor)
         self.share_roi_extractor = False
     else:
         self.share_roi_extractor = True
         self.mask_roi_extractor = self.bbox_roi_extractor
     self.mask_head = build_head(mask_head)
Exemplo n.º 5
0
    def __init__(self,
                 backbone,
                 neck=None,
                 shared_head=None,
                 rpn_head=None,
                 bbox_roi_extractor=None,
                 bbox_head=None,
                 count_head=None,
                 similar_head=None,
                 mask_roi_extractor=None,
                 mask_head=None,
                 pretrained=None,
                 train_cfg=None,
                 test_cfg=None):
        super(CaSe, self).__init__()
        self.backbone = builder.build_backbone(backbone)

        if neck is not None:
            self.neck = builder.build_neck(neck)

        if shared_head is not None:
            self.shared_head = builder.build_shared_head(shared_head)

        if rpn_head is not None:
            self.rpn_head = builder.build_head(rpn_head)

        if count_head is not None:
            self.count_head = builder.build_head(count_head)

        if similar_head is not None:
            self.similar_head = builder.build_head(similar_head)

        if bbox_head is not None:
            self.bbox_roi_extractor = builder.build_roi_extractor(
                bbox_roi_extractor)
            self.bbox_head = builder.build_head(bbox_head)
        if mask_head is not None:
            self.mask_roi_extractor = builder.build_roi_extractor(
                mask_roi_extractor)
            self.mask_head = builder.build_head(mask_head)

        self.train_cfg = train_cfg
        self.test_cfg = test_cfg
    def __init__(self,
                 backbone,
                 neck=None,
                 rpn_head=None,
                 bbox_roi_extractor=None,
                 action_head=None,
                 bbox_head=None,
                 mask_roi_extractor=None,
                 mask_head=None,
                 train_cfg=None,
                 test_cfg=None,
                 pretrained=None):
        super(TwoStageDetector, self).__init__()
        self.backbone = builder.build_backbone(backbone)

        if neck is not None:
            self.neck = builder.build_neck(neck)
        else:
            raise NotImplementedError

        if rpn_head is not None:
            self.rpn_head = builder.build_rpn_head(rpn_head)
        if action_head is not None:
            self.action_head = builder_.build_actionhead(action_head)
        if bbox_head is not None:
            self.bbox_roi_extractor = builder.build_roi_extractor(
                bbox_roi_extractor)
            self.bbox_head = builder.build_bbox_head(bbox_head)

        if mask_head is not None:
            self.mask_roi_extractor = builder.build_roi_extractor(
                mask_roi_extractor)
            self.mask_head = builder.build_mask_head(mask_head)

        self.train_cfg = train_cfg
        self.test_cfg = test_cfg

        self.init_weights(pretrained=pretrained)
Exemplo n.º 7
0
    def __init__(self,
                 semantic_in_channel=256,
                 semantic_out_channel=256,
                 instance_in_channel=256,
                 instance_out_channel=256,
                 dilations=[1, 3, 5],
                 out_size=14,
                 num_classes=80,
                 semantic_out_stride=4,
                 mask_use_sigmoid=False,
                 upsample_cfg=dict(type='bilinear', scale_factor=2)):
        super(SFMStage, self).__init__()

        self.semantic_out_stride = semantic_out_stride
        self.mask_use_sigmoid = mask_use_sigmoid
        self.num_classes = num_classes

        # for extracting instance-wise semantic feats
        self.semantic_transform_in = nn.Conv2d(semantic_in_channel,
                                               semantic_out_channel, 1)
        self.semantic_roi_extractor = build_roi_extractor(
            dict(type='SingleRoIExtractor',
                 roi_layer=dict(type='RoIAlign',
                                output_size=out_size,
                                sampling_ratio=0),
                 out_channels=semantic_out_channel,
                 featmap_strides=[
                     semantic_out_stride,
                 ]))
        self.semantic_transform_out = nn.Conv2d(semantic_out_channel,
                                                semantic_out_channel, 1)

        self.instance_logits = nn.Conv2d(instance_in_channel, num_classes, 1)

        fuse_in_channel = instance_in_channel + semantic_out_channel + 2
        self.fuse_conv = nn.ModuleList([
            nn.Conv2d(fuse_in_channel, instance_in_channel, 1),
            MultiBranchFusion(instance_in_channel, dilations=dilations)
        ])

        self.fuse_transform_out = nn.Conv2d(instance_in_channel,
                                            instance_out_channel - 2, 1)
        self.upsample = build_upsample_layer(upsample_cfg.copy())
        self.relu = nn.ReLU(inplace=True)

        self._init_weights()
Exemplo n.º 8
0
    def init_bbox_head(self, bbox_roi_extractor, bbox_head):
        self.bbox_roi_extractor = nn.ModuleList()
        self.bbox_head = nn.ModuleList()
        if not isinstance(bbox_roi_extractor, list):
            bbox_roi_extractor = [
                bbox_roi_extractor for _ in range(self.num_stages)
            ]
        if not isinstance(bbox_head, list):
            bbox_head = [bbox_head for _ in range(self.num_stages)]
        assert len(bbox_roi_extractor) == len(bbox_head) == self.num_stages

        last_type = ['hbb', 'obb', 'poly']
        for roi_extractor, head in zip(bbox_roi_extractor, bbox_head):
            self.bbox_roi_extractor.append(build_roi_extractor(roi_extractor))
            self.bbox_head.append(build_head(head))

            assert self.bbox_head[-1].start_bbox_type in last_type
            last_type = [self.bbox_head[-1].end_bbox_type]
 def __init__(self,
              backbone,
              neck,
              rpn_head,
              train_cfg,
              test_cfg,
              bbox_roi_extractor=None,
              pretrained=None):
     super(newRPN, self).__init__()
     self.backbone = builder.build_backbone(backbone)
     self.neck = builder.build_neck(neck) if neck is not None else None
     self.rpn_head = builder.build_rpn_head(rpn_head)
     if bbox_roi_extractor is not None:
         self.bbox_roi_extractor = builder.build_roi_extractor(
             bbox_roi_extractor)
     self.train_cfg = train_cfg
     self.test_cfg = test_cfg
     self.init_weights(pretrained=pretrained)
Exemplo n.º 10
0
    def __init__(self, cfg):
        super(TrackerCnnModule, self).__init__()
        model = build_detector(cfg.model,
                               train_cfg=cfg.train_cfg,
                               test_cfg=cfg.test_cfg)
        checkpoint = glob.glob(os.path.join(mmdet_dir, work_dir, '*.pth'))[0]
        load_checkpoint(model, checkpoint)
        model = MMDataParallel(model, device_ids=[0])

        self.bbox_roi_extractor = builder.build_roi_extractor(
            cfg.bbox_roi_extractor)

        for param in model.parameters():
            param.requires_grad = False

        self.detector = model.module
        self.flatten = Flatten()
        self.cfg = cfg
Exemplo n.º 11
0
 def __init__(self,
              backbone,
              neck=None,
              bbox_head=None,
              extractor=dict(type='SingleRoIExtractor',
                             roi_layer=dict(type='RoIAlign', output_size=7),
                             featmap_strides=[1]),
              visual_modality=False,
              train_cfg=None,
              test_cfg=None,
              pretrained=None,
              class_list=None):
     super().__init__(backbone, neck, bbox_head, train_cfg, test_cfg,
                      pretrained)
     self.visual_modality = visual_modality
     if visual_modality:
         self.extractor = build_roi_extractor({
             **extractor, 'out_channels':
             self.backbone.base_channels
         })
         self.maxpool = nn.MaxPool2d(extractor['roi_layer']['output_size'])
     else:
         self.extractor = None
     self.class_list = class_list
Exemplo n.º 12
0
    def __init__(
        self,
        num_classes,
        roi_extractor,
        seq_model_type='MHA',  # {'MHA', 'TX'}
        use_skip_score=False,
        target_means=[0., 0., 0., 0.],
        target_stds=[0.1, 0.1, 0.2, 0.2],
        loss_cls=dict(type='CrossEntropyLoss',
                      use_sigmoid=True,
                      loss_weight=1.0),
        loss_bbox=dict(type='SmoothL1Loss', beta=1.0, loss_weight=1.0)):
        super(TxHead, self).__init__()
        self.num_classes = num_classes
        self.target_means = target_means
        self.target_stds = target_stds
        self.fp16_enabled = False

        self.use_sigmoid_cls = loss_cls.get('use_sigmoid', True)  # Was False
        self.loss_cls = build_loss(loss_cls)
        self.loss_bbox = build_loss(loss_bbox)

        self.feat_channels = roi_extractor.get('out_channels', 256)
        self.num_box_per_frame = 64

        self.use_skip_score = use_skip_score
        self.seq_channels = self.feat_channels + (self.num_classes - 1) + 4

        self.roi_extractor = builder.build_roi_extractor(roi_extractor)
        self.seq_model_type = seq_model_type
        if self.seq_model_type == 'MHA':
            self.seq_model = nn.MultiheadAttention(self.seq_channels, 2)
        elif self.seq_model_type == 'TX':
            self.seq_model = nn.Transformer(d_model=290, nhead=2)
        else:
            raise ValueError
 def init_bbox_head(self, bbox_roi_extractor, bbox_head):
     """Initialize ``bbox_head``"""
     self.bbox_roi_extractor = build_roi_extractor(bbox_roi_extractor)
     self.bbox_head = build_head(bbox_head)