mingyuliutw / UNIT

Unsupervised Image-to-Image Translation
Other
1.98k stars 360 forks source link

Why is noise in GaussianVAE2D a torch Variable? #37

Closed hsm207 closed 6 years ago

hsm207 commented 6 years ago

In the GaussianVAE2D class definition in the file common_net.py, there is a method named sample.

This is how its defined:

  def sample(self, x):

    mu = self.en_mu(x)

    sd = self.softplus(self.en_sigma(x))

    noise = Variable(torch.randn(mu.size(0), mu.size(1), mu.size(2), mu.size(3))).cuda(x.data.get_device())

    return mu + sd.mul(noise), mu, sd

I don't understand why noise is defined as a Variable because we do not need to differentiate the loss function with respect to it, do we?

mingyuliutw commented 6 years ago

This is an implementation of the reparamerterization trick described in the VAE paper. Basically, replacing the non differentiable sampling operation with an arithmetic operation by using auxiliary stochastic variables.