示例#1
0
 def test_matched_iou(self):
   corners1 = tf.constant([[4.0, 3.0, 7.0, 5.0], [5.0, 6.0, 10.0, 7.0]])
   corners2 = tf.constant([[3.0, 4.0, 6.0, 8.0], [14.0, 14.0, 15.0, 15.0]])
   exp_output = [2.0 / 16.0, 0]
   boxes1 = box_list.BoxList(corners1)
   boxes2 = box_list.BoxList(corners2)
   iou = box_list_ops.matched_iou(boxes1, boxes2)
   with self.test_session() as sess:
     iou_output = sess.run(iou)
     self.assertAllClose(iou_output, exp_output)
示例#2
0
    def _compute_loss(self, prediction_tensor, target_tensor, weights):
        """Compute loss function.

        Args:
          prediction_tensor: A float tensor of shape [batch_size, num_anchors, 4]
            representing the decoded predicted boxes
          target_tensor: A float tensor of shape [batch_size, num_anchors, 4]
            representing the decoded target boxes
          weights: a float tensor of shape [batch_size, num_anchors]

        Returns:
          loss: a (scalar) tensor representing the value of the loss function
        """
        predicted_boxes = box_list.BoxList(tf.reshape(prediction_tensor, [-1, 4]))
        target_boxes = box_list.BoxList(tf.reshape(target_tensor, [-1, 4]))
        per_anchor_iou_loss = 1.0 - box_list_ops.matched_iou(predicted_boxes,
                                                             target_boxes)
        return tf.reduce_sum(tf.reshape(weights, [-1]) * per_anchor_iou_loss)