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

sample z from VAE_GAN #22

Open
jiankang1991 opened this issue Oct 29, 2016 · 0 comments
Open

sample z from VAE_GAN #22

jiankang1991 opened this issue Oct 29, 2016 · 0 comments

Comments

@jiankang1991
Copy link

jiankang1991 commented Oct 29, 2016

Hi,
I have a question confused about the latent variable z

According to the code in class VAEGAN,

    def _forward(self, batch, test=False):

        encoded, means, ln_vars = self._encode(batch, test=test)
        rec = self._decode(encoded, test=test)
        normer = reduce(lambda x, y: x*y, means.data.shape)
        kl_loss = F.gaussian_kl_divergence(means, ln_vars)/normer

        samp_p = np.random.standard_normal(means.data.shape).astype('float32')
        z_p = chainer.Variable(samp_p)

It means that this z is first sampled according to VAE from:

encoded, means, ln_vars = self._encode(batch, test=test)

    def encode(self, data, test=False):
        x = self.enc(data, test=test)
        mean, ln_var = F.split_axis(x, 2, 1)
        samp = np.random.standard_normal(mean.data.shape).astype('float32')
        samp = Variable(samp)
        if self.flag_gpu:
            samp.to_gpu()
        z = samp * F.exp(0.5*ln_var) + mean

which means that the sampler z is s.t:
image

then, the sampled z is input to the decoder network to generate images, according to

rec = self._decode(encoded, test=test)

then, another z is sampled by:

        samp_p = np.random.standard_normal(means.data.shape).astype('float32')
        z_p = chainer.Variable(samp_p)

which means it is s.t.
image

and the generated images is created by:

rec_p = self._decode(z_p)

My question is since the two types of z are sampled from different distributions,
why they are input into the same decoder network?
And which output are the generated images from decoder, since they both created by sampling z according to a distribution ?

This is just my opinion.
Please feel free if I make mistakes.
Thank you.

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