'Compute loss function.
Args:
prediction_tensor: A float tensor of shape [batch_size, num_anchors,
code_size] representing the (encoded) predicted locations of objects.
target_tensor: A float tensor of shape [batch_size, num_anchors,
code_size] representing the regression targets
weights: a float tensor of shape [batch_size, num_anchors]
Returns:
loss: a (scalar) tensor representing the value of the loss function
or a float tensor of shape [batch_size, num_anchors]'

def _compute_loss(self, prediction_tensor, target_tensor, weights):

    weighted_diff = ((prediction_tensor - target_tensor) * tf.expand_dims(weights, 2))
    square_diff = (0.5 * tf.square(weighted_diff))
    if self._anchorwise_output:
        return tf.reduce_sum(square_diff, 2)
    return tf.reduce_sum(square_diff)
