michaal94 / torch_DCEC

Pytorch Deep Clustering with Convolutional Autoencoders implementation
MIT License
98 stars 30 forks source link

Using torch.log when apply KLDivLoss. #1

Closed miangangzhen closed 5 years ago

miangangzhen commented 5 years ago

Wondering why using torch.log when apply KLDivLoss.

Your code:

loss_clust = gamma *criteria[1](torch.log(clusters), tar_dist) / batch

My code:

loss = criterion(y_hat_batch, torch.from_numpy(y_batch))

My code doesn't work, but yours did. I can't figure out what's torch.log role?

michaal94 commented 5 years ago

It is because PyTorch expects logprob as the input for KL loss. Check: link