Giter VIP home page Giter VIP logo

ringnet's Introduction

RingNet

alt text

This is an official repository of the paper Learning to Regress 3D Face Shape and Expression from an Image without 3D Supervision. The project was formerly referred by RingNet. The codebase consists of the inference code, i.e. give an face image using this code one can generate a 3D mesh of a complete head with the face region. For further details on the method please refer to the following publication,

Learning to Regress 3D Face Shape and Expression from an Image without 3D Supervision
Soubhik Sanyal, Timo Bolkart, Haiwen Feng, Michael J. Black
CVPR 2019

More details on our NoW benchmark dataset, 3D face reconstruction challenge can be found in our project page. A pdf preprint is also available on the project page.

  • Update: We have changed the license agreemnt for the RingNet code and pre-trained weights. Both are now available under MIT license excluding the NoW Challenge dataset.

  • Update: We have released the evaluation code for NoW Benchmark challenge here.

  • Update: Add demo to build a texture for the reconstructed mesh from the input image.

  • Update: NoW Dataset is divided into Test set and Validation Set. Ground Truth scans are available for the Validation Set. Please Check our project page for more details.

  • Update: We have released a PyTorch implementation of the decoder FLAME with dynamic conture loading which can be directly used for training networks. Please check FLAME_PyTorch for the code.

Installation

The code uses Python 2.7 and it is tested on Tensorflow gpu version 1.12.0, with CUDA-9.0 and cuDNN-7.3.

Setup RingNet Virtual Environment

virtualenv --no-site-packages <your_home_dir>/.virtualenvs/RingNet
source <your_home_dir>/.virtualenvs/RingNet/bin/activate
pip install --upgrade pip==19.1.1

Clone the project and install requirements

git clone https://github.com/soubhiksanyal/RingNet.git
cd RingNet
pip install -r requirements.txt
pip install opendr==0.77
mkdir model

Install mesh processing libraries from MPI-IS/mesh. (This now only works with python 3, so donot install it)

  • Update: Please install the following fork for working with the mesh processing libraries with python 2.7

Download models

  • Download pretrained RingNet weights from the project website, downloads page. Copy this inside the model folder
  • Download FLAME 2019 model from here. Copy it inside the flame_model folder. This step is optional and only required if you want to use the output Flame parameters to play with the 3D mesh, i.e., to neutralize the pose and expression and only using the shape as a template for other methods like VOCA (Voice Operated Character Animation).
  • Download the FLAME_texture_data and unpack this into the flame_model folder.

Demo

RingNet requires a loose crop of the face in the image. We provide two sample images in the input_images folder which are taken from CelebA Dataset.

Output predicted mesh rendering

Run the following command from the terminal to check the predictions of RingNet

python -m demo --img_path ./input_images/000001.jpg --out_folder ./RingNet_output

Provide the image path and it will output the predictions in ./RingNet_output/images/.

Output predicted mesh

If you want the output mesh then run the following command

python -m demo --img_path ./input_images/000001.jpg --out_folder ./RingNet_output --save_obj_file=True

It will save a *.obj file of the predicted mesh in ./RingNet_output/mesh/.

Output textured mesh

If you want the output the predicted mesh with the image projected onto the mesh as texture then run the following command

python -m demo --img_path ./input_images/000001.jpg --out_folder ./RingNet_output --save_texture=True

It will save a *.obj, *.mtl, and *.png file of the predicted mesh in ./RingNet_output/texture/.

Output FLAME and camera parameters

If you want the predicted FLAME and camera parameters then run the following command

python -m demo --img_path ./input_images/000001.jpg --out_folder ./RingNet_output --save_obj_file=True --save_flame_parameters=True

It will save a *.npy file of the predicted flame and camera parameters and in ./RingNet_output/params/.

Generate VOCA templates

If you want to play with the 3D mesh, i.e. neutralize pose and expression of the 3D mesh to use it as a template in VOCA (Voice Operated Character Animation), run the following command

python -m demo --img_path ./input_images/000013.jpg --out_folder ./RingNet_output --save_obj_file=True --save_flame_parameters=True --neutralize_expression=True

License

Free for non-commercial and scientific research purposes. By using this code, you acknowledge that you have read the license terms (https://ringnet.is.tue.mpg.de/license.html), understand them, and agree to be bound by them. If you do not agree with these terms and conditions, you must not use the code. For commercial use please check the website (https://ringnet.is.tue.mpg.de/license.html).

Referencing RingNet

Please cite the following paper if you use the code directly or indirectly in your research/projects.

@inproceedings{RingNet:CVPR:2019,
title = {Learning to Regress 3D Face Shape and Expression from an Image without 3D Supervision},
author = {Sanyal, Soubhik and Bolkart, Timo and Feng, Haiwen and Black, Michael},
booktitle = {Proceedings IEEE Conf. on Computer Vision and Pattern Recognition (CVPR)},
month = jun,
year = {2019},
month_numeric = {6}
}

Contact

If you have any questions you can contact us at [email protected] and [email protected].

Acknowledgement

  • We thank Ahmed Osman for his support in the tensorflow implementation of FLAME.
  • We thank Raffi Enficiaud and Ahmed Osman for pushing the release of psbody.mesh.
  • We thank Benjamin Pellkofer and Jonathan Williams for helping with our RingNet project website.

ringnet's People

Contributors

soubhiksanyal avatar timobolkart avatar tomguluson92 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ringnet's Issues

preserve identity

is it possible to preserve identity for the output meshes, in the gif added to the readme it shows a stage where the identities are preserved and later generalized, can the output obj file be set to the previous stage where identity is preserved?

Mesh from predicted parameters issue

Hi, thanks for this amazing work! I am trying to recover the mesh from the predicted parameters(100 D shape, 50 expression and 6 dimensional pose), and I used a modified version "make_prdicted_mesh_neutral' function(copy flame-fitting project) to do this, it seems the shape and pose is correct, but the expression is wrong. Am I missed something? Thanks a lot.

`
def make_prdicted_mesh_neutral_ringnet(predicted_params_path, flame_model_path):
params = np.load(predicted_params_path, allow_pickle=True)
params = params[()]

pose,betas = np.zeros(15),np.zeros(400)
pose[:3],pose[-3:]= params['pose'][:3],params['pose'][3:]
betas[:params['shape'].shape[0]] = params['shape']
betas[300:300+params['expression'].shape[0]] = params['expression']

flame_genral_model = load_model(flame_model_path)
generated_neutral_mesh = verts_decorated(ch.array([0,0,0]),
                    ch.array(pose),
                    ch.array(flame_genral_model.r),
                    flame_genral_model.J_regressor,
                    ch.array(flame_genral_model.weights),
                    flame_genral_model.kintree_table,
                    flame_genral_model.bs_style,
                    flame_genral_model.f,
                    bs_type=flame_genral_model.bs_type,
                    posedirs=ch.array(flame_genral_model.posedirs),
                    betas=ch.array(betas),#betas=ch.array(np.concatenate((theta[0,75:85], np.zeros(390)))), #
                    shapedirs=ch.array(flame_genral_model.shapedirs),
                    want_Jtr=True)
return generated_neutral_mesh

`
1563679320

psbody?

can you tell me how to install psbody packages?

Version opencv

Hello, thanks or the release of this project! Which version of OpenCV did you use?

Mismatch of RingNet output and FLAME parameter

Greetings.
RingNet output a 159-dimensional vector. which contains 100-dimensional shape parameters, 50-dimension expression parameter and 6-dimensional pose parameter.
However, in Flame, the shape parameter is in shape (300,), expression parameter is in shape (100,), pose parameter is in shape (12,)

https://github.com/Rubikplayer/flame-fitting/blob/d3c4d3d4284d9ba8d36be0b224de7ce133301ebc/hello_world.py#L25-L27

If you can give some explanation, I'd be most grateful.
Thanks in advance!

Output mesh render is blank

Hi,

Thank you so much for your great work!

I have an issue. When I run the following command:

python -m demo --img_path ./input_images/000001.jpg --out_folder ./RingNet_output --save_obj_file=True

Output file does not show any mesh result in 2D images like below:

000001

On the other hand, it produces the mesh like below:

image_000013_mesh_not_perfect

opendr version is 0.77.

I would like to ask how can I get the predicted (output of the model) vertex coordinates or landmark coordinates (points) of the original 2D input image?

Differenciable FLAME decode model?

In your paper ,you use Differenciable FLAME decode model to get 3d mesh by flame parameters, and this FLAME decode model is fixed during training .My question is How to get this Differenciable FLAME decode model?

Can't fit closed eyes

@soubhiksanyal I tested RingNet with some images extracted from RAVDESS. It seems RingNet can't work well for closed eyes, just as the following image shows.
027
Is this because you just used 50 expression blendshapes, or because the limitation of the training data, or others?

For pre-trained model

hello,
thanks for your great works!
i want to follow your work, but i can't download the pretrained RingNet weights you provided on your project website. I've signed up, but the download is very slow and always broken, Can you give me some advice?
thank you again!

what is the preprocessing of the input image?

I downloads ana run your code on my platform follow your instruction, and I have download all the dependence of this project, but I find dispite the demo picture, all the other input will get almost the same result. I think some preprocessing is needed for the input picture, but I cannot find it on your project page or the paper, can you please tell me what preprocessing you do for the input picture? I will thank you more if you can show me the preprocessing code

How to get flame_textrue_data?

I show you updated the demo code yesterday,but i cannot find the description of flame_textrue_data. So how to get flame_textrue_data?

Any way to get RingNet run on Colab?

Hello, since my computer does not support CUDA 9, so I installed it on Google Colab. But Colab does not support virtualenv, and RingNet requires virtualenv to use Mesh.

Any way to get RingNet run on Colab?
Thank you.

Quantitative Evaluation

@soubhiksanyal Hi Soubhik, Thanks for your great work. The quantitative evaluation of your model is a little bit vague. Based on what you reported, you computed the error using the method in this paper, which
computes the distance from ground truth scan points to the estimated mesh surface. I went through that paper but computing the scan-to-mesh distance between the predicted meshes and the
scans is still unclear to me. Would you please share the code you used for the evaluation?
Appreciate your time.

Pose parameters for neck

"RingNet outputs a subset of the FLAME parameters. These parameters are the first 100 shape parameters, first 50 expression parameters, and the pose parameters for the global rotation (FLAME pose parameters 1-3) and the jaw rotation (FLAME pose parameters 7-9). "

Originally posted by @TimoBolkart in #7 (comment)

Wondering what are the FLAME pose parameters 4-6. Are these for the neck which is also a joint in the FLAME model? Does RingNet outputs pose parameters for neck?

Thanks,
Bing

Having trouble with tensorflow/CUDA/absl

I am new to programming and cv in general, so forgive me if my issues seem too simple.

I am using Ubuntu 18.04 and trying to replicate your included demo just to make sure the program is working. I have repeatedly run into different problems that all seem to be related to CUDA and tensorflow.

I have heard that these programs are all very sensitive to driver versions and dependencies. So far, the furthest I seem to get is to a point where I get an absl module missing error. I am sure it is installed, and have tried various version. At one point downgrading forced me to downgrade to tensorflow 1.12. Still the same issue is popping up. I am ready to start over step by step, as tedious as that is.

I wonder if anybody could explain to me how to make sure that the versions of all the needed libraries and whatnot to run RingNet are correct.

Failed to Load the native tensorflow runtime

File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory

Failed to load the native TensorFlow runtime.

Being a beginner in this domain, I seek some help to run the code. Thanks in advance!

Can model predict gazing direction of eyeballs?

Excellent work for 3D face reconstruction from 2D images!

The showing gif and demo video also exhibit eyeballs gazing directions. However, from paper and experiments, I found that the model just outputs 3D mesh, FLAME pose parameters and the jaw rotation. Thus, can we get the rotation matrix of eyeballs? Or I guess that in the demo, the rotations of eyeballs are the same as the rotations of head? Is my guess right?

How to add texture for the 3D model?

When I tried this repository many of the meshes looks similar with another. Hence the texture is really important for identification. How can I add texture to the meshes for using them in VOCA. I have tried with TF_FLAME for creating texture for the mesh using the image file but it was not usable in VOCA. Can you suggest how can I do this?

Output mesh render is blank and the pose of the mesh is wrong

Hi,

When I run the following command with the downloaded pre-trained model:
python -m demo --img_path ./input_images/000001.jpg --out_folder ./RingNet_output --save_obj_file=True

and I'm seeing the following output file.
output
000001
The pose of the reconstructed mesh is like this :
00001-obj
My opendr version is 0.77

Output mesh render is blank

Hi,

I'm running the following command with the downloaded pre-trained model:
python -m demo --img_path ./input_images/000013.jpg --out_folder ./RingNet_output

and I'm seeing the following output file.
output

The renders are all dark. When I ran the same command with the flag --save_obj_file=True,
the obj file was successfully created and I could view it successfully in Blender.
blender-mesh

basic information about output of voca model

run the following command:

python -m demo --img_path ./input_images/000013.jpg --out_folder ./RingNet_output --save_obj_file=True --save_flame_parameters=True --neutralize_expression=True

If I input a face image and generate the input of voca through the above command, is there any way to save the 3d information of the input image and rewrite it into the output obj file of voca, yes, the output of voca Is there any texture information about the input image? That is to say, the output of voca is an obj file with 3d model information (can contain v, f, vn, vf, etc.), mtl file, texture png. Thanks.

How to project 3D points to 2D image using predicted camera parameter?

I am wondering, during training, the 2D feature loss requires to project 3D feature points onto 2D plain. How is it done using the 1x3 vector of the predicted camera parameter? Any training code for the project? This is also important if one wants to align the output 3D mesh with the input 2D image.

Landmark detection

Hi, I would like to ask how to detect the 68 landmarks which PRNet/3DDFA does.
Thanks in advance.

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

python -m demo --img_path ./input_images/000013.jpg --out_folder ./RingNet_output --save_obj_file=True --save_flame_parameters=True --neutralize_expression=True
when I run this command its not giving the output of neutral_expression , I have copied the flame models to the flame_model folder. It has given at line 80 in serialization.py "dd = pickle.load(open(fname_or_dict))"
Pls help me in solving this issue and I am using pyton 3.6 as mesh libraries are working only in python 3.5+

Upgrade Python version

Thanks your excelent work.As python2.7 has be deprecated,I wonder if it is schedled to upgrade Python version for this project.

ImportError: No module named psbody.mesh

I followed the instructions for cloning and building mesh but when I run demo I get:
Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main "__main__", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/home/username/RingNet/demo.py", line 45, in <module> from psbody.mesh import Mesh ImportError: No module named psbody.mesh

How do I tell the RingNet virtual environment to load mesh? I tried running setup install on mesh in the RingNet virtual environment and just got more errors. mesh appears to be python 3 now and RingNet is Python 2 so do I have to use an older version of mesh that is python 2?

expression problem

Could the FLAME model fit the expression around the eyes? According to my test, I feel that the expression fit has some problem when close the eyes. Is there something wrong with my operation?
close1

Remove the global rotation of the generated model

Hi~
Thank you so much for your amazing work!
I originally wanted to use the following code to remove the global rotation of the generated model, but because of the limited expressiveness of the parameters, the results are different from the original model.
I would like to ask how to calculate directly on the vertex coordinates of the original model?

params = np.load(out_param, allow_pickle=True)
params = params[()]
#pose = np.hstack((params['pose'], np.zeros(15-params['pose'].shape[0])))
pose = np.zeros(15)

pose[6] = params['pose'][3]
pose[7] = params['pose'][4]
pose[8] = params['pose'][5]

expression = np.hstack((params['expression'], np.zeros(100-params['expression'].shape[0])))
shape = np.hstack((params['shape'], np.zeros(300-params['shape'].shape[0])))
flame_genral_model = load_model(config.flame_model_path)
generated_neutral_mesh = verts_decorated(ch.array([0.0,0.0,0.0]),
                                    ch.array(pose),
                                    ch.array(flame_genral_model.r),
                                    flame_genral_model.J_regressor,
                                    ch.array(flame_genral_model.weights),
                                    flame_genral_model.kintree_table,
                                    flame_genral_model.bs_style,
                                    flame_genral_model.f,
                                    bs_type=flame_genral_model.bs_type,
                                    posedirs=ch.array(flame_genral_model.posedirs),
                                    betas=ch.array(np.hstack((shape,expression))),#betas=ch.array(np.concatenate((theta[0,75:85], np.zeros(390)))), #
                                    shapedirs=ch.array(flame_genral_model.shapedirs),
                                    want_Jtr=True)
neutral_mesh = Mesh(v=generated_neutral_mesh.r, f=generated_neutral_mesh.f)
neutral_mesh.write_obj(out_mesh)
print("Saved neutral mesh file to " + out_mesh)

image

2D Projection

Hi, thanks for the amazing work. I have been doing some research work on expressions, and I decided to use RingNet to extract the expression parameters. However, I don't know how to use these parameters to realize 3D visualization. In addition, to observe the coherence of the expression sequence, I need to obtain the 2D projection of Flame model. Could you do me a favor on these problems?

Minimum gpu memory requirement

Hi, I tried to run the demo on RTX2060 6G, unfortunately ran out of gpu memory, so I want to know what is the minimum GPU memory requirement?

GPU:0 with 591 MB memory) -> physical GPU (device: 0, name: GeForce RTX 2060, pci bus id: 0000:09:00.0, compute capability: 7.5)
Restoring checkpoint ./model/ring_6_68641..
218
Resizing so the max image size is 224..
2020-11-13 22:02:41.101218: W tensorflow/core/common_runtime/bfc_allocator.cc:211] Allocator (GPU_0_bfc) ran out of memory trying to allocate 530.16MiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
2020-11-13 22:02:41.101256: W tensorflow/core/common_runtime/bfc_allocator.cc:211] Allocator (GPU_0_bfc) ran out of memory trying to allocate 530.16MiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
2020-11-13 22:02:41.117759: W tensorflow/core/common_runtime/bfc_allocator.cc:211] Allocator (GPU_0_bfc) ran out of memory trying to allocate 536.34MiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
2020-11-13 22:02:41.117785: W tensorflow/core/common_runtime/bfc_allocator.cc:211] Allocator (GPU_0_bfc) ran out of memory trying to allocate 536.34MiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
2020-11-13 22:02:41.123718: W tensorflow/core/common_runtime/bfc_allocator.cc:211] Allocator (GPU_0_bfc) ran out of memory trying to allocate 1.06GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
2020-11-13 22:02:41.123733: W tensorflow/core/common_runtime/bfc_allocator.cc:211] Allocator (GPU_0_bfc) ran out of memory trying to allocate 1.06GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
2020-11-13 22:02:41.125294: W tensorflow/core/common_runtime/bfc_allocator.cc:211] Allocator (GPU_0_bfc) ran out of memory trying to allocate 274.25MiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
2020-11-13 22:02:41.125308: W tensorflow/core/common_runtime/bfc_allocator.cc:211] Allocator (GPU_0_bfc) ran out of memory trying to allocate 274.25MiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
2020-11-13 22:02:41.135688: W tensorflow/core/common_runtime/bfc_allocator.cc:211] Allocator (GPU_0_bfc) ran out of memory trying to allocate 545.31MiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
2020-11-13 22:02:41.135703: W tensorflow/core/common_runtime/bfc_allocator.cc:211] Allocator (GPU_0_bfc) ran out of memory trying to allocate 545.31MiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.

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.