mr2.nn.nets.VAE
- class mr2.nn.nets.VAE[source]
Bases:
VAEBaseVariational autoencoder with convolutional encoder and decoder.
- __init__(n_dim: int = 2, n_channels_in: int = 2, latent_channels: int = 8, n_features: Sequence[int] = (32, 64, 128), n_res_blocks: int = 2) None[source]
Initialize the VAE.
- Parameters:
n_dim (
int, default:2) – The number of dimensions, i.e. 1, 2 or 3.n_channels_in (
int, default:2) – The number of channels in the input tensor.latent_channels (
int, default:8) – The number of channels in the latent space.n_features (
Sequence[int], default:(32, 64, 128)) – The number of features at each resolution level.n_res_blocks (
int, default:2) – Number of residual blocks per resolution level.
- __call__(x: Tensor) tuple[Tensor, Tensor][source]
Forward pass of the VAE.
Calculates the reconstruction as well as the KL divergence between the latent space and the standard normal distribution.
- Parameters:
x (
Tensor) – Input tensor- Returns:
tuple of the reconstructed image and the KL divergence between the latent space and the standard normal distribution.