def __init__(self, cfg, in_channels): # from .loss import make_rpn_loss_evaluator # from .inference import make_rpn_postprocessor super(RPNModule, self).__init__() self.cfg = cfg rpn_box_coder = BoxCoder( weights=cfg.RPN.BOX_REG_WEIGHTS, lib=torch) # weights=(1.0, 1.0, 1.0, 1.0, 1.0)) self.anchor_generator = make_anchor_generator(cfg) self.head = RPNHead( in_channels, self.anchor_generator.num_anchors_per_location()[0]) # raise NotImplementedError self.box_selector_train = make_rpn_postprocessor(cfg, rpn_box_coder, is_train=True) self.box_selector_test = make_rpn_postprocessor(cfg, rpn_box_coder, is_train=False) self.loss_evaluator = make_rpn_loss_evaluator(cfg, rpn_box_coder)
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 self.nms_rotate = RotateNMS(nms_threshold=nms_thresh, post_nms_top_n=post_nms_top_n) if box_coder is None: box_coder = BoxCoder(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
def make_roi_box_post_processor(cfg): bbox_reg_weights = cfg.ROI_HEADS.BBOX_REG_WEIGHTS box_coder = BoxCoder(weights=bbox_reg_weights, lib=torch) score_thresh = cfg.ROI_HEADS.SCORE_THRESH nms_thresh = cfg.ROI_HEADS.NMS detections_per_img = cfg.ROI_HEADS.DETECTIONS_PER_IMG cls_agnostic_bbox_reg = cfg.CLS_AGNOSTIC_BBOX_REG postprocessor = PostProcessor(score_thresh, nms_thresh, detections_per_img, box_coder, cls_agnostic_bbox_reg) return postprocessor
def __init__(self, cfg, in_channels): super(RPNModule, self).__init__() anchor_generator = make_anchor_generator(cfg) head = RPNHead( in_channels, anchor_generator.num_anchors_per_location()[0] ) rpn_box_coder = BoxCoder(weights=(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 = make_rpn_loss_evaluator(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
def make_roi_box_loss_evaluator(cfg): from matcher import Matcher from sampler import BalancedPositiveNegativeSampler matcher = Matcher( cfg.ROI_HEADS.FG_IOU_THRESHOLD, cfg.ROI_HEADS.BG_IOU_THRESHOLD, allow_low_quality_matches=False, ) bbox_reg_weights = cfg.ROI_HEADS.BBOX_REG_WEIGHTS box_coder = BoxCoder(weights=bbox_reg_weights, lib=torch) fg_bg_sampler = BalancedPositiveNegativeSampler( cfg.ROI_HEADS.BATCH_SIZE_PER_IMAGE, cfg.ROI_HEADS.POSITIVE_FRACTION) cls_agnostic_bbox_reg = cfg.CLS_AGNOSTIC_BBOX_REG loss_evaluator = FastRCNNLossComputation(matcher, fg_bg_sampler, box_coder, cls_agnostic_bbox_reg) return loss_evaluator
def __init__(self, score_thresh=0.05, nms=0.5, detections_per_img=100, box_coder=None, cls_agnostic_bbox_reg=False): """ Arguments: box_coder (BoxCoder) """ super(PostProcessor, self).__init__() self.score_thresh = score_thresh self.nms = nms self.detections_per_img = detections_per_img self.nms_rotate = RotateNMS(nms_threshold=nms, post_nms_top_n=detections_per_img) if box_coder is None: box_coder = BoxCoder(weights=None, lib=torch) self.box_coder = box_coder self.cls_agnostic_bbox_reg = cls_agnostic_bbox_reg