incerto.ood.Energy#
- class incerto.ood.Energy(model, temperature=1.0)[source]#
Bases:
OODDetectorEnergy-based OOD detector.
Computes the free-energy score
-T * logsumexp(logits / T)for each input. Lower energy is associated with in-distribution data, so the returned score (negated logsumexp) is higher for OOD inputs.- Reference:
Liu et al., “Energy-based Out-of-distribution Detection”, NeurIPS 2020.
- Parameters:
model – A trained classifier returning logits of shape
(batch, n_classes).temperature (
float) – TemperatureTapplied to logits before logsumexp. Default: 1.0.
- __init__(model, temperature=1.0)[source]#
Initialize the OOD detector with a trained model.
The model is automatically: 1. Set to eval mode 2. Has gradients disabled (requires_grad=False)
Methods
__init__(model[, temperature])Initialize the OOD detector with a trained model.
load(path, model, **kwargs)Load detector state from a file.
load_state_dict(state)Load temperature parameter.
predict(x, threshold)Predict whether inputs are OOD using a threshold.
save(path)Save detector state to a file (excluding the model).
score(x)Compute energy-based OOD scores.
Save temperature parameter.