Giter VIP home page Giter VIP logo

cvpr23-e3dge's Introduction

E3DGE: Self-Supervised Geometry-Aware Encoder for Style-based 3D GAN Inversion

S-Lab, Nanyang Technological University1;   Shanghai Artificial Intelligence Laboratory 2 ; *corresponding author

E3DGE is an encoder-based 3D GAN inversion framework that yields high-quality shape and texture reconstruction.
Input Inversion Editing
(-Smile)
Editing
(+Smile)
Toonify

For more visual results, go checkout our project page 📃

Codes coming soon 👊

This repository contains the official implementation of E3DGE: Self-supervised Geometry-Aware Encoder for Style-based 3d GAN Inversion.


📣 Updates

[06/2023] Inference and training codes on FFHQ with StyleSDF base model are released, including colab demo.

[03/2023] E3DGE is accepted to CVPR 2023 🥳!

🐪 TODO

  • Release the inference and training code.
  • Release the colab demo.
  • Release Hugging face demo.
  • Release pre-traind models using EG3D as the base model.
  • Release video inversion code.

🤝 Citation

If you find our work useful for your research, please consider citing the paper:

@inproceedings{lan2022e3dge,
  title={E3DGE: Self-Supervised Geometry-Aware Encoder for Style-based 3D GAN Inversion},
  author={Lan, Yushi and Meng, Xuyi and Yang, Shuai and Loy, Chen Change and Dai, Bo},
  booktitle={Computer Vision and Pattern Recognition (CVPR)},
  year={2023}
}

🖥️ Requirements

NVIDIA GPUs are required for this project. We have test the inference codes on NVIDIA T4 and NVIDIA V100. The training codes have been tested on NVIDIA V100 (32GB). We recommend using anaconda to manage the python environments.

conda create --name e3dge python=3.8
conda activate e3dge
conda install -c conda-forge ffmpeg
conda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 cudatoolkit=10.2 -c pytorch
conda install -c fvcore -c iopath -c conda-forge fvcore iopath
pip install -r requirements.txt

🏃‍♀️ Inference

Download Models

The pretrain 3D generators and encoders are needed for inference.

The following scripts download pretrain models and test dataset.

python download_models.py # download pre-trained models
python download_test_data.py # download preprocessed CelebA-HQ test set

Commands

Note that to render the mesh, 15GB GPU memory is required.

do novel view synthesis given 2D images (on some demo images):

bash scripts/test/demo_view_synthesis.sh

Conduct semantics editing (on some demo images):

bash scripts/test/demo_editing.sh

3D Toonifications with our pre-triaind encoder:

bash scripts/test/demo_toonify.sh

Reproduce the results in Table 1 (Quantitative performance on CelebA-HQ.)

bash scripts/test/eval_2dmetrics_ffhq.sh

More explaination of the inference scripts are included in scripts/test/RUN.md.

🚋 Training

For all the experiments, we use 4 V100 GPUs by default.

FFHQ

Download Pre-trained generators and pre-processed test set

python download_models.py # download pre-trained models
python download_datasets.py # download preprocessed CelebA-HQ test set

Commands

stage 1 training (Sec. 1, Self-supervision for plausible shape inversion.)

bash scripts/train/ffhq/stage1.sh

stage 2.1 training (Sec. 2+3, Local feature fusion for high-fidelity inversion. Using 2D alignment only)

bash scripts/train/ffhq/stage2.1.sh

stage 2.2 training (Sec. 3, Hybrid feature alignment for high-quality editing)

# update the ffhq/afhq dataset path in the bash if adv_lambda != 0 (enables adversarial training)
bash scripts/train/ffhq/stage2.2.sh

Intermediate test results will be saved under ${checkpoints_dir} every 2000 iterations, and the train results will be saved every 100 iterations. For the training results, from the left to right is the (synthetic) ground truth images, E0 reconstruction (64x64 resolution), residual, aligned residual and the E1 reconstructionss (both thumb image and SR image). For the test results, the first line is the real images ground truth images and the second line is the texture inversion results.

To inference the trained models, please refer to the Inference section.

Support for more datasets coming soon...

🛠️ Misc helper scripts

Script to generate the demo video

I have uploaded the python script to export the demo video here gallary_video.py. You can modify the video paths and use it in your own project.

Script to evaluate inversion results

Though our test_ae.py automatically calculates the inversion metrics, you can also simply run this script calc_losses_on_images.py and modify the --data_path and --gt_path argument to calculate the inversion performance of your results.

🙌 Acknowledgements

This study is supported under the RIE2020 Industry Alignment Fund Industry Collaboration Projects (IAF-ICP) Funding Initiative, as well as cash and in-kind contribution from the industry partner(s). It is also partially supported by Singapore MOE AcRF Tier 2 (MOE-T2EP20221-0011) and the NTU URECA research program.

This project is built on source codes shared by StyleSDF.

🗞️ License

Distributed under the S-Lab License. See LICENSE for more information.

Contact

If you have any question, please feel free to contact us via [email protected].

cvpr23-e3dge's People

Contributors

nirvanalan 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

cvpr23-e3dge's Issues

An issue about `--not_apply_que_weight` in `demo_editing.sh`

Thanks for sharing the code! Not sure if this has been raised before, but there was an issue I found when I ran bash scripts/test/demo_editing.sh. It is about the argument --not_apply_que_weight. I ended up with commenting it out and the script worked.

how to inverse test images to 3D mesh except for the demo images

hello,i tried to run the demo_view_synrthesis.sh with different images(not on the demo images),and the results were not satisfactory. And it seems that all the generated mesh are the same one. How can I inverse other images and get new mesh using other images?

pretrain models can not be downloaded

Downloading FFHQ pretrained volume renderer
0% 0.00/63.7M [00:00<?, ?B/s]downloading pretrained_renderer/ffhq_vol_renderer.pt...
100% 63.7M/63.7M [00:00<00:00, 119MB/s]
Downloading FFHQ full model (1024x1024)
0% 0.00/203M [00:00<?, ?B/s]downloading full_models/ffhq1024x1024.pt...
100% 203M/203M [00:01<00:00, 159MB/s]
Downloading E3DGE model pretrained on FFHQ.
Downloading E3DGE Toonifiy encoder & generator pretrained on FFHQ.
0% 0.00/203M [00:00<?, ?B/s]downloading full_models/Toonify400_1024x1024.pt...
0% 0.00/203M [00:00<?, ?B/s]Google Drive download failed.
Trying do download from alternate server

0% 0.00/1.17G [00:00<?, ?B/s]downloading pretrained_models/Toonify/no_local_basic_trainer.pt.pt...

0% 0.00/1.17G [00:00<?, ?B/s]
0% 0.00/1.17G [00:00<?, ?B/s]
0% 0.00/1.17G [00:00<?, ?B/s]
0% 0.00/1.17G [00:00<?, ?B/s]
0% 0.00/1.17G [00:00<?, ?B/s]
0% 0.00/1.17G [00:00<?, ?B/s]
0% 0.00/1.17G [00:00<?, ?B/s]
0% 0.00/1.17G [00:00<?, ?B/s]
0% 0.00/1.17G [00:00<?, ?B/s]
0% 0.00/1.17G [00:00<?, ?B/s]Traceback (most recent call last):
File "/content/3dsdf_projection/download_models.py", line 77, in download_pretrained_models
download_file(session, E3DGE_toonify_generator)
File "/content/3dsdf_projection/download_models.py", line 115, in download_file
res.raise_for_status()
File "/usr/local/lib/python3.10/dist-packages/requests/models.py", line 960, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: https://doc-14-3g-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/mon9hsp9mgn56soirv0dkth0m71uj0s7/1689578850000/11845616351297524119/*/1CIibwVOXRIC-UiNsO2IgyTTQ0SmKvh3m?uuid=3b199a3f-22b7-48bb-a2a4-96d0825c1e4b

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/content/3dsdf_projection/download_models.py", line 158, in
download_pretrained_models()
File "/content/3dsdf_projection/download_models.py", line 82, in download_pretrained_models
download_file(session, E3DGE_toonify_encoder, use_alt_url=True)
File "/content/3dsdf_projection/download_models.py", line 114, in download_file
with session.get(file_url, stream=True) as res:
File "/usr/local/lib/python3.10/dist-packages/requests/sessions.py", line 542, in get
return self.request('GET', url, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/requests/sessions.py", line 515, in request
prep = self.prepare_request(req)
File "/usr/local/lib/python3.10/dist-packages/requests/sessions.py", line 443, in prepare_request
p.prepare(
File "/usr/local/lib/python3.10/dist-packages/requests/models.py", line 318, in prepare
self.prepare_url(url, params)
File "/usr/local/lib/python3.10/dist-packages/requests/models.py", line 392, in prepare_url
raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL '': No scheme supplied. Perhaps you meant http://?
0% 0.00/203M [00:00<?, ?B/s]
0% 0.00/1.17G [00:00<?, ?B/s]

about file download

Hello, There is no file download sentence about "pretrained_renderer/ffhq1024x1024_vol_renderer.pt" in file "download_models.py," is this file downlaod from other way or something I deal with is wrong? Thanks your answer
{9EABBF94-9F95-4ee0-962C-409240101B70}
.

Training details

Hello, thanks for your awesome work.

I'm a little bit confused about the training details.

  1. Train/test set on 2D reconstruction
    Is StyleSDF pre-trained on Celeb-HQ or FFHQ?

  2. Train about Encoders E0 and E1.
    (a) training requires two encoders separately
    (b) train two encoders jointly and, at some phase, freeze the weight of network E0

Could you kindly specify which one is correct between (a) and (b)

Many thanks!

Broken pipe when using ffmpeg

hi, thank you for your great job!
I encountered an issue while running the inference code and I'm unable to resolve it. Can you suggest what could be causing the problem?
image

the env is below (cuda11.3):

_libgcc_mutex             0.1                        main    defaults
_openmp_mutex             5.1                       1_gnu    defaults
addict                    2.4.0                    pypi_0    pypi
antlr4-python3-runtime    4.9.3                    pypi_0    pypi
appdirs                   1.4.4                    pypi_0    pypi
asttokens                 2.2.1                    pypi_0    pypi
attrs                     23.1.0                   pypi_0    pypi
backcall                  0.2.0                    pypi_0    pypi
blas                      1.0                         mkl    defaults
brotlipy                  0.7.0           py39h27cfd23_1003    defaults
bzip2                     1.0.8                h7b6447c_0    defaults
ca-certificates           2023.7.22            hbcca054_0    conda-forge
certifi                   2023.7.22          pyhd8ed1ab_0    conda-forge
cffi                      1.15.1           py39h5eee18b_3    defaults
chardet                   5.2.0                    pypi_0    pypi
charset-normalizer        2.0.4              pyhd3eb1b0_0    defaults
click                     8.1.6                    pypi_0    pypi
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
colorlog                  6.7.0                    pypi_0    pypi
configargparse            1.7                      pypi_0    pypi
contourpy                 1.1.0                    pypi_0    pypi
cryptography              41.0.2           py39h22a60cf_0    defaults
cudatoolkit               11.3.1               h2bc3f7f_2    defaults
cycler                    0.11.0                   pypi_0    pypi
decorator                 5.1.1                    pypi_0    pypi
docker-pycreds            0.4.0                    pypi_0    pypi
executing                 1.2.0                    pypi_0    pypi
facexlib                  0.3.0                    pypi_0    pypi
ffmpeg                    4.3                  hf484d3e_0    pytorch
filterpy                  1.4.5                    pypi_0    pypi
fonttools                 4.42.0                   pypi_0    pypi
freetype                  2.12.1               h4a9f257_0    defaults
fvcore                    0.1.5.post20221221    pyhd8ed1ab_0    conda-forge
giflib                    5.2.1                h5eee18b_3    defaults
gitdb                     4.0.10                   pypi_0    pypi
gitpython                 3.1.32                   pypi_0    pypi
gmp                       6.2.1                h295c915_3    defaults
gnutls                    3.6.15               he1e5248_0    defaults
idna                      3.4              py39h06a4308_0    defaults
imageio                   2.31.1                   pypi_0    pypi
importlib-metadata        6.8.0                    pypi_0    pypi
importlib-resources       6.0.1                    pypi_0    pypi
intel-openmp              2023.1.0         hdb19cb5_46305    defaults
iopath                    0.1.9                      py39    iopath
ipdb                      0.13.13                  pypi_0    pypi
ipython                   8.14.0                   pypi_0    pypi
jedi                      0.19.0                   pypi_0    pypi
jpeg                      9e                   h5eee18b_1    defaults
jsonschema                4.19.0                   pypi_0    pypi
jsonschema-specifications 2023.7.1                 pypi_0    pypi
kiwisolver                1.4.4                    pypi_0    pypi
kornia                    0.7.0                    pypi_0    pypi
lame                      3.100                h7b6447c_0    defaults
lazy-loader               0.3                      pypi_0    pypi
lcms2                     2.12                 h3be6417_0    defaults
ld_impl_linux-64          2.38                 h1181459_1    defaults
lerc                      3.0                  h295c915_0    defaults
libdeflate                1.17                 h5eee18b_0    defaults
libffi                    3.4.4                h6a678d5_0    defaults
libgcc-ng                 11.2.0               h1234567_1    defaults
libgomp                   11.2.0               h1234567_1    defaults
libiconv                  1.16                 h7f8727e_2    defaults
libidn2                   2.3.4                h5eee18b_0    defaults
libpng                    1.6.39               h5eee18b_0    defaults
libstdcxx-ng              11.2.0               h1234567_1    defaults
libtasn1                  4.19.0               h5eee18b_0    defaults
libtiff                   4.5.0                h6a678d5_2    defaults
libunistring              0.9.10               h27cfd23_0    defaults
libwebp                   1.2.4                h11a3e52_1    defaults
libwebp-base              1.2.4                h5eee18b_1    defaults
littleutils               0.2.2                    pypi_0    pypi
llvmlite                  0.40.1                   pypi_0    pypi
lmdb                      1.4.1                    pypi_0    pypi
lxml                      4.9.3                    pypi_0    pypi
lz4-c                     1.9.4                h6a678d5_0    defaults
mapbox-earcut             1.0.1                    pypi_0    pypi
matplotlib                3.7.2                    pypi_0    pypi
matplotlib-inline         0.1.6                    pypi_0    pypi
mkl                       2023.1.0         h6d00ec8_46342    defaults
mkl-service               2.4.0            py39h5eee18b_1    defaults
mkl_fft                   1.3.6            py39h417a72b_1    defaults
mkl_random                1.2.2            py39h417a72b_1    defaults
mmcv                      1.7.0                    pypi_0    pypi
mpmath                    1.3.0                    pypi_0    pypi
munch                     4.0.0                    pypi_0    pypi
ncurses                   6.4                  h6a678d5_0    defaults
nettle                    3.7.3                hbbd107a_1    defaults
networkx                  3.1                      pypi_0    pypi
numba                     0.57.1                   pypi_0    pypi
numpy                     1.24.4                   pypi_0    pypi
omegaconf                 2.3.0                    pypi_0    pypi
opencv-python             4.8.0.74                 pypi_0    pypi
openh264                  2.1.1                h4ff587b_0    defaults
openssl                   3.0.10               h7f8727e_0    defaults
packaging                 23.1                     pypi_0    pypi
parso                     0.8.3                    pypi_0    pypi
pathtools                 0.1.2                    pypi_0    pypi
pexpect                   4.8.0                    pypi_0    pypi
pickleshare               0.7.5                    pypi_0    pypi
pillow                    9.4.0            py39h6a678d5_0    defaults
pip                       23.2.1           py39h06a4308_0    defaults
platformdirs              3.10.0                   pypi_0    pypi
portalocker               2.7.0            py39hf3d152e_0    conda-forge
prompt-toolkit            3.0.39                   pypi_0    pypi
protobuf                  4.23.4                   pypi_0    pypi
psutil                    5.9.5                    pypi_0    pypi
ptyprocess                0.7.0                    pypi_0    pypi
pure-eval                 0.2.2                    pypi_0    pypi
pycollada                 0.7.2                    pypi_0    pypi
pycparser                 2.21               pyhd3eb1b0_0    defaults
pygments                  2.16.1                   pypi_0    pypi
pyopenssl                 23.2.0           py39h06a4308_0    defaults
pyparsing                 3.0.9                    pypi_0    pypi
pysocks                   1.7.1            py39h06a4308_0    defaults
python                    3.9.17               h955ad1f_0    defaults
python-dateutil           2.8.2                    pypi_0    pypi
python_abi                3.9                      2_cp39    conda-forge
pytorch                   1.12.0          py3.9_cuda11.3_cudnn8.3.2_0    pytorch
pytorch-mutex             1.0                        cuda    pytorch
pytorch3d                 0.7.4           py39_cu113_pyt1120    pytorch3d
pywavelets                1.4.1                    pypi_0    pypi
pyyaml                    6.0              py39hb9d737c_4    conda-forge
readline                  8.2                  h5eee18b_0    defaults
referencing               0.30.2                   pypi_0    pypi
requests                  2.31.0           py39h06a4308_0    defaults
rpds-py                   0.9.2                    pypi_0    pypi
rtree                     1.0.1                    pypi_0    pypi
scikit-image              0.21.0                   pypi_0    pypi
scikit-video              1.1.11                   pypi_0    pypi
scipy                     1.11.1                   pypi_0    pypi
sentry-sdk                1.29.2                   pypi_0    pypi
setproctitle              1.3.2                    pypi_0    pypi
setuptools                68.0.0           py39h06a4308_0    defaults
shapely                   2.0.1                    pypi_0    pypi
six                       1.16.0                   pypi_0    pypi
smmap                     5.0.0                    pypi_0    pypi
sorcery                   0.2.2                    pypi_0    pypi
sqlite                    3.41.2               h5eee18b_0    defaults
stack-data                0.6.2                    pypi_0    pypi
svg-path                  6.3                      pypi_0    pypi
sympy                     1.12                     pypi_0    pypi
tabulate                  0.9.0              pyhd8ed1ab_1    conda-forge
tbb                       2021.8.0             hdb19cb5_0    defaults
termcolor                 2.3.0              pyhd8ed1ab_0    conda-forge
tifffile                  2023.7.18                pypi_0    pypi
tk                        8.6.12               h1ccaba5_0    defaults
tomli                     2.0.1                    pypi_0    pypi
torchaudio                0.12.0               py39_cu113    pytorch
torchvision               0.13.0               py39_cu113    pytorch
tqdm                      4.65.0             pyhd8ed1ab_1    conda-forge
traitlets                 5.9.0                    pypi_0    pypi
trimesh                   3.21.7                   pypi_0    pypi
typing_extensions         4.7.1            py39h06a4308_0    defaults
tzdata                    2023c                h04d1e81_0    defaults
urllib3                   1.26.16          py39h06a4308_0    defaults
wandb                     0.15.8                   pypi_0    pypi
wcwidth                   0.2.6                    pypi_0    pypi
wheel                     0.38.4           py39h06a4308_0    defaults
wrapt                     1.15.0                   pypi_0    pypi
xxhash                    3.3.0                    pypi_0    pypi
xz                        5.4.2                h5eee18b_0    defaults
yacs                      0.1.8              pyhd8ed1ab_0    conda-forge
yaml                      0.2.5                h7f98852_2    conda-forge
yapf                      0.40.1                   pypi_0    pypi
zipp                      3.16.2                   pypi_0    pypi
zlib                      1.2.13               h5eee18b_0    defaults
zstd                      1.5.5                hc292b87_0    defaults

Thank you!

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.