MishaLaskin / vqvae

A pytorch implementation of the vector quantized variational autoencoder (https://arxiv.org/abs/1711.00937)
601 stars 71 forks source link

Embedding loss backwards? #6

Open eembees opened 3 years ago

eembees commented 3 years ago

referencing this line:

https://github.com/MishaLaskin/vqvae/blob/d761a999e2267766400dc646d82d3ac3657771d4/models/quantizer.py#L63-L64

From what I can read in the paper the loss is :

log p ... + ||sg[z_e(x)]-e||^2 + beta * ||z_e(x)-sg[e]||^2

but in this code it seems to me to be backwards, I.E.

log p ... + ||z_e(x)-sg[e]||^2 + beta * ||sg[z_e(x)]-e||^2
sakethbachu commented 3 years ago

@eembees I also think the same

lianyixin commented 3 years ago

original tf code is the same as in the paper: e_latent_loss = tf.reduce_mean((tf.stop_gradient(quantized) - inputs) ** 2) q_latent_loss = tf.reduce_mean((quantized - tf.stop_gradient(inputs)) ** 2) loss = q_latent_loss + self._commitment_cost * e_latent_loss

maybe is wrong here