Home

Awesome

GANimation -- An Out-of-the-Box Replicate

<p align="left"> <img src="https://img.shields.io/badge/Status-Release-gold.svg?style=flat-square" alt="Status"> <img src="https://img.shields.io/badge/Platform-Linux | macOS-lightgrey.svg?style=flat-square" alt="Platform"> <img src="https://img.shields.io/badge/PyTorch Version-0.4.1-blue.svg?style=flat-square" alt="PyTorch"> <img src="https://img.shields.io/badge/License-MIT-green.svg?style=flat-square" alt="License"> </p>

A reimplementation of GANimation: Anatomically-aware Facial Animation from a Single Image, using PyTorch. Pretrained models/weights are available at GDrive or BaiduPan(Code:3fyb) !

<div align="center"> <img src="imgs/gifs/celeba_1.gif"> <img src="imgs/gifs/celeba_2.gif"> <img src="imgs/gifs/emotionnet_1.gif"> <img src="imgs/gifs/emotionnet_2.gif"> <img src="imgs/gifs/emotionnet_3.gif"> <img src="imgs/gifs/emotionnet_4.gif"> </div>

ganimation_show

Pros (compared with the official implementation)

All resources related to this project are located at GDrive or BaiduPan(Code:3fyb).

Getting Started

Requirements

Installation

git clone https://github.com/donydchen/ganimation_replicate.git
cd ganimation_replicate
pip install -r requirements.txt

Resources

Train

python main.py --data_root [path_to_dataset]

# e.g. python main.py --data_root datasets/celebA --gpu_ids 0,1 --sample_img_freq 500
#      python main.py --data_root datasets/emotionNet --gpu_ids 0,1 --sample_img_freq 500
#      set '--visdom_display_id 0' if you don't want to use visdom
#      use 'python main.py -h' to check out more options.

Test

python main.py --mode test --data_root [path_to_dataset] --ckpt_dir [path_to_pretrained_model] --load_epoch [epoch_num]

# e.g. python main.py --mode test --data_root datasets/celebA --batch_size 8 --max_dataset_size 150 --gpu_ids 0,1 --ckpt_dir ckpts/celebA/ganimation/190327_161852/ --load_epoch 30
#      set '--interpolate_len 1' if you don't need linear interpolation.
#      use '--save_test_gif' to generate animated images.

Finetune

python main.py --data_root [path_to_dataset] --ckpt_dir [path_to_existing_checkpoint] --load_epoch [epoch_num] 

# e.g. python main.py --data_root datasets/celebA --gpu_ids 0,1 --sample_img_freq 300 --n_threads 18 --ckpt_dir ckpts/celebA/ganimation/190327_161852 --load_epoch 30 --epoch_count 31 --niter 30 --niter_decay 10

Use Own Datasets

./FaceLandmarkImg -f [path_to_img] -aus

# In the result file, values of columns [2:19] are extracted for later usage.

Some Results

CelebA

Training

celeba_training

Testing (with GANimation model, on epoch 30)

celeba_testing

Testing (with StarGAN model, on epoch 30)

celeba_stargan_testing

EmotionNet (Visual quality is much better than that of CelebA)

Training

emotionnet_training

Testing (with GANimation model, on epoch 30)

emotionnet_testing

Testing (with StarGAN model, on epoch 30)

emotionnet_stargan_testing

Why this Project?

My mentor came up with a fancy idea of playing GANs with AUs when I was an intern at AI Lab, Lenovo Research around early August, 2018. I enjoyed the idea very much and started working on it. However, just a few days after that, the GANimation paper showed up, which was not a good news for us... So I tried to replicate GANimation, and this is the start of this project.

And in late August, 2018, I came accross an issue on the official GANimation implementation, claiming that the test result is wrong. While in my case, I did get some reasonable results, so I replied that issue with the results I had got. Since the author of GANimation hadn't decided to release the pretrained model yet, I recieved Emails inquiring me whether I could offer my codes and pretrained models from time to time.

I really wanted to provide the codes and pretrained models. However, I was very busy in the past few months, moving from Beijing to Singapore, working for paper deadlines, so on and so forth. So the codes remained in the server of Lenovo Research for half an year. And these days, I finally got some free time. So I dug out the codes, cleaned them, retrained the network, and now, I make them public. I will keep updating this project if I have time, and hope that these codes can serve to faciliate the research of someone who are working on the related tasks.

Feel free to contact me if you need any help from me related to this project.

Pull Request

You are always welcome to contribute to this repository by sending a pull request.