Exemplo n.º 1
0
def giou(boxlist1, boxlist2, scope=None):
  """Computes pairwise generalized IOU between two boxlists.

  Args:
    boxlist1: BoxList holding N boxes
    boxlist2: BoxList holding M boxes
    scope: name scope.

  Returns:
    a tensor with shape [N, M] representing the pairwise GIoU loss.
  """
  with tf.name_scope(scope, 'PairwiseGIoU'):
    n = boxlist1.num_boxes()
    m = boxlist2.num_boxes()
    boxes1 = tf.repeat(boxlist1.get(), repeats=m, axis=0)
    boxes2 = tf.tile(boxlist2.get(), multiples=[n, 1])
    return tf.reshape(ops.giou(boxes1, boxes2), [n, m])
Exemplo n.º 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 float tensor of shape [batch_size, num_anchors] tensor
        representing the value of the loss function.
    """
    batch_size, num_anchors, _ = shape_utils.combined_static_and_dynamic_shape(
        prediction_tensor)
    predicted_boxes = tf.reshape(prediction_tensor, [-1, 4])
    target_boxes = tf.reshape(target_tensor, [-1, 4])

    per_anchor_iou_loss = 1 - ops.giou(predicted_boxes, target_boxes)
    return tf.reshape(tf.reshape(weights, [-1]) * per_anchor_iou_loss,
                      [batch_size, num_anchors])