Giter Club home page Giter Club logo

ganimation's Introduction

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.

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:

  • attribute_images: images from which the Action Units that we want to use for the animation were computed.
  • images_to_animate: images that we want to animate.
  • pretrained_models: pretrained models (only the generator is needed, you can download it from here
  • results: folder where the resulting images will be stored.
  • attributes.txt: file with the action units from 'attribute_images' computed.

The two options already implemented are the following:

  • animate_image: applies the expressions from 'attributes.txt' to the images in 'images_to_animate'.
  • animate_random_batch: applies the expressions from 'attributes.txt' to random batches of images from the training dataset.

Train the model

Parameters

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

Lambdas
  • lambda_cls: classification lambda.
  • lambda_rec: lambda for the cycle consistency loss.
  • lambda_gp: gradient penalty lambda.
  • lambda_sat: lambda for attention saturation loss.
  • lambda_smooth: lambda for attention smoothing loss.
Training parameters
  • c_dim: number of Action Units to use to train the model.
  • batch_size
  • num_epochs
  • num_epochs_decay: number of epochs to start decaying the learning rate.
  • g_lr: generator's learning rate.
  • d_lr: discriminator's learning rate.
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'.

  • resume_iters: iteration numbre from which we want to start the training. Note that we will need to have a saved model corresponding to that exact iteration number.
  • first_epoch: initial epoch for when we train from pretrained models.
Miscellaneous:
  • mode: train/test.
  • image_dir: path to your image folder.
  • attr_path: path to your attributes txt folder.
  • outputs_dir: name for the output folder.

Virtual

  • use_virtual: this flag activates the use of cycle consistency loss during the training.

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

  • Clean Test function. (DONE)
  • Add an Action Units selector option for training.
  • Add multi-gpu support.
  • Smoother video generation.

ganimation's People

Contributors

vipermu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ganimation's Issues

Could you tell me how many images were used as the data set?

I'm going to train a new model on CelebA-HQ with a pixel size of 384*384px to test the effect of high quality faces, have you tried it? Too large data set will take too long and it is more difficult to train with such large pixels, could you tell me how many images were used as the data set?

Deal with multiple faces

Great Work! Your work is of great help for me.
But I have a question now, can your model handle multiple faces ? If I have a picture that contains multiple faces, how can I create a face animation?
Waiting for your help,thanks

so hard to train

Hi, I use the preprocessed CelebA dataset that you provided to train, but the attention masks become 1 after several iters. I didn't change the parameters in the code.
lambda_cls=160, lambda_rec=10, lambda_gp=10, lambda_sat=0.1, lambda_smooth=1e-4.
When I change lambda_sat to 1, the attention masks also saturate to 1.
But when I change lambda_sat to 1.5, the attention masks become 0.
Your pretrained model works well,did you use the same parameters?
Thanks!

Error on using pretrained models on CPU only machine

RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location='cpu' to map your storages to the CPU.
Even after changing the map_location to 'cpu' the problem still persists and ask for a GPU.
Any help is appreciated.

Generate attribute_image

Great Work! Your work is of great help to me. But I have a problem.
How can I generate attributes.txt in folder eric_andree?

Please help me
Thanks!

RuntimeError: CUDA error: unknown error

Hello! Thanks for your work.
But I have a problem while using "python main.py --mode animation"
I test with cuda9.0 cuda10.0 and cuda10.1 but result in the same error, how can I solve this problem?

Training images: 156295
Testing images: 100
Model running on cuda:0
Traceback (most recent call last):
File "main.py", line 60, in
main(config)
File "main.py", line 25, in main
solver = Solver(data_loader, config_dict)
File "C:\Users\15974\Desktop\ganimation-master\solver.py", line 35, in init
self.build_model()
File "C:\Users\15974\Desktop\ganimation-master\utils.py", line 17, in build_model
self.g_repeat_num).to(self.device)
File "D:\tools\anaconda3\envs\gan\lib\site-packages\torch\nn\modules\module.py", line 386, in to
return self._apply(convert)
File "D:\tools\anaconda3\envs\gan\lib\site-packages\torch\nn\modules\module.py", line 193, in _apply
module._apply(fn)
File "D:\tools\anaconda3\envs\gan\lib\site-packages\torch\nn\modules\module.py", line 193, in _apply
module._apply(fn)
File "D:\tools\anaconda3\envs\gan\lib\site-packages\torch\nn\modules\module.py", line 199, in apply
param.data = fn(param.data)
File "D:\tools\anaconda3\envs\gan\lib\site-packages\torch\nn\modules\module.py", line 384, in convert
return t.to(device, dtype if t.is_floating_point() else None, non_blocking)
File "D:\tools\anaconda3\envs\gan\lib\site-packages\torch\cuda_init
.py", line 163, in _lazy_init
torch._C._cuda_init()
RuntimeError: CUDA error: unknown error

Is there any extra procedure I should convert these images to GIF?

Hi, your project is brillant and I have recurrent it on my machine.

I have a question that how could I got the result like GIF in your readme? Because the results in local result folder are image, is there any extra procedure I should convert these images to GIF?

Thanks!

Missing action unit

Hello @vipermu, thanks for your great work.

I have a question regarding action units on attributes.txt.
OpenFace is able to recognise 18 AUs, but attribtues.txt seems to only have 17 AUs. Could you please inform me which AU is missing?

Cannot open the links

Hi, thank you for your contribution to ganimation project. However, I could not open the links of your pretrained models. Could you please check the links again?

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.