def kullback_leibler_loss(self):
LKL = -0.5*torch.sum(1+self.sigma-self.mu**2-torch.exp(self.sigma))\
/float(hp.Nz*hp.batch_size)
if use_cuda:
KL_min = Variable(torch.Tensor([hp.KL_min]).cuda()).detach()
else:
KL_min = Variable(torch.Tensor([hp.KL_min])).detach()
return hp.wKL*self.eta_step * torch.max(LKL,KL_min)
评论列表
文章目录