Code Monkey home page Code Monkey logo

gumbel_softmax_vae's Introduction

Gumbel Softmax VAE

PyTorch implementation of a Variational Autoencoder with Gumbel-Softmax Distribution.

Table of Contents

Installation

The program requires the following dependencies (easy to install using pip or Ananconda):

  • python 3.6
  • pytorch (version 0.4.0)
  • numpy

Training

python gumbel_softmax_vae.py --log-interval 100 --epochs 100

Results

Better training accuracy and sample image quality were obtained.

Training output

Train Epoch: 1 [0/60000 (0%)]	Loss: 542.627869
Train Epoch: 1 [10000/60000 (17%)]	Loss: 210.317276
Train Epoch: 1 [20000/60000 (33%)]	Loss: 186.174133
Train Epoch: 1 [30000/60000 (50%)]	Loss: 194.145218
Train Epoch: 1 [40000/60000 (67%)]	Loss: 187.440338
Train Epoch: 1 [50000/60000 (83%)]	Loss: 186.376678
====> Epoch: 1 Average loss: 197.6736
====> Test set loss: 171.0257
Train Epoch: 2 [0/60000 (0%)]	Loss: 170.385742
Train Epoch: 2 [10000/60000 (17%)]	Loss: 162.513947
Train Epoch: 2 [20000/60000 (33%)]	Loss: 160.054916
Train Epoch: 2 [30000/60000 (50%)]	Loss: 158.194092
Train Epoch: 2 [40000/60000 (67%)]	Loss: 149.647385
Train Epoch: 2 [50000/60000 (83%)]	Loss: 144.748962
====> Epoch: 2 Average loss: 153.3126
====> Test set loss: 142.1215
Train Epoch: 3 [0/60000 (0%)]	Loss: 149.698944
Train Epoch: 3 [10000/60000 (17%)]	Loss: 140.085403
Train Epoch: 3 [20000/60000 (33%)]	Loss: 138.817505
Train Epoch: 3 [30000/60000 (50%)]	Loss: 136.967743
Train Epoch: 3 [40000/60000 (67%)]	Loss: 137.792786
Train Epoch: 3 [50000/60000 (83%)]	Loss: 134.401184
====> Epoch: 3 Average loss: 138.2995
====> Test set loss: 133.9106

MNIST

Training Step Ground Truth/Reconstructions Generated Samples
1
10
20
30

gumbel_softmax_vae's People

Contributors

yongfeiyan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gumbel_softmax_vae's Issues

Some questions on KLD

In your code the KL divergence is calculated by:
KLD = torch.sum(qy * (log_qy - 1. / categorical_dim), dim=-1).mean()
I think, for the 1. / categorical_dim, it should be replaced by the torch.log(1. / categorical_dim), otherwise, it is not the KL divergence.

Bernoulli Variables

Hi @YongfeiYan, thanks for sharing your project with us.

I would like to know how do I modify the implementation to use Bernoulli variables. I need the network to generate codes consisting of 0s and 1s.

Thanks.

KL divergence term

I was wondering what exactly this line in the KLD calculation does:
log_ratio = torch.log(qy * categorical_dim + 1e-20)

In the definition of the ELBO loss, the KLD should be computed between the variational distribution q(z|x) and the prior p(z). How come you did not simply use the pytorch implementation of KLD (kl_div)?

Can KL divergence be negative?

I'm using your loss function code in my project and getting negative values...

Is it normal to get negative KLD value?

latent dim

Hi, what does the latent_dim mean in your code? Could it be changed to other numbers? I can understand that categorical_dim means 10 categories for 10 digits, but I'm confused about the latent_dim. Thanks!

mistake in Gumbel softmax sample function.

The gumbel_softmax_sample function is logits + gumbel_sample. But it should have been F.log_softmax(logits) + gumbel_sample according to the paper. Is this not a mistake?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.