oneThousand1000 / Portrait3D

(SIGGRAPH 2024) Portrait3D: Text-Guided High-Quality 3D Portrait Generation Using Pyramid Representation and GANs Prior
149 stars 10 forks source link

Portrait3D

This is the official code repository for our SIG'24 paper:

Portrait3D: Text-Guided High-Quality 3D Portrait Generation Using Pyramid Representation and GANs Prior

ACM Transactions on Graphics (Proceedings of SIGGRAPH 2024)

Yiqian Wu, Hao Xu, Xiangjun Tang, Xien Chen, Siyu Tang, Zhebin Zhang, Chen Li, Xiaogang Jin*

[![Project](https://img.shields.io/badge/Portrait3D-1?label=Project&color=8B93FF&logo=data:image/svg+xml;charset=utf-8;base64,PHN2ZyB0PSIxNzEyNDkwMTA3NzIxIiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjkgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjM4NzUiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIj48cGF0aCBkPSJNMTAwMS40MjMyMzggNDk0LjU5MnEyMS41MDQgMjAuNDggMjIuNTI4IDQ1LjA1NnQtMTYuMzg0IDQwLjk2cS0xOS40NTYgMTcuNDA4LTQ1LjA1NiAxNi4zODR0LTQwLjk2LTE0LjMzNnEtNS4xMi00LjA5Ni0zMS4yMzItMjguNjcydC02Mi40NjQtNTguODgtNzcuODI0LTczLjcyOC03OC4zMzYtNzQuMjQtNjMuNDg4LTYwLjQxNi0zMy43OTItMzEuNzQ0cS0zMi43NjgtMjkuNjk2LTY0LjUxMi0yOC42NzJ0LTYyLjQ2NCAyOC42NzJxLTEwLjI0IDkuMjE2LTM4LjQgMzUuMzI4dC02NS4wMjQgNjAuOTI4LTc3LjgyNCA3Mi43MDQtNzUuNzc2IDcwLjY1Ni01OS45MDQgNTUuODA4LTMwLjIwOCAyNy4xMzZxLTE1LjM2IDEyLjI4OC00MC45NiAxMy4zMTJ0LTQ0LjAzMi0xNS4zNnEtMjAuNDgtMTgu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AtaWQ9IjM4NzYiIGZpbGw9IiNmZmZmZmYiPjwvcGF0aD48L3N2Zz4=)](https://onethousandwu.com/portrait3d.github.io/) [![Paper](https://img.shields.io/badge/Paper%20(ACM%20Digital%20Library)-1?color=58A399&logo=data:image/svg+xml;charset=utf-8;base64,PHN2ZyB0PSIxNzEyNDkwMTQyMjM1IiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjU5MTQiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIj48cGF0aCBkPSJNODIzLjI5NiA2MC40MTZxNjUuNTM2IDAgOTkuMzI4IDM4LjR0MzMuNzkyIDkzLjY5NnY1NDMuNzQ0cTAgMjUuNi0yMS41MDQgNDYuMDhsLTE3MS4wMDggMTYzLjg0cS0xMy4zMTIgMTEuMjY0LTIyLjUyOCAxNC4zMzZ0LTIzLjU1MiAzLjA3MkgyNTguMDQ4cS0yMy41NTIgMC00Ny4xMDQtOS43Mjh0LTQxLjk4NC0yNy42NDgtMzAuMjA4LTQzLjAwOC0xMS43NzYtNTUuODA4di02MzQuODhxMC02MC40MTYgMzMuMjgtOTYuMjU2dDk0LjcyLTM1Ljg0aDU2OC4zMnogbS0yMTUuMDQgNjQyLjA0OHExMy4zMTIgMCAyMi41MjgtOS4yMTZUNjQwIDY3MC43MnEwLTE0LjMzNi05LjIxNi0yMy4wNHQtMjIuNTI4LTguNzA0SDI4Ny43NDRxLTEzLjMxMiAwLTIyLjUyOCA4LjcwNFQyNTYgNjcwLjcycTAgMTMuMzEyIDkuMjE2IDIyLjUyOHQyMi41MjggOS4yMTZoMzIwLjUxMnogbTEyOC0xOTIuNTEycTEzLjMxMiAwIDIyLjUyOC05LjIxNlQ3NjggNDc4LjIwOHQtOS4yMTYtMjIuNTI4LTIyLjUyOC05LjIxNkgyODcuNzQ0cS0xMy4zMTIgMC0yMi41MjggOS4yMTZUMjU2IDQ3OC4yMDh0OS4yMTYgMjIuNTI4IDIyLjUyOCA5LjIxNmg0NDguNTEyeiBtNjMuNDg4LTE5MS40ODhxMTMuMzEyIDAgMjIuNTI4LTkuMjE2dDkuMjE2LTIzLjU1MnEwLTEzLjMxMi05LjIxNi0yMi41Mjh0LTIyLjUyOC05LjIxNmgtNTEycS0xMy4zMTIgMC0yMi41MjggOS4yMTZUMjU2IDI4NS42OTZxMCAxNC4zMzYgOS4yMTYgMjMuNTUydDIyLjUyOCA5LjIxNmg1MTJ6IiBwLWlkPSI1OTE1IiBmaWxsPSIjZmZmZmZmIj48L3BhdGg+PC9zdmc+)](https://dl.acm.org/doi/10.1145/3658162) [![Arxiv](https://img.shields.io/badge/Arxiv-1?color=A34343&logo=Arxiv)](https://arxiv.org/abs/2404.10394) [![Suppl](https://img.shields.io/badge/Supplementary-1?color=378CE7&logo=data:image/svg+xml;charset=utf-8;base64,PHN2ZyB0PSIxNzEyNDkwMTgyMzc1IiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9Ijg5MDIiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIj48cGF0aCBkPSJNNDg2LjQgNDA5LjZIMjgyLjE4NTE0M2E0MS4zOTg4NTcgNDEuMzk4ODU3IDAgMCAwLTQxLjc2NDU3MiA0MC45NmMwIDIyLjY3NDI4NiAxOC43MjQ1NzEgNDAuOTYgNDEuNzY0NTcyIDQwLjk2aDk2LjMyOTE0M2EzNjIuNzg4NTcxIDM2Mi43ODg1NzEgMCAwIDAtOTYuMzI5MTQzIDI0NS43NmMwIDk0LjU3MzcxNCAzNi42NDQ1NzEgMTgwLjUxNjU3MSA5Ni4zMjkxNDMgMjQ1Ljc2SDE1Ni43NDUxNDNBODIuNzk3NzE0IDgyLjc5NzcxNCAwI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wLjM1NjMwNTkyLTEwLjM1NjMwNTkyIDEwLjM1NjMwNTkyLTE4LjEyMzUzNTkyODg4ODg4OFYyNjYuMDM3NzI4MTQyMjIyMjVjMC03Ljc2NzIzMDAwODg4ODg4OC01LjE3ODE1Mjk2LTE1LjUzNDQ1ODg3OTk5OTk5OS0xMi45NDUzODI5Njg4ODg4ODgtMTguMTIzNTM1OTI4ODg4ODg4eiIgZmlsbD0iI2ZmZmZmZiIgcC1pZD0iMTI5MTciPjwvcGF0aD48L3N2Zz4=)](https://youtu.be/z7xWiD1p1_4) [![Github](https://img.shields.io/github/stars/oneThousand1000/Portrait3D)](https://github.com/oneThousand1000/Portrait3D) [![dataset-on-hf](https://huggingface.co/datasets/huggingface/badges/raw/main/dataset-on-hf-sm.svg)](https://huggingface.co/datasets/onethousand/Portrait3D_gallery)

Representative_Image

Representative_Image

https://github.com/oneThousand1000/Portrait3D/assets/32099648/bc5721db-6edb-4d6a-a88f-07305476cd67

Requirements

  1. Tested on Python 3.8
  2. At least 12 GB of memory
  3. Tested on NVIDIA RTX 3080Ti with 12 GB of memory (Windows, 1.5h per portrait)
  4. Tested on NVIDIA RTX 4090 with 24 GB of memory (Linux, 0.5h per portrait)
  5. CUDA>=11.6

Installation

Clone this repo to $PROJECT_ROOT$.

Create environment

cd $PROJECT_ROOT$
conda env create -f environment.yaml
conda activate text_to_3dportrait

Torch and torchvision Installation

pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 -f https://download.pytorch.org/whl/torch_stable.html

OSMesa Dependencies (For Linux)

sudo apt install  libosmesa6  libosmesa6-dev

Installing Additional Requirements

pip install -r requirements.txt

kaolin Installation

pip install kaolin==0.13.0 -f https://nvidia-kaolin.s3.us-east-2.amazonaws.com/torch-1.12.1_cu116.html

Stable-diffusion Installation

cd stable-diffusion
pip install -e .
cd ..

SMPL Model Setup

  1. Download SMPL_python_v.1.0.0.zip (version 1.0.0 for Python 2.7 (female/male. 10 shape PCs) ). Save basicModel_f_lbs_10_207_0_v1.0.0.pkl to 3DPortraitGAN_pyramid/smplx_models/smpl/SMPL_FEMALE.pkl, save basicModel_m_lbs_10_207_0_v1.0.0.pkl to 3DPortraitGAN_pyramid/smplx_models/smpl/SMPL_MALE.pkl.

  2. Download SMPLIFY_CODE_V2.ZIP, and save basicModel_neutral_lbs_10_207_0_v1.0.0.pkl to 3DPortraitGAN_pyramid/smplx_models/smpl/SMPL_NEUTRAL.pkl.

Download Link Save Path
basicModel_f_lbs_10_207_0_v1.0.0.pkl 3DPortraitGAN_pyramid/smplx_models/smpl/SMPL_FEMALE.pkl
basicModel_m_lbs_10_207_0_v1.0.0.pkl 3DPortraitGAN_pyramid/smplx_models/smpl/SMPL_MALE.pkl
basicModel_neutral_lbs_10_207_0_v1.0.0.pkl 3DPortraitGAN_pyramid/smplx_models/smpl/SMPL_NEUTRAL.pkl

Inference

3DPortraitGAN_pyramid Model

Our 3DPortraitGAN_pyramid draws inspiration from the 3D-aware StyleGAN2 backbone implemented in SeanChenxy/Mimic3D, and integrates concepts of mask guidance, background synthesis, and tri-grid representation adapted from SizheAn/PanoHead. We extend our sincere gratitude for these significant contributions!

(Recommended) Pretrained models

Download the pre-trained model of 3DPortraitGAN_pyramid:

Download Link Description Save Path
model_512.pkl Pre-trained model of 3DPortraitGAN_pyramid ./3DPortraitGAN_pyramid/models
model_512.json Pose prediction parameters of 3DPortraitGAN_pyramid ./3DPortraitGAN_pyramid/models
decoder_512.ckpt Decoder checkpoint extracted from model_512.pkl ./3DPortraitGAN_pyramid/models
vgg16.pt vgg16 ./3DPortraitGAN_pyramid/models

(Optional) Training

Omit this section if utilizing the pre-trained 3DPortraitGAN_pyramid model aforementioned.

For those interested in the training process, we kindly direct you to our training instructions available here.

Random Image Generation

Preparing Prompts

First, prepare your prompts. These should be organized in the following structure:

test_data
│
└─── 001  
│   │
│   └─── prompt.txt (should initiate with "upper body photo")
└─── 002
│   │
│   └─── prompt.txt (should initiate with "upper body photo")
└─── ...

An example is available in $PROJECT_ROOT$/test_data.

Image generation

Download the Realistic_Vision_V5.1_noVAE model here.

Please download all the folders and the Realistic_Vision_V5.1.ckpt file.

We employ the original stable diffusion in this use case. To convert the diffusers-version model to the original-stable-diffusion-version, follow the steps below:

cd stable-diffusion

activate text_to_3dportrait

git clone git@github.com:huggingface/diffusers.git

cd diffusers/scripts

python convert_diffusers_to_original_stable_diffusion.py --model_path $PATH_of_Realistic_Vision_V5.1_noVAE$ --checkpoint_path $PATH_of_Realistic_Vision_V5.1_noVAE$/realisticVisionV51_v51VAE.ckpt

cd ../../../

Then randomly generate images:

cd stable-diffusion

activate text_to_3dportrait

python get_test_data_df.py --test_data_dir ../test_data --sample_num 6  --scale 5 --df_ckpt $PATH_of_Realistic_Vision_V5.1_noVAE$/realisticVisionV51_v51VAE.ckpt 

cd ..

The generated images will be stored at $PROJECT_ROOT$/test_data/image_id/samples

Note: We discovered that using a smaller scale (for example, --scale 3) tends to generate superior results for specific characters, like ''Tyrion Lannister in the Game of Thrones''. Feel free to experiment with different scales to improve the outcome.

Image Processing

Our image processing code is largely adapted from hongsukchoi/3DCrowdNet_RELEASE.

Installation

conda create -n portrait3d_data python=3.8

activate portrait3d_data

cd data_processing

pip install torch==1.10.2+cu113 torchvision==0.11.3+cu113 -f https://download.pytorch.org/whl/torch_stable.html

pip install -r requirements.txt

python -m pip install -e detectron2

cd ..

For windows:

pip install pywin32==306

For windows users who experience errors during detectron2 installation, please open a x64 Native Tools Command Prompt for Visual Studio and execute python -m pip install -e detectron2.

Pretrained models

Download Link Save Path
R_101_FPN_DL_soft_s1x.pkl ./data_processing/detectron2/projects/DensePose
phi_smpl_27554_256.pkl ./data_processing/detectron2/projects/DensePose
pose_higher_hrnet_w32_512.pth ./data_processing/HigherHRNet-Human-Pose-Estimation/models/pytorch/pose_coco
crowdhuman_yolov5m.pt ./data_processing/yolov5_crowdhuman
basicModel_neutral_lbs_10_207_0_v1.0.0.pkl ./data_processing/common/utils/smplpytorch/smplpytorch/native/models
VPOSER_CKPT ./data_processing/common/utils/human_model_files/smpl/VPOSER_CKPT
J_regressor_extra.npy ./data_processing/data
demo_checkpoint.pth.tar ./data_processing/demo

If you encounter RuntimeError: Subtraction, the - operator, with a bool tensor is not supported., you may refer to this issue for a solution or change L301~L304 of anaconda3/lib/python3.8/site-packages/torchgeometry/core/conversion.py to below:

mask_c0 = mask_d2.float() * mask_d0_d1.float()
mask_c1 = mask_d2.float() * (1 - mask_d0_d1.float())
mask_c2 = (1 - mask_d2.float()) * mask_d0_nd1.float()
mask_c3 = (1 - mask_d2.float()) * (1 - mask_d0_nd1.float())

Then process the randomly generated images to produce aligned images following the alignment setting of 3DPortraitGAN_pyramid:

cd data_processing

activate portrait3d_data
python preprocess_img_for_inversion.py --test_data_dir=$PROJECT_ROOT$/test_data

cd ..

Note: Manually review and discard any subpar images located in $PROJECT_ROOT$/test_data/image_id/samples_new_crop/aligned_images. For optimal inversion results, it is recommended to maintain an aligned image with a frontal view and minor body poses.

3D Portrait Inversion

Inversion

Before proceeding further, always ensure that you have removed all unsatisfactory images in test_data/image_id/samples_new_crop/aligned_images. This step is crucial to prevent suboptimal results.

Notice that we only run projection for the first image in test_data/image_id/samples_new_crop/aligned_images.

cd 3DPortraitGAN_pyramid

activate text_to_3dportrait

python run_inversion_with_pose_optimization.py \
    --model_pkl=./models/model_512.pkl \
    --pose_prediction_kwargs_path=./models/model_512.json \
    --test_data_dir=../test_data \
    --inversion_name=final_inversion \
    --with_pose_optim

Generate Pyramid Tri-grid from Inversion results

python run_trigrid_gen.py  \
    --network=./models/model_512.pkl \
    --inversion_name=final_inversion

cd ..

3D Portrait Generation and Optimization

Our image generation code is largely adapted from ashawkey/stable-dreamfusion. We express our gratitude for their significant contributions!

cd stable-dreamfusion-3DPortrait

python portrait3d_main.py \
    --trigrid_decoder_ckpt=../3DPortraitGAN_pyramid/models/decoder_512.ckpt \
    --inversion_name=final_inversion \
    --network_path=../3DPortraitGAN_pyramid/models/model_512.pkl \
    --test_data_dir=../test_data  \
    --df_ckpt=$PATH_of_Realistic_Vision_V5.1_noVAE$ 

The results will be stored and organized as:

stable-dreamfusion-3DPortrait/output/text_to_3dportrait/image_id
│
└─── trigrid.pkl [Original pyramid tri-grid generated from inversion results]
│
└─── validation [SDS validation images]
│
└─── checkpoints [SDS checkpoints]
│
└─── run [SDS run file]
│
└─── results [SDS rendering results]
|
└─── data [21 rendered views, refer to Section 3.5 in our paper]
|
└─── update_data [21 refined views, refer to Section 3.5 in our paper]
|
└─── log [Pyramid tri-grid optimization log files, refer to Section 3.5 in our paper]
│    │
│    └─── ckpt
│    │    │
│    │    └─── epoch_00019.pth [Final pyramid tri-grid]
│    └─── img 
│
└─── results_final [Final rendering results]

Results Gallery

We offer a gallery of 300 3D portraits (with their corresponding prompts) generated by our method, all viewable and accessible on huggingface.

Portrait3D_gallery
│
└─── 000  
│   │
│   └─── 000_pyramid_trigrid.pth [the pyramid trigrid file] 
│   │
│   └─── 000_prompt.txt [the prompt]
│   │
│   └─── 000_preview.png [the preview image]
│   │
│   └─── ...
└─── 001
│   │
│   └─── ...
└─── 002
│   │
│   └─── ...
│
└─── ...

To visualize these 3D portraits, use the following visualizer:

cd 3DPortraitGAN_pyramid

activate text_to_3dportrait

python pyramid_trigrid_visualizer.py

Input the path of your model_512.pkl into the Pickle field, and press enter (on your keyboard). Then input the pyramid tri-grid path into the Pyramid Tri-Grid Ckpt field, and then press enter (on your keyboard).

Please observe that we maintain the neural rendering resolution at 256 for optimal rendering speed.

https://github.com/oneThousand1000/Portrait3D/assets/32099648/ebc3fcc2-2f7c-400d-8f5e-c41e56d72a1e

Enjoy traversing through these results 😉!

Contact

onethousand@zju.edu.cn / onethousand1250@gmail.com

Citation

If you find this project helpful to your research, please consider citing:

@article{10.1145/3658162,
author = {Wu, Yiqian and Xu, Hao and Tang, Xiangjun and Chen, Xien and Tang, Siyu and Zhang, Zhebin and Li, Chen and Jin, Xiaogang},
title = {Portrait3D: Text-Guided High-Quality 3D Portrait Generation Using Pyramid Representation and GANs Prior},
year = {2024},
issue_date = {July 2024},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
volume = {43},
number = {4},
issn = {0730-0301},
url = {https://doi.org/10.1145/3658162},
doi = {10.1145/3658162},
journal = {ACM Trans. Graph.},
month = {jul},
articleno = {45},
numpages = {12},
keywords = {3D portrait generation, 3D-aware GANs, diffusion models}
}

Acknowledgements

The work is supported by the Information Technology Center and State Key Lab of CAD&CG, Zhejiang University. We extend our sincere gratitude for the generous provision of necessary computing resources.

We also want to express our thanks to those in the open-source community for their valuable contributions.