docstr: Tests that loss returns reasonable values in simple cases.
          
code: def testLoss(self):
      """Tests that loss returns reasonable values in simple cases."""
      model = RPN(self.num_anchors, self.config, debug=True)
  
      # Define placeholders that are used inside the loss method.
      rpn_cls_prob = tf.placeholder(tf.float32)
      rpn_cls_target = tf.placeholder(tf.float32)
      rpn_cls_score = tf.placeholder(tf.float32)
      rpn_bbox_target = tf.placeholder(tf.float32)
      rpn_bbox_pred = tf.placeholder(tf.float32)
  
      loss = model.loss(
          {
              "rpn_cls_prob": rpn_cls_prob,
              "rpn_cls_target": rpn_cls_target,
              "rpn_cls_score": rpn_cls_score,
              "rpn_bbox_target": rpn_bbox_target,
              "rpn_bbox_pred": rpn_bbox_pred,
          }
      )
  
      # Test perfect score.
      with self.test_session() as sess:
          sess.run(tf.global_variables_initializer())
          loss_dict = sess.run(
              loss,
              feed_dict={
                  # Probability is (background_prob, foreground_prob)
                  rpn_cls_prob: [[0, 1], [1.0, 0]],
                  # Target: 1 being foreground, 0 being background.
                  rpn_cls_target: [1, 0],
                  # Class scores before applying softmax. Since using cross
                  # entropy, we need a big difference between values.
                  rpn_cls_score: [[-100.0, 100.0], [100.0, -100.0]],
                  # Targets and predictions are exactly equal.
                  rpn_bbox_target: [
                      [0.1, 0.1, 0.1, 0.1],
                      [0.1, 0.1, 0.1, 0.1],
                  ],
                  rpn_bbox_pred: [
                      [0.1, 0.1, 0.1, 0.1],
                      [0.1, 0.1, 0.1, 0.1],
                  ],
              },
          )
  
          # Assert close since cross-entropy could return very small value.
          self.assertAllClose(tuple(loss_dict.values()), (0, 0))
  
file_path: luminoth/luminoth/models/fasterrcnn/rpn_test.py
imports: import numpy
  import tensorflow
  from easydict import EasyDict
  from luminoth.models.fasterrcnn.rpn import RPN
  from luminoth.utils.anchors import generate_anchors_reference
  from luminoth.utils.test import generate_gt_boxes, generate_anchors
label_desc: Use image node_id 4 for calling the RPNTest obj's underlying member method code with example usage: obj.testLoss() without return types