MCPcopy Create free account
hub / github.com/OUCMachineLearning/OUCML / loss_function

Function loss_function

One_Day_One_GAN/day15/vae.py:80–92  ·  view source on GitHub ↗

recon_x: generating images x: origin images mu: latent mean logvar: latent log variance

(recon_x, x, mu, logvar)

Source from the content-addressed store, hash-verified

78
79
80def loss_function(recon_x, x, mu, logvar):
81 """
82 recon_x: generating images
83 x: origin images
84 mu: latent mean
85 logvar: latent log variance
86 """
87 BCE = reconstruction_function(recon_x, x) # mse loss
88 # loss = 0.5 * sum(1 + log(sigma^2) - mu^2 - sigma^2)
89 KLD_element = mu.pow(2).add_(logvar.exp()).mul_(-1).add_(1).add_(logvar)
90 KLD = torch.sum(KLD_element).mul_(-0.5)
91 # KL divergence
92 return BCE + KLD
93
94
95optimizer = optim.Adam(model.parameters(), lr=1e-3)

Callers 1

vae.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected