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

SimCLR loss and nearest neighbors computed on hidden features? #134

Open
emessori opened this issue Apr 3, 2023 · 0 comments
Open

SimCLR loss and nearest neighbors computed on hidden features? #134

emessori opened this issue Apr 3, 2023 · 0 comments

Comments

@emessori
Copy link

emessori commented Apr 3, 2023

Hello,

I was checking your code and noticed that in the definition of SimCLRLoss, more specifically in the forward function, you wrote the following:
input: - features: hidden feature representation of shape [b, 2, dim] output: - loss: loss computed according to SimCLR
From the original SimCLR paper, it was my understanding that the loss function is computed on the output of the projection head (in this case the MLP head attached on top of the backbone resnet). Therefore, I am wondering if I'm missing something or if there is a typo in the comment in SimCLRLoss.

EDIT

There is also something in the computation of the nearest neighbors (function mine_nearest_neighbor, defined for the MemoryBank class in the memory file) which is not clear to me. More specifically, I thought that the nearest neighbors were computed on the 'hidden features', i.e. the vector representation output by the backbone and not by the projection head, but by looking at the dimension of the features it seems that this is not the case. For example, in my config file I set features_dim=128 and since my backbone is ResNet18, I also have backbone['dim'] = 512 as specified both in models\resnet_cifar and models\resnet_stl. However, if I print out the shape of features in mine_nearest_neighbors I can see that each vector is made of 128 entries and not 512.
Does this mean that you compute the nearest neighbors in the space where the loss function is applied and not w.r.t. the outputs of the backbone network?

Thank you and have a nice day!

@emessori emessori changed the title SimCLR loss computed on hidden features? SimCLR loss and nearest neighbors computed on hidden features? Apr 5, 2023
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