Installation

July 31, 2023 ยท View on GitHub

The provided code is in PyTorch with support of DistributedDataParallel. This repository requires Nvdiffrast and CUDA for differentiable rendering.

  1. For installation and more information about Nvdiffrast, you may refer to their document. We recommend using with Docker as in their tutorial, and we also provide script for launching with docker.

  2. To install Docker, visit
    https://www.docker.com/get-started

  3. To clone this repository and Nvdiffrast repositor, run

git clone https://github.com/facebookresearch/multiface
git clone https://github.com/NVlabs/nvdiffrast
  1. To build docker image with nvdiffrast and the required python packages in this repository, one can modify the Dockerfile in nvdiffrast or simply swap in our provided Dockerfile
mv nvdiffrast/docker/Dockerfile nvdiffrast/docker/Dockerfile.original
cp multiface/Dockerfile nvdiffrast/docker/Dockerfile
cd nvdiffrast
chmod +x run_sample.sh
./run_sample.sh --build-container
cd ..

Alternatively, one can install in local environment if all the CUDA dependencies are taken care of using

cd nvdiffrast 
pip install .

However, we did NOT test instllation on this method, thus would strongly recommend using option 4.1.

  1. To download the mini-dataset (for sanity check), run
pip3 install -r requirements.txt
python3 download_dataset.py --dest "/path/to/mini_dataset/" --download_config "./mini_download_config.json"```

This will download 2 expressions (images, textures and mesh) from enity 6795937 under directory /path/to/mini_dataset/.
In the last part of installation, we will instruct how to donwload the entire dataset (400TB).

6. You can run the training script in docker using command:

docker run --rm -it --gpus all --user $(id -u):$(id -g) -v `pwd`:/app -v /path/to/mini_dataset/:/dataset --workdir /app --shm-size 256g TORCH_EXTENSIONS_DIR=/app/tmp gltorch:latest python -m torch.distributed.launch --nproc_per_node=1 train.py --data_dir /path/to/mini_dataset/m--20180227--0000--6795937--GHS --krt_dir /path/to/mini_dataset/m--20180227--0000--6795937--GHS/KRT --framelist_train /path/to/mini_dataset/m--20180227--0000--6795937--GHS/frame_list.txt --framelist_test /path/to/mini_dataset/m--20180227--0000--6795937--GHS/frame_list.txt --test_segment "./mini_test_segment.json --lambda_screen 1"

Assuming you have downloaded and put the dataset on your local directory /path/to/mini_dataset. Running the above command sets the shm memory size to 256GB, and uses 1 gpus as specified by nproc_per_node argument. It will launch training on the identity m--20180227--0000--6795937--GHS (6795937).

If you have installed Nvdiffrast to your system you can simply launch the training script by:

python -m torch.distributed.launch --nproc_per_node=1 train.py --data_dir /path/to/mini_dataset/m--20180227--0000--6795937--GHS --krt_dir /path/to/mini_dataset/m--20180227--0000--6795937--GHS/KRT --framelist_train /path/to/mini_dataset/m--20180227--0000--6795937--GHS/frame_list.txt --framelist_test "./mini_frame_list.txt"  --result_path "./mini_dataset" --test_segment "./mini_test_segment.json" --lambda_screen 1 --model_path "./mini_dataset/best_model.pth"

And the testing script by:

python -m torch.distributed.launch --nproc_per_node=1 test.py --data_dir /path/to/mini_dataset/m--20180227--0000--6795937--GHS --krt_dir /path/to/mini_dataset/m--20180227--0000--6795937--GHS/KRT --framelist_test /path/to/mini_dataset/m--20180227--0000--6795937--GHS/frame_list.txt --test_segment "./mini_test_segment.json"

We provide the pretrained model pretrained model on this minidataset. You can check your training result by comparing training and testing loss using split of mini_test_segment.json:

Training Loss (screen/ mesh / tex)Testing Loss (screen / mesh / tex)
0.268333 / 0.769636 / 0.6541520.154118 / 0.758897 / 0.379572

  1. To donwload the ENTIRE dataset (13 entities), you will need ~120 TB during downloading and ~65TB for storage in total. Size of images, mesh and textures of each entity is provided:
Entity IDName of Root FolderImages (TB)Mesh (GB)Textures (GB)
002645310m--20190828--1318--002645310--GHS7.8452400
002643814m--20180426--0000--002643814--GHS1.621412
002539136m--20180105--0000--002539136--GHS1.520381
7889059m--20180927--0000--7889059--GHS1.829493
002757580m--20171024--0000--002757580--GHS1.421380
2183941m--20180418--0000--2183941--GHS2.132577
5372021m--20180510--0000--5372021--GHS2.027513
8870559m--20180406--0000--8870559--GHS2.432611
6674443m--20180226--0000--6674443--GHS1.726429
5067077m--20190529--1004--5067077--GHS11493100
002914589m--20181017--0000--002914589--GHS1.121367
6795937m--20180227--0000--6795937--GHS1.927521
002421669m--20190529--1300--002421669--GHS13513100
Total-49.340113284

Run python3 download_dataset.py --dest "path/to/dataset" --download_config "./download_config.json"

You may refer to DATA_STRUCTURE.md to check the completness of data for each entity under its root folder.

You may select the directory of data to be downloaded by specifying --dest. To make the download flexiable, you may use download_config.json (specify by --download_config) to select the data to be downloaded with the following variables:

VariableTypeDefault
entitylist of stringall the entity will be downloaded
imagebooleanraw images of enities selected will be downloaded
meshbooleantracked mesh of enities selected will be downloaded
texturebooleanunwrapped texture of enities selected will be downloaded
metadatabooleanmetadata of enities selected will be downloaded
audiobooleanaudio of enities selected will be downloaded
expressionlist of stringall the facial expression (contains both v1 and v2 scripts) will be downloaded

Notice that

  • audio is NOT a necessity to train a deep appearance model.

  • download the entire dataset is time- and space-consumming, we STRONGLY recommend users to download the mini-dataset (specifying --download_config "./path/to/mini_download_config.json") to check the flow works property first.

  • entities are downloaded one-by-one, which means that all the .tar files will be deleted after files are unzipped.


  1. We provide pretrained models (base, res, warp, non, bilinear) for each identity. The model is a simple VAE model that reconstruct mesh and view-specific texture. It is trained using ground-truth mesh and texture only. For entities 002643814, 7889059, 2183941, 5372021, 8870559, 6674443, 002914589, 6795937 (V1), we use expression EXP_ROM07_Facial_Expressions as the testing set, and for entites 002645310, 5067077, 002421669 (V2), we use expression EXP_free_face as the testing set.
Entity IDArchitecturePretrained ModelScript (use arch = warp as an example)Testing Loss (de-normalized tex / mesh)
002645310warp002645310_model.pthtraining / testing18.665674 / 0.042628
002645310base002645310_model.pth18.735119 / 0.041797
002645310res002645310_model.pth19.138665 / 0.048746
002645310non002645310_model.pth19.007677 / 0.044026
002645310bilinear002645310_model.pth18.841177 / 0.038838
002643814warp002643814_model.pthtraining / testing20.847874 / 0.038342
002643814base002643814_model.pth20.848138 / 0.038573
002643814res002643814_model.pth21.163654 / 0.039592
002643814non002643814_model.pth23.281789 / 0.039129
002643814bilinear002643814_model.pth21.080736 / 0.041327
7889059warp7889059_model.pthtraining / testing18.008945 / 0.024577
7889059base7889059_model.pth17.679865 / 0.024595
7889059res7889059_model.pth17.885587 / 0.024815
7889059non7889059_model.pth19.597485 / 0.025804
7889059bilinear7889059_model.pth18.138184 / 0.024527
5372021warp5372021_model.pthtraining / testing22.772976 / 0.05659
5372021base5372021_model.pth22.705741 / 0.058686
5372021res5372021_model.pth22.771726 / 0.059977
5372021non5372021_model.pth23.890847 / 0.056937
5372021bilinear5372021_model.pth22.818947 / 0.059152
2183941warp2183941_model.pthtraining / testing18.099761 / 0.026366
2183941base2183941_model.pth18.01334 / 0.026446
2183941res2183941_model.pth18.127609 / 0.026275
2183941non2183941_model.pth18.67969 / 0.026859
2183941bilinear2183941_model.pth18.016645 / 0.0267
8870559warp8870559_model.pthtraining / testing20.24462 / 0.022224
8870559base8870559_model.pth19.6116 / 0.022267
8870559res8870559_model.pth19.623022 / 0.022605
8870559non8870559_model.pth20.694372 / 0.022865
8870559bilinear8870559_model.pth19.908477 / 0.022487
6674443warp6674443_model.pthtraining / testing11.556278 / 0.018385
6674443base6674443_model.pth11.544078 / 0.018167
6674443res6674443_model.pth11.492206 / 0.018371
6674443non6674443_model.pth12.802362 / 0.017907
6674443bilinear6674443_model.pth11.545044 / 0.018235
5067077warp5067077_model.pthtraining / testing18.433626 / 0.01709
5067077base5067077_model.pth18.405165 / 0.017144
5067077res5067077_model.pth18.362903 / 0.017263
5067077non5067077_model.pth20.123446 / 0.016517
5067077bilinear5067077_model.pth18.564676 / 0.01704
002914589warp002914589_model.pthtraining / testing16.158173 / 0.032149
002914589base002914589_model.pth15.898207 / 0.030074
002914589res002914589_model.pth16.312272 / 0.035597
002914589non002914589_model.pth17.539636 / 0.032196
002914589bilinear002914589_model.pth16.246784 / 0.032283
6795937warp6795937_model.pthtraining / testing12.514287 / 0.023636
6795937base6795937_model.pth12.515156 / 0.022909
6795937res6795937_model.pth12.441071 / 0.023138
6795937non6795937_model.pth14.661052 / 0.022178
6795937bilinear6795937_model.pth12.669178 / 0.022721
002421669warp002421669_model.pthtraining / testing19.889421 / 0.010812
002421669base002421669_model.pth20.49622 / 0.010553
002421669res002421669_model.pth19.717948 / 0.010831
002421669non002421669_model.pth23.371122 / 0.010628
002421669bilinear002421669_model.pth20.877214 / 0.010807