MCPcopy Create free account
hub / github.com/KeepTryingTo/Pytorch-GAN / loss_function

Method loss_function

PyTorch-VAE/models/cvae.py:133–147  ·  view source on GitHub ↗
(self,
                      *args,
                      **kwargs)

Source from the content-addressed store, hash-verified

131 return [self.decode(z), input, mu, log_var]
132
133 def loss_function(self,
134 *args,
135 **kwargs) -> dict:
136 recons = args[0]
137 input = args[1]
138 mu = args[2]
139 log_var = args[3]
140
141 kld_weight = kwargs['M_N'] # Account for the minibatch samples from the dataset
142 recons_loss =F.mse_loss(recons, input)
143
144 kld_loss = torch.mean(-0.5 * torch.sum(1 + log_var - mu ** 2 - log_var.exp(), dim = 1), dim = 0)
145
146 loss = recons_loss + kld_weight * kld_loss
147 return {'loss': loss, 'Reconstruction_Loss':recons_loss, 'KLD':-kld_loss}
148
149 def sample(self,
150 num_samples:int,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected