'Compute loss function.
Args:
prediction_tensor: A float tensor of shape [batch_size, num_anchors,
num_classes] representing the predicted logits for each class
target_tensor: A float tensor of shape [batch_size, num_anchors,
num_classes] representing one-hot encoded classification 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):

    num_classes = prediction_tensor.get_shape().as_list()[(-1)]
    per_row_cross_ent = tf.nn.softmax_cross_entropy_with_logits(labels=tf.reshape(target_tensor, [(-1), num_classes]), logits=tf.reshape(prediction_tensor, [(-1), num_classes]))
    if self._anchorwise_output:
        return (tf.reshape(per_row_cross_ent, tf.shape(weights)) * weights)
    return tf.reduce_sum((per_row_cross_ent * tf.reshape(weights, [(-1)])))
