예제 #1
0
    def __init__(self, anchor, match_threshold=0.5, unmatched_threshold=0.5):
        """Constructs anchor labeler to assign labels to anchors.

    Args:
      anchor: an instance of class Anchors.
      match_threshold: a float number between 0 and 1 representing the
        lower-bound threshold to assign positive labels for anchors. An anchor
        with a score over the threshold is labeled positive.
      unmatched_threshold: a float number between 0 and 1 representing the
        upper-bound threshold to assign negative labels for anchors. An anchor
        with a score below the threshold is labeled negative.
    """
        similarity_calc = iou_similarity.IouSimilarity()
        matcher = argmax_matcher.ArgMaxMatcher(
            match_threshold,
            unmatched_threshold=unmatched_threshold,
            negatives_lower_than_unmatched=True,
            force_match_for_each_row=True)
        box_coder = faster_rcnn_box_coder.FasterRcnnBoxCoder()

        self._target_assigner = target_assigner.TargetAssigner(
            similarity_calc, matcher, box_coder)
        self._anchor = anchor
        self._match_threshold = match_threshold
        self._unmatched_threshold = unmatched_threshold
예제 #2
0
    def __init__(self,
                 mix_gt_boxes: bool = True,
                 num_sampled_rois: int = 512,
                 foreground_fraction: float = 0.25,
                 foreground_iou_threshold: float = 0.5,
                 background_iou_high_threshold: float = 0.5,
                 background_iou_low_threshold: float = 0,
                 skip_subsampling: bool = False,
                 **kwargs):
        """Initializes a ROI sampler.

    Args:
      mix_gt_boxes: A `bool` of whether to mix the groundtruth boxes with
        proposed ROIs.
      num_sampled_rois: An `int` of the number of sampled ROIs per image.
      foreground_fraction: A `float` in [0, 1], what percentage of proposed ROIs
        should be sampled from the foreground boxes.
      foreground_iou_threshold: A `float` that represents the IoU threshold for
        a box to be considered as positive (if >= `foreground_iou_threshold`).
      background_iou_high_threshold: A `float` that represents the IoU threshold
        for a box to be considered as negative (if overlap in
        [`background_iou_low_threshold`, `background_iou_high_threshold`]).
      background_iou_low_threshold: A `float` that represents the IoU threshold
        for a box to be considered as negative (if overlap in
        [`background_iou_low_threshold`, `background_iou_high_threshold`])
      skip_subsampling: a bool that determines if we want to skip the sampling
        procedure than balances the fg/bg classes. Used for upper frcnn layers
        in cascade RCNN.
      **kwargs: Additional keyword arguments passed to Layer.
    """
        self._config_dict = {
            'mix_gt_boxes': mix_gt_boxes,
            'num_sampled_rois': num_sampled_rois,
            'foreground_fraction': foreground_fraction,
            'foreground_iou_threshold': foreground_iou_threshold,
            'background_iou_high_threshold': background_iou_high_threshold,
            'background_iou_low_threshold': background_iou_low_threshold,
            'skip_subsampling': skip_subsampling,
        }

        self._sim_calc = iou_similarity.IouSimilarity()
        self._box_matcher = box_matcher.BoxMatcher(thresholds=[
            background_iou_low_threshold, background_iou_high_threshold,
            foreground_iou_threshold
        ],
                                                   indicators=[-3, -1, -2, 1])
        self._target_gather = target_gather.TargetGather()

        self._sampler = box_sampler.BoxSampler(num_sampled_rois,
                                               foreground_fraction)
        super(ROISampler, self).__init__(**kwargs)
예제 #3
0
    def __init__(self, match_threshold=0.5, unmatched_threshold=0.5):
        """Constructs anchor labeler to assign labels to anchors.

    Args:
      match_threshold: a float number between 0 and 1 representing the
        lower-bound threshold to assign positive labels for anchors. An anchor
        with a score over the threshold is labeled positive.
      unmatched_threshold: a float number between 0 and 1 representing the
        upper-bound threshold to assign negative labels for anchors. An anchor
        with a score below the threshold is labeled negative.
    """
        self.similarity_calc = iou_similarity.IouSimilarity()
        self.target_gather = target_gather.TargetGather()
        self.matcher = box_matcher.BoxMatcher(
            thresholds=[unmatched_threshold, match_threshold],
            indicators=[-1, -2, 1],
            force_match_for_each_col=True)
        self.box_coder = faster_rcnn_box_coder.FasterRcnnBoxCoder()
예제 #4
0
    def test_similarity_unbatched(self):
        boxes = tf.constant([
            [0, 0, 1, 1],
            [5, 0, 10, 5],
        ], dtype=tf.float32)

        gt_boxes = tf.constant([
            [0, 0, 5, 5],
            [0, 5, 5, 10],
            [5, 0, 10, 5],
            [5, 5, 10, 10],
        ],
                               dtype=tf.float32)

        sim_calc = iou_similarity.IouSimilarity()
        sim_matrix = sim_calc(boxes, gt_boxes)

        self.assertAllClose(sim_matrix.numpy(),
                            [[0.04, 0, 0, 0], [0, 0, 1., 0]])
예제 #5
0
    def __init__(self,
                 anchor,
                 match_threshold=0.7,
                 unmatched_threshold=0.3,
                 rpn_batch_size_per_im=256,
                 rpn_fg_fraction=0.5,
                 has_centerness=False,
                 center_match_iou_threshold=0.3,
                 center_unmatched_iou_threshold=0.1,
                 num_center_samples_per_im=256):
        """Constructs rpn anchor labeler to assign labels and centerness to anchors.

    Args:
      anchor: an instance of class Anchors.
      match_threshold: a float number between 0 and 1 representing the
        lower-bound threshold to assign positive labels for anchors. An anchor
        with a score over the threshold is labeled positive.
      unmatched_threshold: a float number between 0 and 1 representing the
        upper-bound threshold to assign negative labels for anchors. An anchor
        with a score below the threshold is labeled negative.
      rpn_batch_size_per_im: number of anchors that are sampled per image.
      rpn_fg_fraction:
      has_centerness: whether to include centerness target creation. An anchor
        is paired with one centerness score.
      center_match_iou_threshold: a float number between 0 and 1 representing
        the lower-bound threshold to sample foreground anchors for centerness
        regression. An anchor with a score over the threshold is sampled as
        foreground sample for centerness regression. We sample mostly from the
        foreground region (255 out of 256 samples). That is, we sample 255 vs 1
        (foreground vs background) anchor points to learn centerness regression.
      center_unmatched_iou_threshold: a float number between 0 and 1
        representing the lower-bound threshold to sample background anchors for
        centerness regression. An anchor with a score over the threshold is
        sampled as foreground sample for centerness regression. We sample very
        sparsely from the background region (1 out of 256 samples). That is, we
        sample 255 vs 1 (foreground vs background) anchor points to learn
        centerness regression.
      num_center_samples_per_im: number of anchor points per image that are
        sampled as centerness targets.
    """
        super(OlnAnchorLabeler,
              self).__init__(anchor,
                             match_threshold=match_threshold,
                             unmatched_threshold=unmatched_threshold,
                             rpn_batch_size_per_im=rpn_batch_size_per_im,
                             rpn_fg_fraction=rpn_fg_fraction)
        similarity_calc = iou_similarity.IouSimilarity()
        matcher = argmax_matcher.ArgMaxMatcher(
            match_threshold,
            unmatched_threshold=unmatched_threshold,
            negatives_lower_than_unmatched=True,
            force_match_for_each_row=True)
        box_coder = faster_rcnn_box_coder.FasterRcnnBoxCoder()
        if has_centerness:
            center_matcher = argmax_matcher.ArgMaxMatcher(
                center_match_iou_threshold,
                unmatched_threshold=center_match_iou_threshold,
                negatives_lower_than_unmatched=True,
                force_match_for_each_row=True,
            )
        else:
            center_matcher = None

        self._target_assigner = target_assigner.OlnTargetAssigner(
            similarity_calc, matcher, box_coder, center_matcher=center_matcher)
        self._num_center_samples_per_im = num_center_samples_per_im
        self._center_unmatched_iou_threshold = center_unmatched_iou_threshold
        self._rpn_batch_size_per_im = rpn_batch_size_per_im
        self._rpn_fg_fraction = rpn_fg_fraction