Code Monkey home page Code Monkey logo

training_cvae's Introduction

Training Conditional Variational Autoencoders

This is the repo for training CVAE on images. The original paper for traditional VAE and CVAE are here: VAE, CVAE.

Requirments

  • Make sure you have set up a python environment for tensorflow. More details of instructions can be found here.
  • The version of the modules we use is listed in requirements.txt.

Usage

1) Download this repository

Start by downloading or clone this repository:

git clone https://github.com/ml5js/training-cvae.git
cd training-cvae

2) Collect data

This CVAE model can generate new image based on the training data and you could tune the latent vectors to change its shape.

When you have your image data and labels of each of them, make sure put them in a folder in the root of this project like this:

── data_folder
      ├── car
      |   ├── car1.png
      |   ├── car2.png
      |   └── ...
      |
      ├── airplane
      |   ├── airplane1.png
      |   ├── airplane2.png
      |   └── ...
      ├── ...
      └── ...

The type of file can be either numpy array like .npy or image files like .png, .jpg or .jpeg.

If you do not have a dataset on hand, you could use the download.py to download the quick draw dataset provided by Google. Please make sure make a data folder before you run:

python download.py

3) Train

Run the training script with default settings:

python train.py --data_dir=./folder_with_my_custom_data

Or you could specify your preferred hyperparameters settings like this:

# This are the hyperparameters you can change to fit your data
python train.py --data_dir=./quick_draw \
--n_dim=16 \
--num_layers 2 \
--image_size=28 \
--image_depth=1 \
--filters=8 \
--learning_rate=0.0005 \
--decay_rate=0.01 \
--batch_size=128 \
--epochs=30

Or you could simply run the bash script run.sh:

bash run.sh

Important thing to notice: when fit your data into the model, the input numpy array or image should to be square and the image_size hyperparameter should be compatible or errors will occur! If you don't have square image or data, you have to shave it into square by yourself.

4) Use it

Once the model is ready, you will get one manifest.json file and a folder named model or your custom name that contains your model. Be sure to move both of them into your ml5 sketch folder and run the below command:

const cvae = new ml5.CVAE('./manifest.json');

That's it! Have fun with CVAE in ml5!

training_cvae's People

Contributors

derek-wds avatar wenheli 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.