Code Monkey home page Code Monkey logo

tf-vqvae's Introduction

VQ-VAE (Neural Discrete Representation Learning) Tensorflow

Intro

This repository implements the paper, Neural Discrete Representation Learning (VQ-VAE) in Tensorflow.

โš ๏ธ This is not an official implementation, and might have some glitch (,or a major defect).

Requirements

  • Python 3.5
  • Tensorflow (v1.3 or higher)
  • numpy, better_exceptions, tqdm, etc.
  • ffmpeg

Updated Result: ImageNet

  • ImageNet

    Validation Set Images Reconstructed Images
    Imagenet original images Imagenet Reconstructed Images
    • Class Conditioned Sampled Image (Not cherry-picked, just random sample)

      alp

      admiral

      coral reef

      gray_whale

      brown bear

      pickup truck

    • I could not reproduce as sharp images as the author produced.

    • But, some of results seems understandable.

    • Usually, natural scene images having consistent pixel orders shows better result, such as Alp or coral reef.

    • More tuning might provide better result.

Updated Result: Sampling with PixelCNN

  • Pixel CNN

    • MNIST Sampled Image (Conditioned on class labels)

      MNIST Sampled Images

    • Cifar10 Sampled Image (Conditioned on class labels)

      Cifar10 Sampled Imagesl

      From top row to bottom, the sampled images for classes (airplane,auto,bird,cat,deer,dog,frog,horse,ship,truck)

      Not that satisfying so far; I guess hyperparameters for VQ-VAE should be tuned first to generate more sharper result.

Results

All training is done with Quadro M4000 GPU. Training MNIST only takes less than 10 minutes.

  • MNIST

    Original Images Reconstructed Images
    MNIST original images MNIST Reconstructed Images

    The result on MNIST test dataset. (K=20, D=64, latent space=3 by 3)

    I also observed its latent space by changing single value for each latent space from one of the observed latent code. The result is shown below. MNIST Latent Observation

    It seems that spatial location of latent code is improtant. By changing latent code on a specific location, the pixel matches with the location is disturbed.

    MNIST Latent Observation - Random Walk

    This results shows the 1000 generated images starting from knwon latent codes and changing aa single latent code at radnom location by +1 or -1. Most of the images are redundant (unrealistic), so it indicates that there are much room for compression.

    If you want to further explore the latent space, then try to play with notebook files I provided.

  • CIFAR 10

    Original Images Reconstructed Images
    MNIST original images MNIST Reconstructed Images

    I was able to get 4.65 bits/dims. (K=10, D=256, latent space=8 by 8)

Training

It will download required datasets on the directory ./datasets/{mnist,cifar10} by itself. Hence, just run the code will do the trick.

Run train

  • Run mnist: python mnist.py
  • Run cifar10: python cifar10.py

Change the hyperparameters accordingly as you want. Please check at the bottom of each script.

Evaluation

I provide the model and the code for generating (,or reconstructing) images in the form of Jupyter notebook. Run jupyter notebook server, then run it to see more results with provided models.

If you want to test NLL, then run test() function on cifar.py by uncomment the line. You can find it at the bottom of the file.

TODO

  • WaveNet?

Contributions are welcome!

Thoughts and Help request

  • The results seems correct, but there is a chance that the implmentation is not perfectly correct (especially, gradient copying...). If you find any glitches (or, a major defect) then, please let me know!
  • I am currently not sure how exactly NLL should be computed. Anyone who wants me a proper explantion on this?

Acknowledgement

tf-vqvae's People

Contributors

hiwonjoon avatar

Watchers

Shubham Pachori avatar paper2code - bot avatar

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.