incerto.ood.Mahalanobis#

class incerto.ood.Mahalanobis(model, layer_name='penultimate')[source]#

Bases: _FeatureHookMixin, OODDetector

Feature-space Mahalanobis (Lee et al., NeurIPS 2018).

__init__(model, layer_name='penultimate')[source]#

Methods

__init__(model[, layer_name])

fit(loader)

load(path, model, **kwargs)

Load detector state from a file.

load_state_dict(state)

Load fitted Mahalanobis parameters.

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 input samples.

state_dict()

Save fitted Mahalanobis parameters.

__init__(model, layer_name='penultimate')[source]#
fit(loader)[source]#
score(x)[source]#

Compute OOD scores for input samples.

Higher scores indicate the input is more likely to be out-of-distribution.

Parameters:

x – Input tensor of shape (batch_size, *input_dims)

Returns:

OOD scores of shape (batch_size,) where higher values indicate more OOD-like samples.

Note

The scale of scores depends on the detection method. Use the predict() method with a threshold for binary OOD decisions.

state_dict()[source]#

Save fitted Mahalanobis parameters.

Return type:

dict

load_state_dict(state)[source]#

Load fitted Mahalanobis parameters.

Parameters:

state (dict)

Return type:

None