docstr: Test nms threshold
docstr_tok: ["Test","nms","threshold"]
code: def testNMSThreshold(self):
      """
      Test nms threshold
      """
      gt_boxes = np.array(
          [
              [10, 10, 26, 36],
              [10, 10, 20, 22],
              [10, 11, 20, 21],
              [19, 30, 33, 38],
          ]
      )
      """
          IoU Matrix of gt_boxes
          [[ 1.          0.31154684  0.26361656  0.10408922]
           [ 0.31154684  1.          0.84615385  0.        ]
           [ 0.26361656  0.84615385  1.          0.        ]
           [ 0.10408922  0.          0.          1.        ]]
          """
      all_anchors = np.array(
          [
              [11, 13, 34, 31],
              [10, 10, 20, 22],
              [11, 13, 34, 28],
              [21, 29, 34, 37],
          ]
      )
      rpn_cls_prob = np.array(
          [[0.8, 0.2], [0.1, 0.9], [0.4, 0.6], [0.2, 0.8]]
      )
      config = self.config
      config["post_nms_top_n"] = 4
      config["nms_threshold"] = 0.0
  
      results = self._run_rpn_proposal(
          all_anchors, rpn_cls_prob, self.config, gt_boxes=gt_boxes
      )
  
      # Check we get exactly 2 'nms proposals' because 2 IoU equals to 0.
      # Also check that we get the corrects scores.
      self.assertEqual(results["proposals"].shape, (2, 4))
  
      self.assertAllClose(results["scores"], [0.9, 0.8])
  
      config["nms_threshold"] = 0.3
  
      results = self._run_rpn_proposal(
          all_anchors, rpn_cls_prob, self.config, gt_boxes=gt_boxes
      )
  
      # Check we get exactly 3 'nms proposals' because 3 IoU lowers than 0.3.
      # Also check that we get the corrects scores.
      self.assertEqual(results["proposals"].shape, (3, 4))
  
      self.assertAllClose(results["scores"], [0.9, 0.8, 0.2])
  
      config["nms_threshold"] = 0.6
  
      results = self._run_rpn_proposal(
          all_anchors, rpn_cls_prob, self.config, gt_boxes=gt_boxes
      )
  
      # Check we get exactly 3 'nms proposals' because 3 IoU lowers than 0.3.
      # Also check that we get the corrects scores.
      self.assertEqual(results["proposals"].shape, (3, 4))
  
      self.assertAllClose(results["scores"], [0.9, 0.8, 0.2])
  
      config["nms_threshold"] = 0.8
  
      results = self._run_rpn_proposal(
          all_anchors, rpn_cls_prob, self.config, gt_boxes=gt_boxes
      )
  
      # Check we get exactly 3 'nms proposals' because 3 IoU lowers than 0.8.
      # Also check that we get the corrects scores.
      self.assertEqual(results["proposals"].shape, (3, 4))
  
      self.assertAllClose(results["scores"], [0.9, 0.8, 0.2])
  
      config["nms_threshold"] = 1.0
  
      results = self._run_rpn_proposal(
          all_anchors, rpn_cls_prob, self.config, gt_boxes=gt_boxes
      )
  
      # Check we get 'post_nms_top_n' nms proposals because
      # 'nms_threshold' = 1 and this only removes duplicates.
      self.assertEqual(results["proposals"].shape, (4, 4))
  
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 3 for calling the RPNProposalTest obj's underlying member method code with example usage: obj.testNMSThreshold() without return types