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])
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.
    
inference_api/src/main/object_detection/core/losses.py