'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'

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

    diff = (prediction_tensor - target_tensor)
    abs_diff = tf.abs(diff)
    abs_diff_lt_1 = tf.less(abs_diff, 1)
    anchorwise_smooth_l1norm = (tf.reduce_sum(tf.where(abs_diff_lt_1, (0.5 * tf.square(abs_diff)), (abs_diff - 0.5)), 2) * weights)
    if self._anchorwise_output:
        return anchorwise_smooth_l1norm
    return tf.reduce_sum(anchorwise_smooth_l1norm)
