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

Question about the process of calculating top1, 3, 5 accuracy in nice_stand.py #14

Open
gyuseok0917 opened this issue Oct 21, 2024 · 0 comments

Comments

@gyuseok0917
Copy link

gyuseok0917 commented Oct 21, 2024

with torch.no_grad():
    for i, (teeg, tlabel) in enumerate(self.test_dataloader):
        teeg = Variable(teeg.type(self.Tensor))
        tlabel = Variable(tlabel.type(self.LongTensor))
        all_center = Variable(all_center.type(self.Tensor))            

        tfea = self.Proj_eeg(self.Enc_eeg(teeg))
        tfea = tfea / tfea.norm(dim=1, keepdim=True)
        similarity = (100.0 * tfea @ all_center.t()).softmax(dim=-1)  # no use 100?
        _, indices = similarity.topk(5)

        tt_label = tlabel.view(-1, 1)
        total += tlabel.size(0)
        top1 += (tt_label == indices[:, :1]).sum().item()
        top3 += (tt_label == indices[:, :3]).sum().item()
        top5 += (tt_label == indices).sum().item()

Hello. I have a question while referencing your code. I saw the code for obtaining top1,3,5 accuracy in nice_stand.py, and I understand that t_label represents the actual integer label of the data. Then, after taking the inner product of eeg and image embedding, it is expressed as a probability distribution through softmax, and then the top k with the highest probability are selected and indices, which are the index information of these, are obtained. t_label is expressed as tt_label by converting the shape and then selecting k indices in order according to the highest probability according to k = 1, 3, 5 and then comparing them with tt_label. The problem here is that tt_label represents the actual integer label of the corresponding data, and indices represent the index information of the position with the highest probability, but the two values ​​are not comparable, so how can the top-1,3,5 accuracy be obtained?

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