Coder Social home page Coder Social logo

xchenz / havatar Goto Github PK

View Code? Open in Web Editor NEW
118.0 11.0 9.0 74.96 MB

[TOG 2023] HAvatar: High-fidelity Head Avatar via Facial Model ConditionedNeural Radiance Field

Home Page: https://www.liuyebin.com/havatar/

License: Other

Python 97.22% C++ 0.42% Cuda 2.36%
nerf-avatar

havatar's Introduction

HAvatar: High-fidelity Head Avatar via Facial Model ConditionedNeural Radiance Field

Teaser image

HAvatar: High-fidelity Head Avatar via Facial Model ConditionedNeural Radiance Field
Xiaochen Zhao, Lizhen Wang, Jingxiang Sun, Hongwen Zhang, Jinli Suo, Yebin Liu

Project | Paper

Abstract: The problem of modeling an animatable 3D human head avatar under light-weight setups is of significant importance but has not been well solved. Existing 3D representations either perform well in the realism of portrait images synthesis or the accuracy of expression control, but not both. To address the problem, we introduce a novel hybrid explicit-implicit 3D representation, Facial Model Conditioned Neural Radiance Field, which integrates the expressiveness of NeRF and the prior information from the parametric template. At the core of our representation, a synthetic-renderings-based condition method is proposed to fuse the prior information from the parametric model into the implicit field without constraining its topological flexibility. Besides, based on the hybrid representation, we properly overcome the inconsistent shape issue presented in existing methods and improve the animation stability. Moreover, by adopting an overall GAN-based architecture using an image-to-image translation network, we achieve high-resolution, realistic and view-consistent synthesis of dynamic head appearance. Experiments demonstrate that our method can achieve state-of-the-art performance for 3D head avatar animation compared with previous methods.

Train Avatar

Compile ops

cd model/op
python setup.py install

Prepare Dataset

We provide a processed demo dataset. Please download and unzip it into data/demo.

We also provide preprocessing code in data_preprocessing. If you want to generate dataset from the video, please download faceverse file (data_preprocessing/metamodel/v3/faceverse_v3_1.npy) and RVM pretrained models (data_preprocessing/BgMatting_models/rvm_resnet50_fp32.torchscript).

cd data_preprocessing
python fit_video.py --video_path path/to/your/video --base_dir data/avatar

Training

# Stage one

python train_avatar.py --datadir data/demo --logdir logs/demo

After convergence (we train about 20000 steps in this case, you can check the loss with tensorboard), continue with the second training stage. To accelerate the convergence, we provide a pretrained image translation module. Please download an put it into pretrained_models.

# Stage two

python train_avatarHD.py --datadir data/demo --logdir logs/demo/HD --ckpt logs/demo/checkpoint200000.ckpt

Animate Avatar

We provide a pretrained monocular head avatar checkpoint, please download and put it into logs/demo/HD.

Self-Reenactment

python avatarHD_reenactment.py --torch_test --savedir results/demo/self-recon --ckpt logs/demo/HD/latest.pt --split data/demo/sv_v31_all.json

Cross-Reenactment

# preprocess dataset

cd data_preprocessing
python fit_video.py --video_path path/to/your/actor_video --base_dir data/actor --avatar_tracking_dir data/demo
python avatarHD_reenactment.py --savedir results/demo/cross-reenact --ckpt logs/demo/HD/latest.pt --split data/actor/drive_demo.json

Citation

@article{zhao2023havatar,
  author = {Zhao, Xiaochen and Wang, Lizhen and Sun, Jingxiang and Zhang, Hongwen and Suo, Jinli and Liu, Yebin},
  title = {HAvatar: High-Fidelity Head Avatar via Facial Model Conditioned Neural Radiance Field},
  year = {2023},
  publisher = {Association for Computing Machinery},
  address = {New York, NY, USA},
  issn = {0730-0301},
  url = {https://doi.org/10.1145/3626316},
  doi = {10.1145/3626316},
  note = {Just Accepted},
  journal = {ACM Trans. Graph.},
  month = {oct},
  keywords = {parametric facial model, image-to-image translation, image synthesis, head avatar, neural radiance field}
}

Acknowledgements

Part of the code is borrowed from Nerface and StyleAvatar.

havatar's People

Contributors

xchenz 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

havatar's Issues

Training speed

What would I expect the average time training a model to take using this project?
I know it's dependent on GPU etc but would like an idea regardless

By the way your team is doing great work I'm looking forward to any possible Gaussian head projects you might have upcoming.

how about the gpu requirement?

I meet the cuda out of memeory issue. torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 54.00 MiB. GPU 0 has a total capacity of 23.50 GiB of which 35.69 MiB is free. Process 210694 has 22.70 GiB memory in use. Including non-PyTorch memory, this process has 768.00 MiB memory in use. Of the allocated memory 509.71 MiB is allocated by PyTorch, and 34.29 MiB is reserved by PyTorch but unallocated.

Is this reasonable?

Could be a compilation problem with the fused_bias_act?

(havatar) ubuntu:~/havatar$ python train_avatar.py --datadir data/demo --logdir logs/demo
Credentials not found on disk. Authenticate with:

from fused import NotebookCredentials
credentials = NotebookCredentials()

Setting up [LPIPS] perceptual loss: trunk [alex], v[0.1], spatial [off]
/home/ubuntu/miniconda3/envs/lhm-havatar/lib/python3.8/site-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.
warnings.warn(
/home/ubuntu/miniconda3/envs/lhm-havatar/lib/python3.8/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or None for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing weights=AlexNet_Weights.IMAGENET1K_V1. You can also use weights=AlexNet_Weights.DEFAULT to get the most up-to-date weights.
warnings.warn(msg)
Loading model from: /home/lhm/.local/lib/python3.8/site-packages/lpips/weights/v0.1/alex.pth
Setting up [LPIPS] perceptual loss: trunk [vgg], v[0.1], spatial [off]
/home/ubuntu/miniconda3/envs/lhm-havatar/lib/python3.8/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or None for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing weights=VGG16_Weights.IMAGENET1K_V1. You can also use weights=VGG16_Weights.DEFAULT to get the most up-to-date weights.
warnings.warn(msg)
Loading model from: /home/lhm/.local/lib/python3.8/site-packages/lpips/weights/v0.1/vgg.pth
/home/ubuntu/miniconda3/envs/lhm-havatar/lib/python3.8/site-packages/torch/functional.py:504: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3526.)
return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
StyleGAN conditon img!
StyleGAN conditon img!
0.01730502024292946: 100%|█████████████████████████████████████████████████████████████████████████████████████| 3000/3000 [00:19<00:00, 150.07it/s]
Saved mesh as debug/vis_motionWeightVol.obj
Traceback (most recent call last):
File "train_avatar.py", line 324, in
main()
File "train_avatar.py", line 121, in main
rgb_coarse, _, acc_coarse, weights, rgb_fine, _, acc_fine, latent_code_loss = trainer(**inp_data)
File "/home/ubuntu/miniconda3/envs/lhm-havatar/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/home/ubuntu/miniconda3/envs/lhm-havatar/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/home/lhm/havatar/model/nerf_trainer.py", line 104, in forward
rgb_coarse, _, acc_coarse, weights, rgb_fine, _, acc_fine = self.nerf_forward(ray_batch=ray_batch, background_prior=background_prior,
File "/home/lhm/havatar/model/nerf_trainer.py", line 41, in nerf_forward
self.model_coarse.set_conditional_embedding(front_render_cond=inputs['front_render_cond'], left_render_cond=inputs['left_render_cond'],
File "/home/lhm/havatar/model/nerf_model.py", line 82, in set_conditional_embedding
conditonXYplane_embedding, _ = self.XY_gen(inp_latents, front_render_cond)
File "/home/ubuntu/miniconda3/envs/lhm-havatar/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/home/ubuntu/miniconda3/envs/lhm-havatar/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/home/lhm/havatar/model/styleUnet.py", line 798, in forward
styles = [self.style(s) for s in styles]
File "/home/lhm/havatar/model/styleUnet.py", line 798, in
styles = [self.style(s) for s in styles]
File "/home/ubuntu/miniconda3/envs/lhm-havatar/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/home/ubuntu/miniconda3/envs/lhm-havatar/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/home/ubuntu/miniconda3/envs/lhm-havatar/lib/python3.8/site-packages/torch/nn/modules/container.py", line 215, in forward
input = module(input)
File "/home/ubuntu/miniconda3/envs/lhm-havatar/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/home/ubuntu/miniconda3/envs/lhm-havatar/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/home/lhm/havatar/model/styleUnet.py", line 150, in forward
out = fused_leaky_relu(out, self.bias * self.lr_mul)
File "/home/lhm/havatar/model/op/fused_act.py", line 122, in fused_leaky_relu
return FusedLeakyReLUFunction.apply(input.contiguous(), bias, negative_slope, scale)
File "/home/ubuntu/miniconda3/envs/lhm-havatar/lib/python3.8/site-packages/torch/autograd/function.py", line 539, in apply
return super().apply(*args, **kwargs) # type: ignore[misc]
File "/home/lhm/havatar/model/op/fused_act.py", line 69, in forward
out = fused.fused_bias_act(input, bias, empty, 3, 0, negative_slope, scale)
AttributeError: module 'fused' has no attribute 'fused_bias_act'

I use CUDA 12.3, torch 2.1.0+cu121. How can I solve this problem?
Looking forward to your reply!

License

Any plans to add a license to the repo?

ModuleNotFoundError: No module named 'utils'

Traceback (most recent call last):
File "/home/codes/havatar/avatarHD_reenactment.py", line 6, in
from model.nerf_trainer import Trainer as nerf_trainer
File "/home/codes/havatar/model/nerf_trainer.py", line 3, in
from model import nerf_model
File "/home/codes/havatar/model/nerf_model.py", line 3, in
from utils.sh_util import eval_sh
ModuleNotFoundError: No module named 'utils'

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.