Git Product home page Git Product logo

facegen's Introduction

FaceGen using GAN: Generative Adversarial Networks

Authors:
  • Josep de Cid Rodríguez
  • Gonzalo Recio Domènech

Requirements

The main requirement in this python is to have Python3.7.X installed. It may come already installed in most devices. Otherwise, just go to their website and download the specific version for your OS.

The second important tool is Pipenv a Python library for managing library dependencies in virtual environments. The main idea behind using this tool is to be easily able to track the packages used in our project in a centralized way, being able to update, install or manage them for any purpose in a few simple commands.

Once Pipenv is installed, run in this folder the following command:

pipenv --python 3.7
pipenv install

which will create the virtual environment and install all the requirements specified in Pipfile.

Usage

All commands can be run without entering the virtual environment shell by typing pipenv run as a prefix before the python command. However, for simplicity, we log into the environment shell. A prefix with the project name appearing before each line of command shows its proper working:

> pipenv shell
(FaceGen) >

Datasets

The used datasets are. Download and put them in /datasets folder.

Environment variables

Copy the .env_template to a .env file and fill the specified environment variables required.

  • CIFAR_PATH: Path of CIFAR10 dataset (required only if training with GA).
  • DATASET_PATH: Path of the faces dataset (CelabA, UTKFace or any other dataset to run).
  • LOG_DIR: Directory to save the logs for Tensorboard visualization.
  • CKPT_DIR: Directory to save PyTorch models checkpoints.

This would be an example of .env:

CIFAR_PATH=$PROJECTS/FaceGen/datasets/CIFAR
DATASET_PATH=$PROJECTS/FaceGen/datasets/UTKFace
LOG_DIR=$PROJECTS/FaceGen/runs
CKPT_DIR=$PROJECTS/FaceGen/checkpoints

Train the model

To train the model, simply run the following command:

(FaceGen) > python main.py {ALG}

where ALG can take the value of GA for Genetic Algorithms, VAE for Variatonal Auto-encoders and GAN for Generative Adversarial Networks.

If you want to ensure reproducibility, a manual --seed must be introduced in the command line:

(FaceGen) > python main.py GAN --seed 42

If we have an available GPU card that supports CUDA, it will be training the model using the GPU.

Generate new samples from a pre-trained model

There are 4 different pre-trained models in this MEGA folder.

To generate new samples, we can use the same script, just indicating the pre-trained model path and the number of samples to generate using the --generate flag.

The following command generates 5 samples using the GAN model checkpoint named model_42 which may be a file with .pt extension located in the folder ENV['CKPT_DIR']. Results will be stored in src/generated_samples.

(FaceGen) > python main.py GAN --generate model_42 5

Results Samples

Samples evolution along training process checkpoints from VAE with UTKFace dataset: VAE Generations

Samples evolution along training process checkpoints from VAE with CelebA dataset: VAE Generations

Samples evolution along training process checkpoints from GAN with UTKFace dataset: VAE Generations

Samples evolution along training process checkpoints from GAN with CelebA dataset: VAE Generations

facegen's People

Contributors

gonzalorecio avatar josepdecid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.