Giter Club home page Giter Club logo

gif's Introduction

GIF: Generative Interpretable Faces

This is the official implementation for the paper GIF: Generative Interpretable Faces. GIF is a photorealistic generative face model with explicit control over 3D geometry (parametrized like FLAME), appearance, and lighting.

  • Key words: Generative Interpretable Faces, conditional generative models, 3D conditioning of GANs, explicit 3D control of photorealistic faces, Photorealistic faces.

Important links

Watch a brief presentation

Watch a presentation

Citation

If you find our work useful in your project please cite us as

@inproceedings{GIF2020,
    title = {{GIF}: Generative Interpretable Faces},
    author = {Ghosh, Partha and Gupta, Pravir Singh and Uziel, Roy and Ranjan, Anurag and Black, Michael J. and Bolkart, Timo},
    booktitle = {International Conference on 3D Vision (3DV)},
    year = {2020},
    url = {http://gif.is.tue.mpg.de/}
}

Installation

  • python3 -m venv ~/.venv/gif
  • source ~/.venv/gif/bin/activate
  • pip install -r requirements.txt

First thing first

Before Running any program you will need to download a few resource files and create a suitable placeholder for the training artifacts to be stored

  1. you can use this link to download input files necessary to train GIF from scratch - http://files.is.tuebingen.mpg.de/gif/input_files.zip
  2. you can use this link to download checkpoints and samples generated from pre-trained GIF models and its ablated versions - http://files.is.tuebingen.mpg.de/gif/output_files.zip
  3. Now create a directory called GIF_resources and unzip the input zip or checpoint zip or both in this directory
  4. When you train or fine tune a model the output directory checkpoint and sample directory will be populated. Rmember that the model atifacts can easily become a few 10s of terabytes
  5. The main resource directory should be named GIF_resources and it should have input_files and output_fiels as sub-directories
  6. Now you need to provide the path to this directory in the constants.py script and make changes if necessary if you wish to change names of the subdirectories
  7. Edit the line resources_root = '/path/to/the/unzipped/location/of/GIF_resources'
  8. Modify any other paths as you need
  9. Download the FLAME 2020 model and the FLAME texture space from here - https://flame.is.tue.mpg.de/ (you need to sign up and agree to the license for access)
  10. Please make sure to dowload 2020 version. After signing in you sould be able to download FLAME 2020
  11. Download the FLAME_texture_data, Unzip it and place the texture_data_256.npy file in the flame resources directory.
  12. Please place the generic_model.pkl file in GIF_resources/input_files/flame_resource
  13. In this directory you will need to place the generic_model.pkl, head_template_mesh.obj, and FLAME_texture.npz in addition to the already provided files in the zip you just downloaded from the link given above. You can find these files from the official flame website. Link given in point 9.

Preparing training data

To train GIF you will need to prepare two lmdb datasets

  1. An LMDB datset containing FFHQ images in different scales
    1. To prepare this cd prepare_lmdb
    2. run python prepare_ffhq_multiscale_dataset.py --n_worker N_WORKER DATASET_PATH
    3. Here DATASET_PATH is the parth to the directory that contains the FFHQ images
    4. Place the created lmdb file in the GIF_resources/input_files/FFHQ directory, alongside ffhq_fid_stats
  2. An LMDB dataset containing renderings of the FLAME model
    1. To run GIF you will need the rendered texture and normal images of the FLAME mesh for FFHQ images. This is already provided as deca_rendered_with_public_texture.lmdb with the input_file zip. It is located in GIF_resources_to_upload/input_files/DECA_inferred
    2. To create this on your own simply run python create_deca_rendered_lmdb.py

Training

To resume training from a checkpoint run python train.py --run_id <runid> --ckpt /path/to/saved.mdl/file/<runid>/model_checkpoint_name.model

Note here that you point to the .model file not the npz one.

To start training from scratch run python train.py --run_id <runid>

Note that the training code will take all available GPUs in the system and perform data parallelization. You can set visible GPUs by etting the CUDA_VISIBLE_DEVICES environment variable. Run CUDA_VISIBLE_DEVICES=0,1 python train.py --run_id <runid> to run on GPU 0 and 1

To run random face generation follow the following steps

  1. Clone this repo
  2. Download the pretrained model. Please note that you have to download the model with correct run_id
  3. activate your virtual environment
  4. cd plots
  5. python generate_random_samples.py
  6. Remember to uncomment the appropriate run_id

To generate Figure 3

  1. cd plots
  2. python role_of_different_parameters.py it will generate batch_size number of directories in f'{cnst.output_root}sample/' named gen_iamges<batch_idx>. Each of these directory contain a column of images as shown in figure 3 in the paper.

Amazon mechanical turk (AMT) evaluations:

Disclaimer: This section can be outdated and/or have changed since the time of writing the document. It is neither intended to advertise nor recommend any particular 3rd party product. The inclusion of this guide is solely for quick reference purposes and is provided without any liability.

  • you will need 3 accounts
  1. Mturk - https://requester.mturk.com/
  2. Mturk sandbox - just for experiments (No real money involved) https://requestersandbox.mturk.com/
  3. AWS - for uploading the images https://aws.amazon.com/
  • once that is done you may follow the following steps
  1. Upload the images to S3 in AWS website (into 2 different folders. e.g. model1, model2)
  2. Make the files public. (You can verify it by clicking one file, and try to view the image using the link)
  3. Create one project (not so sure what are the optimal values there, I believe that people at MPI have experience with that
  4. In “Design Layout” insert the html code from mturk/mturk_layout.html or write your own layout
  5. Finally you will have to upload a CSV file which will have s3 or any other public links for images that will be shown to the participants
  6. You can generate such links using the generate_csv.py or the create_csv.py scripts
  7. Finally follow an AMT tutorial to deploye and obtain the results
  8. You may use the plot_results.py or plot_histogram_results.py script to visualize AMT results

Running the naive vector conditioning model

  • Code to run vector conditioning to arrvie soon on a different branch :-)

Acknowledgements

GIF uses DECA to get FLAME geometry, appearance, and lighting parameters for the FFHQ training data. We thank H. Feng for prepraring the training data, Y. Feng and S. Sanyal for support with the rendering and projection pipeline, and C. Köhler, A. Chandrasekaran, M. Keller, M. Landry, C. Huang, A. Osman and D. Tzionas for fruitful discussions, advice and proofreading. We specially thank Taylor McConnell for voicing over our video. The work was partially supported by the International Max Planck Research School for Intelligent Systems (IMPRS-IS) and by Amazon Web Services.

gif's People

Contributors

guptapravirsingh avatar parthaeth avatar timobolkart avatar vrwarg 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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

gif's Issues

When is the code open source?

Thanks to your work "GIF: Generative Interpretable Faces", and I'm interested in this work and desiring for the source code. I wonder when it will be public, or can you send the original code to me? Thanks, looking forward your reply.

CUDA out of memory

I have got this issue when I try to run python generate_voca_animation.py

any hint?

Output:
Collating FFHQ parameters
Collating FFHQ parameters, done!
<<<<<<<<<< Running Style GAN 2 >>>>>>>>>>>>>>>>>>>>>>>
generator const_input n_params: 8192
generator to_rgb n_params: 1568667
generator progression n_params: 27955884
generator z_to_w n_params: 2101248
creating the FLAME Decoder
/home/wiam/Desktop/GIF/my_utils/photometric_optimization/models/FLAME.py:92: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
self.register_buffer('dynamic_lmk_faces_idx', torch.tensor(lmk_embeddings['dynamic_lmk_faces_idx'], dtype=torch.long))
/home/wiam/Desktop/GIF/my_utils/photometric_optimization/models/FLAME.py:93: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
self.register_buffer('dynamic_lmk_bary_coords', torch.tensor(lmk_embeddings['dynamic_lmk_bary_coords'], dtype=self.dtype))
/home/wiam/anaconda3/envs/gif3/lib/python3.8/site-packages/pytorch3d/io/obj_io.py:533: UserWarning: Mtl file does not exist: /home/wiam/Desktop/GIF/GIF_resources/input_files//flame_resource/template.mtl
warnings.warn(f"Mtl file does not exist: {f}")
creating the FLAME Decoder
/home/wiam/Desktop/GIF/my_utils/photometric_optimization/models/FLAME.py:92: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
self.register_buffer('dynamic_lmk_faces_idx', torch.tensor(lmk_embeddings['dynamic_lmk_faces_idx'], dtype=torch.long))
/home/wiam/Desktop/GIF/my_utils/photometric_optimization/models/FLAME.py:93: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
self.register_buffer('dynamic_lmk_bary_coords', torch.tensor(lmk_embeddings['dynamic_lmk_bary_coords'], dtype=self.dtype))
0%| | 0/30 [00:00<?, ?it/s]/home/wiam/anaconda3/envs/gif3/lib/python3.8/site-packages/torch/nn/functional.py:3060: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details.
warnings.warn("Default upsampling behavior when mode={} is changed "
0%| | 0/30 [00:26<?, ?it/s]
Traceback (most recent call last):
File "generate_voca_animation.py", line 90, in
overlay_visualizer.get_rendered_mesh(flame_params=(shape_batch, exp_batch, pose_batch,
File "/home/wiam/Desktop/GIF/my_utils/visualize_flame_overlay.py", line 24, in get_rendered_mesh
self.rendering_helper.render_tex_and_normal(shapecode=shape, expcode=expression,
File "/home/wiam/Desktop/GIF/my_utils/photometric_optimization/gif_helper.py", line 33, in render_tex_and_normal
albedos = self.flametex(texcode)
File "/home/wiam/anaconda3/envs/gif3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(input, **kwargs)
File "/home/wiam/Desktop/GIF/my_utils/photometric_optimization/models/FLAME.py", line 256, in forward
texture = self.texture_mean + (self.texture_basis
texcode[:,None,:]).sum(-1)
RuntimeError: CUDA out of memory. Tried to allocate 4.69 GiB (GPU 0; 11.17 GiB total capacity; 1.63 GiB already allocated; 4.20 GiB free; 6.41 GiB reserved in total by PyTorch)

Reproducing the results for table 3

Dear authors, thank you for sharing your valuable work. I was trying to generate the results like table 3 of the paper using the script GIF/tests/deca_inf_vs_given_cond_landmark_viz.py. Here, I could not find the paths for flame_datapath and face_region_only_indices variable.

RuntimeError: Not compiled with GPU support

Dear authors, thank you so much for sharing your work. I wanted to reproduce the results by training the model from scratch. I have installed the packages in the requirements.txt in a python 3.8.18 environment but I am getting error like:


Exception has occurred: RuntimeError       (note: full exception trace is shown but execution is paused at: _run_module_as_main)
Not compiled with GPU support
  File "/data/mdwkhan/3d_gen_codes/pytorch3d/pytorch3d/renderer/mesh/rasterize_meshes.py", line 189, in forward
    pix_to_face, zbuf, barycentric_coords, dists = _C.rasterize_meshes(
  File "/data/mdwkhan/3d_gen_codes/pytorch3d/pytorch3d/renderer/mesh/rasterize_meshes.py", line 136, in rasterize_meshes
    return _RasterizeFaceVerts.apply(
  File "/data/mdwkhan/3d_gen_codes/GIF/my_utils/photometric_optimization/renderer.py", line 59, in forward
    pix_to_face, zbuf, bary_coords, dists = rasterize_meshes(
  File "/data/mdwkhan/anaconda3/envs/gif2/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/data/mdwkhan/3d_gen_codes/GIF/my_utils/photometric_optimization/renderer.py", line 152, in forward
    rendering = self.rasterizer(transformed_vertices, self.faces.expand(batch_size, -1, -1), attributes)
  File "/data/mdwkhan/anaconda3/envs/gif2/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/data/mdwkhan/3d_gen_codes/GIF/my_utils/photometric_optimization/gif_helper.py", line 37, in render_tex_and_normal
    rendering_results = self.render(verts, trans_verts, albedos, lights=lightcode)
  File "/data/mdwkhan/3d_gen_codes/GIF/my_utils/visualize_flame_overlay.py", line 24, in get_rendered_mesh
    self.rendering_helper.render_tex_and_normal(shapecode=shape, expcode=expression,
  File "/data/mdwkhan/3d_gen_codes/GIF/loss_functions/losses.py", line 210, in get_image_and_textures
    self.flame_visualizer.get_rendered_mesh(flame_params=(shape, exp, pose, light_code, texture_code),
  File "/data/mdwkhan/3d_gen_codes/GIF/loss_functions/losses.py", line 163, in tex_sp_intrp_loss
    textures, tx_masks, _ = self.get_image_and_textures(alpha, flame_batch, generator, max_ids, normal_maps_as_cond,
  File "/data/mdwkhan/3d_gen_codes/GIF/train.py", line 229, in train
    interp_loss = interp_tex_loss.tex_sp_intrp_loss(
  File "/data/mdwkhan/3d_gen_codes/GIF/train.py", line 402, in <module>
    train(args, dataset, generator, discriminator_flm, fid_computer, flame_param_est, used_sampless,
  File "/data/mdwkhan/anaconda3/envs/gif2/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/data/mdwkhan/anaconda3/envs/gif2/lib/python3.8/runpy.py", line 194, in _run_module_as_main (Current frame)
    return _run_code(code, main_globals, None,
RuntimeError: Not compiled with GPU support

about flame parameters

Hi, thanks for your great work!
I find that DECA can only preocess images with size 224*224 ? How do you get the flame parameters of FFHQ which are 1024 *1024?
Hope to get your guidance!

Mtl file does not exist

hello
when I run generate_random_samples.py I found this warning.Please tell me where I can find this file.Thanks
/usr/local/lib/python3.6/dist-packages/pytorch3d/io/obj_io.py:457: UserWarning: Mtl file does not exist: /content/GIF/GIF_resources/input_files/flame_resource/template.mtl
warnings.warn(f"Mtl file does not exist: {f}")

train on my own datasets ,but the test results are bad

Hi, @ParthaEth, I have followed your step to create my own datasets, but after train for a few days, the test results are all bad(I only use one person(6k images) to train, and it contain abundant expression and pose )

329292484

I first use DECA to get parameters and then create the datasets use the scripts in prepare_lmdb
My loss values are nearly like below: G_loss=5.x/ D_loss=1.x/embd_reg_loss=0/interp_loss=2.x

Hope you can give some advice, thanks~

GIF_resources link is missing

Thinks for your great job, it's brings new ideas to this research topic.
However, I find that GIF_resources file is missing, and the link to the file is not public available.
Could you please release necessary files recently? Can't wait to run your code.

Thanks.

ModuleNotFoundError: No module named 'my_utils.photometric_optimization.models'

Hi! I've followed the "First thing first" instructions. Now I'd like to generate some images, without any training, so I continued with the "To run random face generation" instructions, but I get this error

python role_of_different_parameters.py
Traceback (most recent call last):
File "role_of_different_parameters.py", line 7, in
from model.stg2_generator import StyledGenerator
File "../model/stg2_generator.py", line 15, in
from my_utils.photometric_optimization.models import FLAME
ModuleNotFoundError: No module named 'my_utils.photometric_optimization.models'

error: verts, faces, aux = load_obj(obj_filename)

Hi, thanks for your great work!
I have completed the configuration followed first thing first section of the read me,
But when I run python generate_random_samples.py , I got some errors, Can you give me some proposal!thanks!

../GIF-master/my_utils/photometric_optimization/renderer.py line 94
verts, faces, aux = load_obj(obj_filename) #line:93
uvcoords = aux.verts_uvs[None, ...] # (N, V, 2) line:94

File "../GIF-master/my_utils/photometric_optimization/renderer.py", line 94, in init
TypeError: 'NoneType' object is not subscriptable

File is missing

line in generate_gif.py from my_utils.ringnet_overlay.util import tensor_vis_landmarks, There is no such folder in the repository. Could you please upload it?

File not found:'b_box_stats.npz'

Thanks for your work.
When I run codes under "plots/voca/", I got an error: Can't find the file named "b_box_stats.npz", I found that the path of "b_box_stats.npz" is from "constants.py",line 50.
I don’t know where to get this file. Could you tell me how to get it?

run fail

I not sure it is model version or code version issue?

File "generate_random_samples.py", line 162, in
flm_batch = position_to_given_location(flame_decoder, flm_batch)
File "../my_utils/eye_centering.py", line 39, in position_to_given_location
verts, _, _ = deca_flame_decoder(shape_params=shape, expression_params=expression, pose_params=pose)
File "/home/ubuntu/.conda/envs/gif/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "../my_utils/photometric_optimization/models/FLAME.py", line 204, in forward
self.lbs_weights, dtype=self.dtype)
File "../my_utils/photometric_optimization/models/lbs.py", line 211, in lbs
J_transformed, A = batch_rigid_transform(rot_mats, J, parents, dtype=dtype)
File "../my_utils/photometric_optimization/models/lbs.py", line 353, in batch_rigid_transform
rel_joints.view(-1, 3, 1)).view(-1, joints.shape[1], 4, 4)
RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.

git clone gives an error

I followed your instruction "First things first" and got error:

git clone --recurse-submodules [email protected]:ParthaEth/GIF.git
Cloning into 'GIF'...
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Is there something wrong?

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.