'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]
class_indices: (Optional) A 1-D integer tensor of class indices.
If provided, computes loss only for the specified class indices.
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, class_indices=None):

    weights = tf.expand_dims(weights, 2)
    if (class_indices is not None):
        weights *= tf.reshape(ops.indices_to_dense_vector(class_indices, tf.shape(prediction_tensor)[2]), [1, 1, (-1)])
    per_entry_cross_ent = tf.nn.sigmoid_cross_entropy_with_logits(labels=target_tensor, logits=prediction_tensor)
    if self._anchorwise_output:
        return tf.reduce_sum((per_entry_cross_ent * weights), 2)
    return tf.reduce_sum((per_entry_cross_ent * weights))
