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

There should be a stop gradient in the simsiam model #39

Open
nikheelpandey opened this issue May 27, 2021 · 1 comment
Open

There should be a stop gradient in the simsiam model #39

nikheelpandey opened this issue May 27, 2021 · 1 comment

Comments

@nikheelpandey
Copy link

nikheelpandey commented May 27, 2021

Hello,

I was using your implementation of SimSiam for contrastive learning. I noticed that the model that you have created has a few problems:

  1. The "stop_gradient" part of the network is absent from your implementation. This model is effectively training both the path.

Could you please clarify how and where you are taking care of it?

@hhhdw
Copy link

hhhdw commented Jul 5, 2021

def D(p, z, version='simplified'): # negative cosine similarity
if version == 'original':
z = z.detach() # stop gradient
p = F.normalize(p, dim=1) # l2-normalize
z = F.normalize(z, dim=1) # l2-normalize
return -(p*z).sum(dim=1).mean()

elif version == 'simplified':# same thing, much faster. Scroll down, speed test in __main__
    return - F.cosine_similarity(p, z.detach(), dim=-1).mean()
else:
    raise Exception

There is a 'detach' after 'z' when compute loss

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

2 participants