VQ-VAE learns discrete latent codes by quantizing continuous latent representations. An encoder maps input to a continuous space, which is quantized to the nearest code in a learned codebook. A decoder reconstructs from the quantized code.
Loss combines reconstruction, codebook, and commitment terms: L=∣∣x−x^∣∣2+∣∣sg[ze]−e∣∣2+β∣∣ze−sg[e]∣∣2
Where sg denotes stop-gradient, z_e is the encoder output, and e is the quantized code.
Implement:
vq_vae_loss(x_recon, x_true, z_e, z_q, beta=0.25)
Computes reconstruction, codebook, and commitment losses.
No results yet
Run your code to check it against the examples, or submit to run every test.