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

(Maybe) in-consistency between VQ-VAE paper and its implementation. #252

Open
Apollo1840 opened this issue Aug 30, 2022 · 2 comments
Open

Comments

@Apollo1840
Copy link

FIrst of all, maybe it is my misunderstanding of the paper, so hope somebody could explain it for me, thanks! :


in the paper, the loss is defined as
Screenshot from 2022-08-30 11-52-26

where e is the codebook defined at the beginning of the Section:
Screenshot from 2022-08-30 11-57-36

So, in the paper, the codebook loss and commitment loss are MSE between z_e(x) and e.

However, in the implementation, they are implemented as MSE between z_e(x)(inputs) and z_q(x)(quantized), where variable quantized means quantized encoding of the image, namely z_q:
Screenshot from 2022-08-30 11-58-19

Are they actually the same thing? why?

  • If the paper stated is right. how the dimension matches between z_e(x)(H' * W' * D) and e(K * D)?
  • if the implementation is right. how z_q(x)(quantized) backprop since its calculation contains argmin?
@Apollo1840
Copy link
Author

Apollo1840 commented Aug 30, 2022

Probably, e in the loss formula in the paper actually stands for the z_q(x). The author did not write as z_q(x) because its calculation evolves argmin, which is not-differentiable. However, this is not a problem to implement it naively as z_q(x), because tensorflow, as well as pytorch, will stop the gradient before argmin operation, thus it works as intended and causes no BUG.

That is my new understanding.

@Apollo1840
Copy link
Author

Probably, e in the paper stands for the z_q(x). The author did not write as z_q(x) because its calculation evolves argmin, which is not-differentiable. However, this is not a problem to implement it naively as z_q(x), because tensorflow, as well as pytorch, will stop the gradient before argmin operation, thus it works as intended and causes no BUG.

That is my new understanding.

please close this if admin thinks this explanation is right.

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