OOD_VAE#

class dataeval.detectors.ood.OOD_VAE(model: VAE, samples: int = 10)#

VAE based outlier detector.

Parameters:
  • model (VAE) – A VAE model.

  • samples (int, default 10) – Number of samples sampled to evaluate each instance.

Examples

Instantiate an OOD detector metric with a generic dataset - batch of images with shape (3,25,25)

>>> metric = OOD_VAE(create_model("VAE", dataset[0].shape))

Adjusting fit parameters, including setting the fit threshold at 85% for a training set with about 15% out-of-distribution

>>> metric.fit(dataset, threshold_perc=85, batch_size=128, verbose=False)

Detect out of distribution samples at the ‘feature’ level

>>> result = metric.predict(dataset, ood_type="feature")
fit(x_ref: ArrayLike, threshold_perc: float = 100.0, loss_fn: ~typing.Callable[[...], ~tensorflow.python.framework.tensor.Tensor] = <dataeval.utils.tensorflow._internal.loss.Elbo object>, optimizer: ~tf_keras.src.optimizers.optimizer.Optimizer | None = None, epochs: int = 20, batch_size: int = 64, verbose: bool = True) None#

Train the model and infer the threshold value.

Parameters:
  • x_ref (ArrayLike) – Training data.

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

  • loss_fn (Callable | None, default None) – Loss function used for training.

  • optimizer (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.

predict(X: ArrayLike, batch_size: int = 10000000000, ood_type: Literal['feature', 'instance'] = 'instance') OODOutput#

Predict whether instances are out of distribution or not.

Parameters:
  • X (ArrayLike) – Input data for out-of-distribution prediction.

  • batch_size (int, default 1e10) – Number of instances to process in each batch.

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

Returns:

  • Dictionary containing the outlier predictions for the selected level,

  • and the OOD scores for the data including both ‘instance’ and ‘feature’ (if present) level scores.

score(X: ArrayLike, batch_size: int = 10000000000) OODScoreOutput#

Compute the out of distribution scores for a given dataset.

Parameters:
  • X (ArrayLike) – Input data to score.

  • batch_size (int, default 1e10) – Number of instances to process in each batch. Use a smaller batch size if your dataset is large or if you encounter memory issues.

Returns:

An object containing the instance-level and feature-level OOD scores.

Return type:

OODScoreOutput