Out-of-Distribution LLR

How-To Guides

Check out this how to to begin using the Out-of-Distribution Detection class

Out-of-Distribution Detection Tutorial

DataEval API

class dataeval.detectors.OOD_LLR(model: PixelCNN, model_background: PixelCNN | None = None, log_prob: Callable | None = None, sequential: bool = False)
fit(x_ref: ~numpy._typing._array_like._SupportsArray[~numpy.dtype[~typing.Any]] | ~numpy._typing._nested_sequence._NestedSequence[~numpy._typing._array_like._SupportsArray[~numpy.dtype[~typing.Any]]] | bool | int | float | complex | str | bytes | ~numpy._typing._nested_sequence._NestedSequence[bool | int | float | complex | str | bytes], threshold_perc: float = 100.0, loss_fn: ~typing.Callable | None = None, optimizer: ~keras.src.optimizers.optimizer.Optimizer = <class 'keras.src.optimizers.adam.Adam'>, epochs: int = 20, batch_size: int = 64, verbose: bool = True, mutate_fn: ~typing.Callable = <function mutate_categorical>, mutate_fn_kwargs: dict = {'feature_range': (0, 255), 'rate': 0.2, 'seed': 0}, mutate_batch_size: int = 10000000000) None

Train semantic and background generative models.

Parameters:
  • x_ref (ArrayLike) – Training batch.

  • threshold_perc (float, default 100.0) – Percentage of reference data that is normal.

  • loss_fn (Optional[Callable], default None) – Loss function used for training.

  • optimizer (keras.optimizers.Optimizer, default keras.optimizers.Adam) – Optimizer used for training.

  • epochs (int, default 20) – Number of training epochs.

  • batch_size (int, default 64) – Batch size used for training.

  • verbose (bool, default True) – Whether to print training progress.

  • mutate_fn (Callable, default mutate_categorical) – Mutation function used to generate the background dataset.

  • mutate_fn_kwargs (dict, default {"rate": 0.2, "seed": 0, "feature_range": (0, 255)}) – Kwargs for the mutation function used to generate the background dataset. Default values set for an image dataset.

  • mutate_batch_size (int, default int(1e10)) – Batch size used to generate the mutations for the background dataset.

predict(X: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], batch_size: int = 10000000000, ood_type: Literal['feature', 'instance'] = 'instance') OODOutput

Predict whether instances are out-of-distribution or not.

Parameters:
  • X (ArrayLike) – Batch of instances.

  • batch_size (int, default int(1e10)) – Batch size used when making predictions with the autoencoder.

  • ood_type (Literal["feature", "instance"], default "instance") – Predict out-of-distribution at the ‘feature’ or ‘instance’ level.

Return type:

Dictionary containing the outlier predictions and both feature and instance level outlier scores.

score(X: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], batch_size: int = 10000000000) OODScore

Compute instance and (optionally) feature level outlier scores.

Parameters:
  • X (ArrayLike) – Batch of instances.

  • batch_size (int, default int(1e10)) – Batch size used when making predictions with the autoencoder.

Return type:

Instance and feature level outlier scores.