docstr: Test clipping of proposals before and after NMS
docstr_tok: ["Test","clipping","of","proposals","before","and","after","NMS"]
code: def testClippingOfProposals(self):
      """
      Test clipping of proposals before and after NMS
      """
      # Before NMS
      gt_boxes = np.array(
          [
              [0, 0, 10, 12],
              [10, 10, 20, 22],
              [10, 10, 20, 22],
              [30, 25, 39, 39],
          ]
      )
      all_anchors = np.array(
          [
              [-20, -10, 12, 6],
              [2, -10, 20, 20],
              [0, 0, 12, 16],
              [2, -10, 20, 2],
          ]
      )
      rpn_cls_prob = np.array(
          [
              [0.3, 0.7],
              [0.4, 0.6],
              [0.3, 0.7],
              [0.1, 0.9],
          ]
      )
  
      rpn_bbox_pred = np.array(
          [  # This is set to zeros so when decode is
              [0, 0, 0, 0],  # applied in RPNProposal the anchors don't
              [0, 0, 0, 0],  # change, leaving us with unclipped
              [0, 0, 0, 0],  # proposals.
              [0, 0, 0, 0],
          ]
      )
      config = EasyDict(self.config)
      config["clip_after_nms"] = False
      results_before = self._run_rpn_proposal(
          all_anchors,
          rpn_cls_prob,
          config,
          gt_boxes=gt_boxes,
          rpn_bbox_pred=rpn_bbox_pred,
      )
      im_size = tf.placeholder(tf.float32, shape=(2,))
      proposals_unclipped = tf.placeholder(
          tf.float32,
          shape=(results_before["proposals_unclipped"].shape),
      )
      clip_bboxes_tf = clip_boxes(proposals_unclipped, im_size)
  
      with self.test_session() as sess:
          clipped_proposals = sess.run(
              clip_bboxes_tf,
              feed_dict={
                  proposals_unclipped: results_before[
                      "proposals_unclipped"
                  ],
                  im_size: self.im_size,
              },
          )
  
      # Check we clip proposals right after filtering the invalid area ones.
      self.assertAllEqual(
          results_before["unsorted_proposals"], clipped_proposals
      )
  
      # Checks all NMS proposals have values inside the image boundaries
      proposals = results_before["proposals"]
      self.assertTrue((proposals >= 0).all())
      self.assertTrue(
          (proposals < np.array(self.im_size + self.im_size)).all()
      )
  
      # After NMS
      config["clip_after_nms"] = True
      results_after = self._run_rpn_proposal(
          all_anchors,
          rpn_cls_prob,
          config,
          gt_boxes=gt_boxes,
          rpn_bbox_pred=rpn_bbox_pred,
      )
      im_size = tf.placeholder(tf.float32, shape=(2,))
      proposals_unclipped = tf.placeholder(
          tf.float32, shape=(results_after["proposals_unclipped"].shape)
      )
      clip_bboxes_tf = clip_boxes(proposals_unclipped, im_size)
  
      with self.test_session() as sess:
          clipped_proposals = sess.run(
              clip_bboxes_tf,
              feed_dict={
                  proposals_unclipped: results_after[
                      "proposals_unclipped"
                  ],
                  im_size: self.im_size,
              },
          )
  
      # Check we don't clip proposals in the beginning of the function.
      self.assertAllEqual(
          results_after["unsorted_proposals"],
          results_after["proposals_unclipped"],
      )
  
      proposals = results_after["proposals"]
      # Checks all NMS proposals have values inside the image boundaries
      self.assertTrue((proposals >= 0).all())
      self.assertTrue(
          (proposals < np.array(self.im_size + self.im_size)).all()
      )
  
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 7 for calling the RPNProposalTest obj's underlying member method code with example usage: obj.testClippingOfProposals() without return types