Skip to content
data

VAEOutput

extendsModelOutput
VAEOutput(sample: Tensor, latent: Tensor, mu: Tensor, logvar: Tensor, loss: Tensor | None = None, recon_loss: Tensor | None = None, kl_loss: Tensor | None = None)

End-to-end VAE forward output.

Attributes

sampleTensor
Reconstructed image x^\hat{x} shaped (B, C, H, W).
latentTensor
Sampled latent z=μ+σ⋅εz = \mu + \sigma \cdot \varepsilon, shape (B, latent_dim).
Encoder mean μ(x)\mu(x).
logvarTensor
Encoder log-variance log⁡σ2(x)\log \sigma^2(x).
loss(Tensor or None, optional)
Total ELBO loss (recon_loss + β · kl_loss) when targets were supplied to forward.
recon_loss(Tensor or None, optional)
Reconstruction term alone (typically BCE or MSE).
kl_loss(Tensor or None, optional)
KL divergence term DKL(q(z∣x)∥p(z))D_{\mathrm{KL}}(q(z|x) \| p(z)) alone.

Notes

Returned by VAEModel.forward. VAEForImageGeneration wraps the decoder for unconditional sampling and returns GenerationOutput from its generate method.

Examples

>>> import lucid
>>> from lucid.models import VAEOutput
>>> out = VAEOutput(
...     sample=lucid.zeros(1, 3, 32, 32),
...     latent=lucid.zeros(1, 128),
...     mu=lucid.zeros(1, 128),
...     logvar=lucid.zeros(1, 128),
... )
>>> out.sample.shape, out.latent.shape
((1, 3, 32, 32), (1, 128))
The reconstruction and KL terms are kept apart from the total so a
caller can watch them move against each other during training.
>>> out.recon_loss is None, out.kl_loss is None
(True, True)

Used by 2