mindspore.nn.probability.toolbox.VAEAnomalyDetection

class mindspore.nn.probability.toolbox.VAEAnomalyDetection(encoder, decoder, hidden_size=400, latent_size=20)[source]

Toolbox for anomaly detection by using VAE.

Variational Auto-Encoder(VAE) can be used for Unsupervised Anomaly Detection. The anomaly score is the error between the X and the reconstruction of X. If the score is high, the X is mostly outlier.

Parameters
  • encoder (Cell) – The Deep Neural Network (DNN) model defined as encoder.

  • decoder (Cell) – The DNN model defined as decoder.

  • hidden_size (int) – The size of encoder’s output tensor.

  • latent_size (int) – The size of the latent space.

Supported Platforms:

Ascend GPU

predict_outlier(sample_x, threshold=100.0)[source]

Predict whether the sample is an outlier.

Parameters
  • sample_x (Tensor) – The sample to be predicted, the shape is (N, C, H, W).

  • threshold (float) – the threshold of the outlier. Default: 100.0.

Returns

Bool, whether the sample is an outlier.

predict_outlier_score(sample_x)[source]

Predict the outlier score.

Parameters

sample_x (Tensor) – The sample to be predicted, the shape is (N, C, H, W).

Returns

numpy.dtype, the predicted outlier score of the sample.

train(train_dataset, epochs=5)[source]

Train the VAE model.

Parameters
  • train_dataset (Dataset) – A dataset iterator to train model.

  • epochs (int) – Total number of iterations on the data. Default: 5.

Returns

Cell, the trained model.