Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusion about the kd_ce_loss #1

Open
fengjiejiejiejie opened this issue Jun 25, 2023 · 0 comments
Open

Confusion about the kd_ce_loss #1

fengjiejiejiejie opened this issue Jun 25, 2023 · 0 comments

Comments

@fengjiejiejiejie
Copy link

Hi,
thanks for your impressive paper and codes, but I'm confused about the kd_ce_loss:

def FNKD(self, student_outputs, teacher_outputs, student_feature, teacher_feature):
student_L2norm = torch.norm(student_feature)
teacher_L2norm = torch.norm(teacher_feature)
q_fn = F.log_softmax(teacher_outputs / teacher_L2norm, dim=1)
to_kd = F.softmax(student_outputs / student_L2norm, dim=1)
KD_ce_loss = self.ce(
q_fn, to_kd[:, 0].long())
return KD_ce_loss

Why use self.ce after the softmax/log_softmax?
Is to_kd[:, 0] just using the first channel of the student_outputs (background)?
Maybe the following is right?

q_fn = F.log_softmax(teacher_outputs / T, dim=1)
to_kd = F.softmax(student_outputs / T, dim=1)
KD_ce_loss = -torch.mean(torch.sum(to_kd * q_fn, dim=1))

best,
fj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant