incerto.ood.MSP#
- class incerto.ood.MSP(model)[source]#
Bases:
OODDetectorMaximum-Softmax-Probability (MSP) baseline OOD detector.
Returns
1 - max softmax probabilityas the OOD score, so higher means more likely OOD. Despite its simplicity, MSP is a strong baseline.- Reference:
Hendrycks & Gimpel, “A Baseline for Detecting Misclassified and Out-of-Distribution Examples in Neural Networks”, ICLR 2017.
- Parameters:
model – A trained classifier returning logits of shape
(batch, n_classes).
- __init__(model)#
Initialize the OOD detector with a trained model.
The model is automatically: 1. Set to eval mode 2. Has gradients disabled (requires_grad=False)
- Parameters:
model – A trained PyTorch model (nn.Module)
- Raises:
TypeError – If model is not an nn.Module.
Methods
__init__(model)Initialize the OOD detector with a trained model.
load(path, model, **kwargs)Load detector state from a file.
load_state_dict(state)Load detector state from a dictionary.
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 OOD scores for a batch of inputs.
state_dict()Return a dictionary containing the detector's state.