PyTorch-VAE icon indicating copy to clipboard operation
PyTorch-VAE copied to clipboard

Possible mistake in vanilla_vae 'loss_function'

Open sh3rlock14 opened this issue 3 years ago • 3 comments

I think that in vanilla_vae.py loss_function there's a mistake in KLD returned value:

return {'loss': loss, 'Reconstruction_Loss':recons_loss.detach(), 'KLD':-kld_loss.detach()}

the negative sign (-) should not be there!

sh3rlock14 avatar Sep 27 '22 10:09 sh3rlock14

Agree, the negative sign was already added before, so it should not be there

dvalenciar avatar Sep 29 '22 04:09 dvalenciar

Agree. Line#143 already has one negative sign.

chengengliu avatar Mar 22 '23 12:03 chengengliu

this also happens in the mssim_vae.py line#155 `

    kld_loss = torch.mean(-0.5 * torch.sum(1 + log_var - mu ** 2 - log_var.exp(), dim = 1), dim = 0) 

    loss = recons_loss + kld_weight * kld_loss
    return {'loss': loss, 'Reconstruction_Loss':recons_loss, 'KLD':-kld_loss}`

Maximusprime3 avatar May 21 '23 12:05 Maximusprime3