EnergyCriterion#

class torch_uncertainty.ood_criteria.EnergyCriterion[source]#

OOD criterion based on the free-energy score (Liu et al., NeurIPS 2020).

Defined as the negative log-sum-exp of the logits:

\[\text{score}(\mathbf{z}) = -\log\left(\sum_{i=1}^{C} \exp(z_i)\right)\]

where \(\mathbf{z} = [z_1, \dots, z_C]\) is the logit vector. Larger values of the energy (i.e. of the score) indicate greater uncertainty and a higher likelihood of being out-of-distribution.

Variables:

input_type – Expected input type is logits.

forward(inputs)[source]#

Compute the negative energy score.

Parameters:

inputs (Tensor) – Tensor of logits with shape (batch_size, num_classes).

Returns:

Negative energy score for each sample.

Return type:

Tensor