Example #1
0
    def __init__(
        self,
        pre_nms_top_n,
        post_nms_top_n,
        nms_thresh,
        min_size,
        box_coder=None,
        fpn_post_nms_top_n=None,
    ):
        """
        Arguments:
            pre_nms_top_n (int)
            post_nms_top_n (int)
            nms_thresh (float)
            min_size (int)
            box_coder (BoxCoder)
            fpn_post_nms_top_n (int)
        """
        super(RPNPostProcessor, self).__init__()
        self.pre_nms_top_n = pre_nms_top_n
        self.post_nms_top_n = post_nms_top_n
        self.nms_thresh = nms_thresh
        self.min_size = min_size

        if box_coder is None:
            box_coder = RBoxCoder(weights=(1.0, 1.0, 1.0, 1.0, 1.0))
        self.box_coder = box_coder

        if fpn_post_nms_top_n is None:
            fpn_post_nms_top_n = post_nms_top_n
        self.fpn_post_nms_top_n = fpn_post_nms_top_n
Example #2
0
    def __init__(self, cfg):
        super(RPNModule, self).__init__()

        self.cfg = cfg.clone()

        anchor_generator = make_anchor_generator(cfg)

        in_channels = cfg.MODEL.BACKBONE.OUT_CHANNELS
        rpn_head = registry.RPN_HEADS[cfg.MODEL.RPN.RPN_HEAD]
        head = rpn_head(cfg, in_channels, 1)

        rpn_box_coder = RBoxCoder(weights=(1.0, 1.0, 1.0, 1.0, 1.0))

        box_selector_train = make_rpn_postprocessor(cfg,
                                                    rpn_box_coder,
                                                    is_train=True)
        box_selector_test = make_rpn_postprocessor(cfg,
                                                   rpn_box_coder,
                                                   is_train=False)

        loss_evaluator = loss_evaluator_dict[cfg.MODEL.RPN.RPN_HEAD](
            cfg, rpn_box_coder)

        self.anchor_generator = anchor_generator
        self.head = head
        self.box_selector_train = box_selector_train
        self.box_selector_test = box_selector_test
        self.loss_evaluator = loss_evaluator
        self.loss_name = loss_name_dict[cfg.MODEL.RPN.RPN_HEAD]
Example #3
0
def make_roi_box_post_processor(cfg):
    use_fpn = cfg.MODEL.ROI_HEADS.USE_FPN

    bbox_reg_weights = cfg.MODEL.ROI_HEADS.RBBOX_REG_WEIGHTS
    box_coder = RBoxCoder(weights=bbox_reg_weights)

    score_thresh = cfg.MODEL.ROI_HEADS.SCORE_THRESH
    nms_thresh = cfg.MODEL.ROI_HEADS.NMS
    detections_per_img = cfg.MODEL.ROI_HEADS.DETECTIONS_PER_IMG

    postprocessor = PostProcessor(score_thresh, nms_thresh, detections_per_img,
                                  box_coder)
    return postprocessor
Example #4
0
 def __init__(
     self, score_thresh=0.05, nms=0.5, detections_per_img=100, box_coder=None
 ):
     """
     Arguments:
         score_thresh (float)
         nms (float)
         detections_per_img (int)
         box_coder (BoxCoder)
     """
     super(PostProcessor, self).__init__()
     self.score_thresh = score_thresh
     self.nms = nms
     self.detections_per_img = detections_per_img
     if box_coder is None:
         box_coder = RBoxCoder(weights=(10., 10., 5., 5., 1.))
     self.box_coder = box_coder
Example #5
0
def make_roi_box_loss_evaluator(cfg):
    matcher = Matcher(
        cfg.MODEL.ROI_HEADS.FG_IOU_THRESHOLD,
        cfg.MODEL.ROI_HEADS.BG_IOU_THRESHOLD,
        allow_low_quality_matches=False,
    )

    bbox_reg_weights = cfg.MODEL.ROI_HEADS.RBBOX_REG_WEIGHTS
    box_coder = RBoxCoder(weights=bbox_reg_weights)

    fg_bg_sampler = BalancedPositiveNegativeSampler(
        cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE,
        cfg.MODEL.ROI_HEADS.POSITIVE_FRACTION)

    loss_evaluator = FastRCNNLossComputation(matcher, fg_bg_sampler, box_coder)

    return loss_evaluator
Example #6
0
 def __init__(
     self, score_thresh=0.02, nms=0.5, detections_per_img=100, box_coder=None, nms_type="remove", shrink_margin=1.4
 ):
     """
     Arguments:
         score_thresh (float)
         nms (float)
         detections_per_img (int)
         box_coder (BoxCoder)
         nms_type: "remove" or "merge"
     """
     super(PostProcessor, self).__init__()
     self.score_thresh = score_thresh
     self.nms = nms
     self.detections_per_img = detections_per_img
     if box_coder is None:
         box_coder = RBoxCoder(weights=(10., 10., 5., 5., 1.))
     self.box_coder = box_coder
     self.shrink_margin = shrink_margin
     self.nms_fn = boxlist_nms if nms_type == "remove" else cluster_nms
     self.update_cls = False
     self.update_box = False
Example #7
0
def make_roi_box_loss_evaluator(cfg):
    matcher = Matcher(
        cfg.MODEL.ROI_HEADS.FG_IOU_THRESHOLD,
        cfg.MODEL.ROI_HEADS.BG_IOU_THRESHOLD,
        allow_low_quality_matches=False,
        discard_high_matches=cfg.MODEL.ROI_HEADS.HIGHEST_DISCARD,
        highest_threshold=cfg.MODEL.ROI_HEADS.HIGHEST_THRESHOLD,
    )
    bbox_reg_weights = cfg.MODEL.ROI_HEADS.RBBOX_REG_WEIGHTS
    box_coder = RBoxCoder(weights=bbox_reg_weights)

    fg_bg_sampler = BalancedPositiveNegativeSampler(
        cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE,
        cfg.MODEL.ROI_HEADS.POSITIVE_FRACTION)

    edge_punished = cfg.MODEL.EDGE_PUNISHED
    loss_evaluator = FastRCNNLossComputation(
        matcher,
        fg_bg_sampler,
        box_coder,
        edge_punished,
        discard_highest=cfg.MODEL.ROI_HEADS.HIGHEST_DISCARD)

    return loss_evaluator
Example #8
0
    def __init__(self,
                 pre_nms_top_n,
                 post_nms_top_n,
                 nms_thresh,
                 min_size,
                 nms_type="remove",
                 box_coder=None,
                 fpn_post_nms_top_n=None,
                 base_size=640.,
                 scale_stack=[0.25, 0.125, 0.0625, 0.03125, 0.015625],
                 score_thresh=0.1):
        """
        Arguments:
            pre_nms_top_n (int)
            post_nms_top_n (int)
            nms_thresh (float)
            min_size (int)
            box_coder (BoxCoder)
            fpn_post_nms_top_n (int)
        """
        super(RPNPostProcessor, self).__init__()
        self.pre_nms_top_n = pre_nms_top_n
        self.post_nms_top_n = post_nms_top_n
        self.nms_thresh = nms_thresh
        self.min_size = min_size
        self.base_size = base_size
        self.score_thresh = score_thresh

        if box_coder is None:
            box_coder = RBoxCoder(weights=(1.0, 1.0, 1.0, 1.0, 1.0))
        self.box_coder = box_coder
        self.scale_stack = scale_stack
        if fpn_post_nms_top_n is None:
            fpn_post_nms_top_n = post_nms_top_n
        self.fpn_post_nms_top_n = fpn_post_nms_top_n
        self.nms_fn = boxlist_nms if nms_type == "remove" else cluster_nms