Home

Awesome

GANimation

This repository contains an implementation of GANimation by Pumarola et al. based on StarGAN code by @yunjey. With this model they are able to modify in a continuous way facial expressions of single images.

Pretrained models and the preprocessed CelebA dataset are provided to facilitate the use of this model as well as the process for preparing other datasets for training this model.

<p align="center"> <img width="170" height="170" src="https://github.com/vipermu/ganimation/blob/master/video_results/frida.gif"> </p> <p align="center"> <img width="600" height="150" src="https://github.com/vipermu/ganimation/blob/master/video_results/eric_andre.gif"> </p>

Setup

Conda environment

Create your conda environment by just running the following command: conda env create -f environment.yml

Datasets

CelebA preprocessed dataset

Download and unzip the CelebA preprocessed dataset uploaded to this link extracted from MMLAB. Here you can find a folder containing the aligned and resized 128x128 images as well as a txt file containing their respective Action Units vectors computed using OpenFace. By default, this code assumes that you have these two elements in ./data/celeba/.

Use your own dataset

If you want to use other datasets you will need to detect and crop bounding boxes around the face of each image, compute their corresponding Action Unit vectors and resize them to 128x128px.

You can perform all these steps using OpenFace. First you will need to setup the project. They provide guides for linux and windows. Once the models are compiled, read their Action Unit wiki and their documentation on these models to find out which is the command that you need to execute.

In my case the command was the following: ./build/bin/FaceLandmarkImg -fdir datasets/my-dataset/ -out_dir processed/my-processed-dataset/ -aus -simalign -au_static -nobadaligned -simsize 128 -format_aligned jpg -nomask

After computing these Action Units, depending on the command that you have used, you will obtain different output formats. With the command that I used, I obtained a csv file for each image containing its corresponding Action Units vector among extra information, a folder for each image containing the resized and cropped image and a txt file with extra details about each image. You can find in openface_utils folder the code that I used to extract all the Action Unit information in a txt file and to group all the images into a single folder.

After having the Action Unit txt file and the image folder you can move them to the directory of this project. By default, this code assumes that you have these two elements in ./data/celeba/.

Generate animations

Pretrained models can be downloaded from this link. This folder contains the weights of both models (the Generator and the Discriminator) after training the model for 37 epochs.

By running python main.py --mode animation the default animation will be executed. There are two different types of animations already implemented which can be selected with the parameter 'animation_mode'. It is presuposed that the following folders are present:

The two options already implemented are the following:

Train the model

Parameters

You can either modify these parameters in main.py or by calling them as command line arguments.

Lambdas
Training parameters
Pretrained models parameters

The weights are stored in the following format: <epoch>-<iteration>-<G/D>.ckpt where G and D represent the Generator and the Discriminator respectively. We save the state of thoptimizers in the same format and extension but add '_optim'.

Miscellaneous:

Virtual

Virtual Cycle Consistency Loss

The aim of this new component is to minimize the noise produced by the Action Unit regression. This idea was extracted from Label-Noise Robust Multi-Domain Image-to-Image Translation by Kaneko et al.. It is not proven that this new component improves the outcomes of the model but the masks seem to be darker when it is applied without losing realism on the output images.

TODOs