def __init__(self, cfg, in_channels):
        super(KeypointRCNNFeatureExtractor, self).__init__()

        use_gn = cfg.MODEL.ROI_KEYPOINT_HEAD.USE_GN

        use_contextual_pooler = False
        if use_contextual_pooler:
            pooler = make_contextual_pooler(cfg, 'ROI_KEYPOINT_HEAD')
        else:
            pooler = make_pooler(cfg, 'ROI_KEYPOINT_HEAD')
        self.pooler = pooler

        input_features = in_channels
        layers = cfg.MODEL.ROI_KEYPOINT_HEAD.CONV_LAYERS
        resolution = cfg.MODEL.ROI_KEYPOINT_HEAD.POOLER_RESOLUTION
        next_feature = input_features
        self.blocks = []
        for layer_idx, layer_features in enumerate(layers, 1):
            layer_name = "kp_fcn{}".format(layer_idx)
            module = make_conv3x3(
                next_feature, layer_features,
                dilation=1, stride=1, use_gn=use_gn, use_relu=True, kaiming_init=True
            )
            self.add_module(layer_name, module)
            next_feature = layer_features
            self.blocks.append(layer_name)
        self.out_channels = layer_features
        if cfg.MODEL.ROI_KEYPOINT_HEAD.ATTENTION_ON:
            self.regional_attention = RegionalAttention(cfg, in_channels, self.pooler, resolution)
        else:
            self.regional_attention = None
示例#2
0
    def __init__(self, cfg, in_channels):
        """
        Arguments:
            num_classes (int): number of output classes
            input_size (int): number of channels of the input once it's flattened
            representation_size (int): size of the intermediate representation
        """
        super(MaskRCNNFPNFeatureExtractor, self).__init__()

        use_contextual_pooler = False
        if use_contextual_pooler:
            pooler = make_contextual_pooler(cfg, 'ROI_MASK_HEAD')
        else:
            pooler = make_pooler(cfg, 'ROI_MASK_HEAD')

        input_size = in_channels
        self.pooler = pooler

        use_gn = cfg.MODEL.ROI_MASK_HEAD.USE_GN
        layers = cfg.MODEL.ROI_MASK_HEAD.CONV_LAYERS
        dilation = cfg.MODEL.ROI_MASK_HEAD.DILATION
        resolution = cfg.MODEL.ROI_MASK_HEAD.POOLER_RESOLUTION

        use_dcn = cfg.MODEL.ROI_MASK_HEAD.USE_DCN
        dcn_config = {
            "with_modulated_dcn": cfg.MODEL.ROI_MASK_HEAD.WITH_MODULATED_DCN,
            "deformable_groups": cfg.MODEL.ROI_MASK_HEAD.DEFORMABLE_GROUPS,
        }

        self.blocks, next_feature = make_blocks(
            layers,
            input_size,
            pattern='mask_fcn',
            parent=self,
            dilation=dilation,
            use_gn=use_gn,
            use_dcn=use_dcn,
            dcn_config=dcn_config,
        )

        self.out_channels = next_feature

        if cfg.MODEL.ROI_MASK_HEAD.ATTENTION_ON:
            self.regional_attention = RegionalAttention(
                cfg, in_channels, self.pooler, resolution)
        else:
            self.regional_attention = None
    def __init__(self, cfg, in_channels):
        super(FPNXconv1fcFeatureExtractor, self).__init__()

        resolution = cfg.MODEL.ROI_BOX_HEAD.POOLER_RESOLUTION

        use_contextual_pooler = False
        if use_contextual_pooler:
            pooler = make_contextual_pooler(cfg, 'ROI_BOX_HEAD')
        else:
            pooler = make_pooler(cfg, 'ROI_BOX_HEAD')

        input_size = in_channels
        self.pooler = pooler

        use_gn = cfg.MODEL.ROI_BOX_HEAD.USE_GN
        dilation = cfg.MODEL.ROI_BOX_HEAD.DILATION
        layers = cfg.MODEL.ROI_MASK_HEAD.CONV_LAYERS

        use_dcn = cfg.MODEL.ROI_BOX_HEAD.USE_DCN
        dcn_config = {
            "with_modulated_dcn": cfg.MODEL.ROI_BOX_HEAD.WITH_MODULATED_DCN,
            "deformable_groups": cfg.MODEL.ROI_BOX_HEAD.DEFORMABLE_GROUPS,
        }

        self.xconvs, next_feature = make_blocks(
            layers,
            input_size,
            pattern='xconvs',
            parent=self,
            dilation=dilation,
            use_gn=use_gn,
            use_dcn=use_dcn,
            dcn_config=dcn_config,
        )

        input_size = next_feature * resolution**2
        representation_size = cfg.MODEL.ROI_BOX_HEAD.MLP_HEAD_DIM
        self.fc6 = make_fc(input_size, representation_size, use_gn=False)
        self.out_channels = representation_size

        if cfg.MODEL.ROI_BOX_HEAD.ATTENTION_ON:
            self.regional_attention = RegionalAttention(
                cfg, in_channels, self.pooler, resolution)
        else:
            self.regional_attention = None
    def __init__(self, cfg, in_channels):
        super(FPN2MLPFeatureExtractor, self).__init__()

        resolution = cfg.MODEL.ROI_BOX_HEAD.POOLER_RESOLUTION

        use_contextual_pooler = False
        if use_contextual_pooler:
            pooler = make_contextual_pooler(cfg, 'ROI_BOX_HEAD')
        else:
            pooler = make_pooler(cfg, 'ROI_BOX_HEAD')

        input_size = in_channels * resolution**2
        representation_size = cfg.MODEL.ROI_BOX_HEAD.MLP_HEAD_DIM
        use_gn = cfg.MODEL.ROI_BOX_HEAD.USE_GN
        self.pooler = pooler
        self.fc6 = make_fc(input_size, representation_size, use_gn)
        self.fc7 = make_fc(representation_size, representation_size, use_gn)
        self.out_channels = representation_size
    def __init__(self, cfg, in_channels):
        super(ResNet50Conv5ROIFeatureExtractor, self).__init__()

        use_contextual_pooler = False
        if use_contextual_pooler:
            pooler = make_contextual_pooler(cfg, 'ROI_BOX_HEAD')
        else:
            pooler = make_pooler(cfg, 'ROI_BOX_HEAD')

        stage = resnet.StageSpec(index=4, block_count=3, return_features=False)
        head = resnet.ResNetHead(
            block_module=cfg.MODEL.RESNETS.TRANS_FUNC,
            stages=(stage, ),
            num_groups=cfg.MODEL.RESNETS.NUM_GROUPS,
            width_per_group=cfg.MODEL.RESNETS.WIDTH_PER_GROUP,
            stride_in_1x1=cfg.MODEL.RESNETS.STRIDE_IN_1X1,
            stride_init=None,
            res2_out_channels=cfg.MODEL.RESNETS.RES2_OUT_CHANNELS,
            dilation=cfg.MODEL.RESNETS.RES5_DILATION)

        self.pooler = pooler
        self.head = head
        self.out_channels = head.out_channels