docstr: Test outside anchors and topN filters
docstr_tok: ["Test","outside","anchors","and","topN","filters"]
code: def testOutsidersAndTopN(self):
      """
      Test outside anchors and topN filters
      """
      gt_boxes = np.array(
          [
              [10, 10, 20, 22],
              [10, 10, 20, 22],
              [10, 10, 20, 50],  # Outside anchor
              [10, 10, 20, 22],
          ]
      )
      all_anchors = np.array(
          [
              [11, 13, 34, 31],
              [10, 10, 20, 22],
              [11, 13, 34, 40],
              [7, 13, 34, 30],
          ]
      )
      rpn_cls_prob = np.array(
          [[0.3, 0.7], [0.4, 0.6], [0.9, 0.1], [0.8, 0.2]]
      )
  
      results = self._run_rpn_proposal(
          all_anchors, rpn_cls_prob, self.config, gt_boxes=gt_boxes
      )
  
      # Check we get exactly 3 'nms proposals' and 3 'unsorted_proposals'
      # because we have 4 gt_boxes, but 1 outsider (and nms_threshold = 1).
      self.assertEqual(results["proposals"].shape, (3, 4))
  
      # We don't remove proposals outside, we just clip them.
      self.assertEqual(results["unsorted_proposals"].shape, (4, 4))
  
      # Also check that we get the corrects scores.
      self.assertAllClose(results["scores"], [0.7, 0.6, 0.2])
  
      config = self.config
      config["post_nms_top_n"] = 2
  
      results = self._run_rpn_proposal(
          all_anchors, rpn_cls_prob, config, gt_boxes=gt_boxes
      )
  
      # Check that with a post_nms_top_n = 2 we have only 2 'nms proposals'
      # but 3 'unsorted_proposals'.
      self.assertAllEqual(results["proposals"].shape, (2, 4))
  
      self.assertEqual(results["unsorted_proposals"].shape, (4, 4))
  
      # Also check that we get the corrects scores.
      self.assertAllClose(results["scores"], [0.7, 0.6])
  
      # Sorted
      self.assertAllClose(
          results["sorted_top_scores"], [0.7, 0.6, 0.2, 0.1]
      )
  
      # Check that we only filter by pre_nms_top_n
      config["post_nms_top_n"] = 3
      config["pre_nms_top_n"] = 2
  
      results = self._run_rpn_proposal(
          all_anchors, rpn_cls_prob, config, gt_boxes=gt_boxes
      )
  
      # Check that with a post_nms_top_n = 3 and pre_nms_top = 2
      # we have only 2 'nms proposals' and 2 'unsorted_proposals'.
  
      self.assertAllEqual(results["proposals"].shape, (2, 4))
  
      # Filter pre nms
      self.assertEqual(results["sorted_top_proposals"].shape, (2, 4))
  
      # Also check that we get the corrects scores.
      self.assertAllClose(results["scores"], [0.7, 0.6])
  
      self.assertAllClose(results["sorted_top_scores"], [0.7, 0.6])
  
      config["post_nms_top_n"] = 1
      config["pre_nms_top_n"] = 2
  
      results = self._run_rpn_proposal(
          all_anchors, rpn_cls_prob, config, gt_boxes=gt_boxes
      )
  
      # Check that with a post_nms_top_n = 1 and pre_nms_top = 2
      # we have only 1 'nms proposals' and 2 'unsorted_proposals'.
      self.assertAllEqual(results["proposals"].shape, (1, 4))
  
      self.assertEqual(results["sorted_top_proposals"].shape, (2, 4))
  
      # Also check that we get the corrects scores.
      self.assertAllClose(results["scores"], [0.7])
  
      self.assertAllClose(results["sorted_top_scores"], [0.7, 0.6])
  
file_path: luminoth/luminoth/models/fasterrcnn/rpn_proposal_test.py
imports: import numpy
  import tensorflow
  from easydict import EasyDict
  from luminoth.models.fasterrcnn.rpn_proposal import RPNProposal
  from luminoth.utils.bbox_transform_tf import encode, clip_boxes
label_desc: Use image node_id 4 for calling the RPNProposalTest obj's underlying member method code with example usage: obj.testOutsidersAndTopN() without return types