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)
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()
def test_target_gather_unbatched(self): gt_boxes = tf.constant([ [0, 0, 5, 5], [0, 5, 5, 10], [5, 0, 10, 5], [5, 5, 10, 10], ], dtype=tf.float32) gt_classes = tf.constant([[2], [10], [3], [-1]], dtype=tf.int32) labeler = target_gather.TargetGather() match_indices = tf.constant([0, 2], dtype=tf.int32) match_indicators = tf.constant([-2, 1]) mask = tf.less_equal(match_indicators, 0) cls_mask = tf.expand_dims(mask, -1) matched_gt_classes = labeler(gt_classes, match_indices, cls_mask) box_mask = tf.tile(cls_mask, [1, 4]) matched_gt_boxes = labeler(gt_boxes, match_indices, box_mask) self.assertAllEqual(matched_gt_classes.numpy(), [[0], [3]]) self.assertAllClose(matched_gt_boxes.numpy(), [[0, 0, 0, 0], [5, 0, 10, 5]])