vturrisi / solo-learn

solo-learn: a library of self-supervised methods for visual representation learning powered by Pytorch Lightning
MIT License
1.39k stars 181 forks source link

The setting for offline and online KNN? #337

Closed realliyifei closed 1 year ago

realliyifei commented 1 year ago

What is the setting for offline and online KNN in the readme?

For offline KNN, the gridsearch is implemented here (k, temperature, feature_type, distance_function): do you use the setting of the best performance for each model respectively? Or do you stick to a good setting for all models?

For online KNN, a similar question as above is raised.

vturrisi commented 1 year ago

Hi. The online knn is defined here: https://github.com/vturrisi/solo-learn/blob/main/solo/methods/base.py#L252-L255

realliyifei commented 1 year ago

thanks by the code the default setting for online knn seems to be: k=20, T= 0.07, distance_func=euclidean.

It would be good to also know what is the knn setting you used for the offline performance in readme

vturrisi commented 1 year ago

@DonkeyShot21 Will probably know that.

DonkeyShot21 commented 1 year ago

In general, parameters for the linear evaluation and knn are tuned on the test set in SSL. However, the default parameters are quite strong, you should not see a big gap in performance. Not sure why the default is euclidian for the distance function, it should be cosine

realliyifei commented 1 year ago

RE distance func: I saw this line is euclidian but yes I agree cosine should be the default, which is what I am using
RE parameters: different, reasonable parameters of knn cause ~1 point on top-1 accuracy of imagenet on my side, so while it may not be that strong, the gap is still noticeable 

Overall these are the valuable information, thanks! So it sounds like different models' performances on the readme use different optimal knn parameters respectively? I assumed they use the same setting to compare.

DonkeyShot21 commented 1 year ago

I am not 100% sure, but they should have been tuned for each model, resulting in different parameters.

realliyifei commented 1 year ago

i see. thanks!