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 moco implementation #6

Open
mingkai-zheng opened this issue Jan 6, 2022 · 0 comments
Open

Question about the moco implementation #6

mingkai-zheng opened this issue Jan 6, 2022 · 0 comments

Comments

@mingkai-zheng
Copy link

Hello, I'm a bit confused about the moco implementation in this paper. Since moco only has one forward pass for the teacher network, so I guess that the lazy update is not required for moco right? In this case, did you include the bn statistics for the current batch during the forward pass?

To be more specific, do you update the running_mean and running_var before calculating x?

with torch.no_grad():
    self.running_mean = self.momentum * mean + (1 - self.momentum) * self.running_mean
    self.running_var = self.momentum * var * n / (n - 1) + (1 - self.momentum) * self.running_var

x = (x - self.running_mean[None, :, None, None].detach()) / (
    torch.sqrt(self.running_var[None, :, None, None].detach() + self.eps)
)

or you calculate x first

x = (x - self.running_mean[None, :, None, None].detach()) / (
    torch.sqrt(self.running_var[None, :, None, None].detach() + self.eps)
)

with torch.no_grad():
    self.running_mean = self.momentum * mean + (1 - self.momentum) * self.running_mean
    self.running_var = self.momentum * var * n / (n - 1) + (1 - self.momentum) * self.running_var

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