incerto.ood.ODIN#

class incerto.ood.ODIN(model, temperature=1000.0, epsilon=0.0014)[source]#

Bases: OODDetector

ODIN (Liang et al., ICLR 2018).

__init__(model, temperature=1000.0, epsilon=0.0014)[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)

Parameters:

model – A trained PyTorch model (nn.Module)

Methods

__init__(model[, temperature, epsilon])

Initialize the OOD detector with a trained model.

load_state_dict(state)

Load ODIN hyperparameters.

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 ODIN hyperparameters.

__init__(model, temperature=1000.0, epsilon=0.0014)[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)

Parameters:

model – A trained PyTorch model (nn.Module)

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 ODIN hyperparameters.

Return type:

dict

load_state_dict(state)[source]#

Load ODIN hyperparameters.

Parameters:

state (dict)

Return type:

None