Created
September 13, 2018 02:43
-
-
Save AruniRC/f4ca0ea6b72bc1bf0b4060dc564ae712 to your computer and use it in GitHub Desktop.
Pytorch distillation soft targets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if self.distill: | |
soft_target = Variable(data[2].cuda()) | |
distill_loss = torch.mean(torch.sum(- nn.Softmax(dim=1)(soft_target/self.T) * nn.LogSoftmax(dim=1)(out_data/self.T), 1)) | |
loss += self.lbda*distill_loss | |
self.writer.add_scalar('train/distill_loss', distill_loss, i_acc+i+1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(code snippet courtesy Jong-Chyi)