mindspore.nn.probability.dpn.VAE

class mindspore.nn.probability.dpn.VAE(encoder, decoder, hidden_size, latent_size)[source]

Variational Auto-Encoder (VAE).

The VAE defines a generative model, Z is sampled from the prior, then used to reconstruct X by a decoder. For more details, refer to Auto-Encoding Variational Bayes.

Note

When the encoder and decoder are defined, the shape of the encoder’s output tensor and decoder’s input tensor must be \((N, hidden\_size)\). The latent_size must be less than or equal to the hidden_size.

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.

Inputs:
  • input (Tensor) - The shape of input tensor is \((N, C, H, W)\), which is the same as the input of encoder.

Outputs:
  • output (Tuple) - (recon_x(Tensor), x(Tensor), mu(Tensor), std(Tensor)).

Supported Platforms:

Ascend GPU

generate_sample(generate_nums, shape)[source]

Randomly sample from latent space to generate samples.

Parameters
  • generate_nums (int) – The number of samples to generate.

  • shape (tuple) – The shape of sample, it must be (generate_nums, C, H, W) or (-1, C, H, W).

Returns

Tensor, the generated samples.

reconstruct_sample(x)[source]

Reconstruct samples from original data.

Parameters

x (Tensor) – The input tensor to be reconstructed, the shape is (N, C, H, W).

Returns

Tensor, the reconstructed sample.