IAFSampler¶
Sampler fitting an Inverse Autoregressive Flow (IAF)
in the Autoencoder’s latent space.
Available models:¶
Vanilla Autoencoder model. |
|
Vanilla Variational Autoencoder model. |
|
\(\beta\)-VAE model. |
|
Variational Auto Encoder with linear Normalizing Flows model. |
|
Variational Auto Encoder with Inverse Autoregressive Flows ( |
|
Disentangled \(\beta\)-VAE model. |
|
FactorVAE model. |
|
\(\beta\)-TCVAE model. |
|
Importance Weighted Autoencoder model. |
|
VAE using perseptual similarity metrics model. |
|
Wasserstein Autoencoder model. |
|
Info Variational Autoencoder model. |
|
Variational Mixture of Posteriors (VAMP) VAE model |
|
\(\mathcal{S}\)-VAE model. |
|
Adversarial Autoencoder model. |
|
Variational Autoencoder using Adversarial reconstruction loss model. |
|
Vector Quantized-VAE model. |
|
Hamiltonian VAE. |
|
Regularized Autoencoder with gradient penalty model. |
|
Regularized Autoencoder with L2 decoder params regularization model. |
|
Riemannian Hamiltonian VAE model. |
- class pythae.samplers.IAFSamplerConfig(n_made_blocks=2, n_hidden_in_made=3, hidden_size=128, include_batch_norm=False)[source]¶
This is the IAF sampler model configuration instance.
- Parameters
n_made_blocks (int) – The number of MADE model to consider in the IAF. Default: 2.
n_hidden_in_made (int) – The number of hidden layers in the MADE models. Default: 3.
hidden_size (list) – The number of unit in each hidder layer. The same number of units is used across the n_hidden_in_made and n_made_blocks
include_batch_norm (bool) – Whether to include batch normalization after each
MADElayers. Default: False.
- class pythae.samplers.IAFSampler(model, sampler_config=None)[source]¶
Fits an Inverse Autoregressive Flow in the Autoencoder’s latent space.
- Parameters
model (BaseAE) – The AE model to sample from
sampler_config (IAFSamplerConfig) – A IAFSamplerConfig instance containing the main parameters of the sampler. If None, a pre-defined configuration is used. Default: None
Note
The method
fitmust be called to fit the sampler before sampling.- fit(train_data, eval_data=None, training_config=None, batch_size=64)[source]¶
Method to fit the sampler from the training data
- Parameters
train_data (Union[torch.Tensor, np.ndarray, Dataset]) – The train data needed to retrieve the training embeddings and fit the flows in the latent space.
eval_data (Union[torch.Tensor, np.ndarray, Dataset]) – The train data needed to retrieve the evaluation embeddings and fit the flows in the latent space.
training_config (BaseTrainerConfig) – the training config to use to fit the flow.
batch_size (int) – The batch size to use to retrieve the embeddings. Default: 64.
- sample(num_samples=1, batch_size=500, output_dir=None, return_gen=True, save_sampler_config=False)[source]¶
Main sampling function of the sampler.
- Parameters
num_samples (int) – The number of samples to generate
batch_size (int) – The batch size to use during sampling
output_dir (str) – The directory where the images will be saved. If does not exist the folder is created. If None: the images are not saved. Defaults: None.
return_gen (bool) – Whether the sampler should directly return a tensor of generated data. Default: True.
save_sampler_config (bool) – Whether to save the sampler config. It is saved in output_dir
- Returns
The generated images
- Return type