hanzhanggit / StackGAN-v2

MIT License
846 stars 190 forks source link

Why do we compute KL loss in this way? #30

Open jszgz opened 5 years ago

jszgz commented 5 years ago

def KL_loss(mu, logvar):

-0.5 * sum(1 + log(sigma^2) - mu^2 - sigma^2)

KLD_element = mu.pow(2).add_(logvar.exp()).mul_(-1).add_(1).add_(logvar)
KLD = torch.mean(KLD_element).mul_(-0.5)
return KLD
jszgz commented 5 years ago

What does this formula mean?