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

normalize model outputs for kNN evaluation #395

Open
clemsgrs opened this issue Mar 15, 2024 · 0 comments
Open

normalize model outputs for kNN evaluation #395

clemsgrs opened this issue Mar 15, 2024 · 0 comments

Comments

@clemsgrs
Copy link

In the kNN evaluation code, the class probabilities retrieved from model output don't sum to 1:

dinov2/dinov2/eval/knn.py

Lines 192 to 195 in e1277af

def forward(self, features_dict, targets):
for k in self.keys:
features_dict = features_dict[k]
return {"preds": features_dict, "target": targets}

This causes issues when computing kNN metrics.
I would suggest adding the following line of code to ensure probabilities sum to 1:

def forward(self, features_dict, targets):
    for k in self.keys:
        features_dict = features_dict[k]
    features_dict = features_dict / features_dict.sum(dim=-1).unsqueeze(-1)
    return {"preds": features_dict, "target": targets}
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