Giter Site home page Giter Site logo

apple / ml-gmpi Goto Github PK

View Code? Open in Web Editor NEW
336.0 21.0 31.0 831 KB

Official PyTorch implementation of GMPI (ECCV 2022, Oral Presentation)

License: Other

Python 94.18% Shell 0.60% C++ 1.60% Cuda 3.62%
3d eccv2022 generative-adversarial-network neural-rendering pytorch generative-model multiplane-images

ml-gmpi's Introduction

Generative Multiplane Images (GMPI)

Making a 2D GAN 3D-Aware

ECCV 2022 (Oral)

Generative Multiplane Images: Making a 2D GAN 3D-Aware, ECCV 2022 (Oral).
Xiaoming Zhao, Fangchang Ma, David Güera Cobo, Zhile Ren, Alexander G. Schwing, and Alex Colburn.

Table of Contents

Environment Setup

This code has been tested on Ubuntu 18.04 with CUDA 10.2.

conda env create -f environment.yml

Using Pretrained Checkpoints

Download Checkpoints

cd /path/to/this/repo
export GMPI_ROOT=$PWD

Please download our pretrained checkpoints from the release page or this link and place them under ${GMPI_ROOT}/ckpts. The structure should be:

.
+-- ckpts
|  +-- gmpi_pretrained
|  |  +-- FFHQ256
|  |  +-- FFHQ512
|  |  +-- FFHQ1024
|  |  +-- AFHQCat
|  |  +-- MetFaces

We use the following variables for illustration purposes.

# This can be FFHQ256, FFHQ512, FFHQ1024, AFHQCat, or MetFaces
export DATASET_NAME=FFHQ1024
export OUTPUT_DIR=${GMPI_ROOT}/ckpts/gmpi_pretrained/${DATASET_NAME}

# Set this to your favourate seed
export SEED=589

# - When psi = 1.0 there is no truncation, which is used for quantitative results in the paper.
# - To obtain better qualitative results, use psi < 1.0.
export TRUNCATION_PSI=1.0

Render a Single Image

The following command renders an image ${OUTPUT_DIR}/rendered.png, along with:

  • mpi_alpha.png: alpha maps for all planes,
  • mpi_rgb.png: the same RGB texture for all planes,
  • mpi_rgba.png: RGB-alpha images for all planes.
conda activate gmpi && \
export PYTHONPATH=${GMPI_ROOT}:${GMPI_ROOT}/gmpi/models:$PYTHONPATH && \
python ${GMPI_ROOT}/gmpi/eval/vis/render_video.py \
--ckpt_path ${OUTPUT_DIR}/generator.pth \
--output_dir ${OUTPUT_DIR} \
--seeds ${SEED} \
--nplanes 96 \
--truncation_psi ${TRUNCATION_PSI} \
--exp_config ${OUTPUT_DIR}/config.pth \
--render_single_image 1

Note: We use nplanes = 96 in the paper for reporting quantitative and qualitative results, but GMPI is able to produce high-quality results even with 32 planes. Use a small nplanes (e.g., 32) if your run into CUDA out-of-memoory errors.

Render a Video

The following command renders a video in ${OUTPUT_DIR}, along with:

  • video_rgb.mp4: video for the RGB rendering,
  • video_depth.mp4: video for the depth rendering.
conda activate gmpi && \
export PYTHONPATH=${GMPI_ROOT}:${GMPI_ROOT}/gmpi/models:$PYTHONPATH && \
python ${GMPI_ROOT}/gmpi/eval/vis/render_video.py \
--ckpt_path ${OUTPUT_DIR}/generator.pth \
--output_dir ${OUTPUT_DIR} \
--seeds ${SEED} \
--nplanes 96 \
--truncation_psi ${TRUNCATION_PSI} \
--exp_config ${OUTPUT_DIR}/config.pth \
--render_single_image 0 \
--horizontal_cam_move 1

Notes:

  • Set nplanes to some small number (e.g., 32) if your run into CUDA out-of-memoory errors.
  • Set horizontal_cam_move to 0 if you want a video with vertical camera motion.

Extract a Mesh

The following command produces a mesh ${OUTPUT_DIR}/mesh_${TRUNCATION_PSI}.ply.

conda activate gmpi && \
export PYTHONPATH=${GMPI_ROOT}:${GMPI_ROOT}/gmpi/models:$PYTHONPATH && \
python ${GMPI_ROOT}/gmpi/eval/vis/extract_mesh.py \
--ckpt_path ${OUTPUT_DIR}/generator.pth \
--dataset ${DATASET_NAME} \
--save_dir ${OUTPUT_DIR} \
--exp_config ${OUTPUT_DIR}/config.pth \
--stylegan2_sanity_check 0 \
--truncation_psi ${TRUNCATION_PSI} \
--seed ${SEED} \
--chunk_n_planes -1

Notes:

  • Set chunk_n_planes to some small positive numbers (e.g., 64) if your run into CUDA out-of-memoory errors.
  • It may take several minutes to extract a mesh with Marching Cubes, for resolutions of 512 or above.

Training and Evaluation

Please refer to TRAIN_EVAL.md for more details.

Citation

Xiaoming Zhao, Fangchang Ma, David Güera, Zhile Ren, Alexander G. Schwing, and Alex Colburn. Generative Multiplane Images: Making a 2D GAN 3D-Aware. ECCV 2022.

@inproceedings{zhao-gmpi2022,
  title = {Generative Multiplane Images: Making a 2D GAN 3D-Aware},
  author = {Xiaoming Zhao and Fangchang Ma and David Güera and Zhile Ren and Alexander G. Schwing and Alex Colburn},
  booktitle = {Proc. ECCV},
  year = {2022},
}

License

This sample code is released under the LICENSE terms.

Disclaimer

Some of this software was built on Nvidia codebase, as noted within the applicable files, and such Nvidia code is available under its own terms at https://github.com/NVlabs/stylegan2-ada-pytorch. The authors of this software are not responsible for the contents of third-party websites.

ml-gmpi's People

Contributors

fangchangma avatar xiaoming-zhao 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

ml-gmpi's Issues

download FFHQ tfrecord dataset related issue

Hello, thank you for good research.
I want to train your model and refer your research.
But, when I download and preprocessing FFHQ, there is some problem.
FFHQ tfrecord -> FFHQ 256 preprocessing is suggested.
But the FFHQ tfrecord google drive api is disconnected everytime. (how do you download it?)
Is there any other option I can download it ?
There is no repository who provide 13G FFHQ 256 dataset...
If you give me a favor, It will be a great help. Thank you.

Query in calculating the depth and pose metric

Hi....
Can you Please help me calculating the Depth and Pose metric.....

eval "$(conda shell.bash hook)"
conda activate gmpi
export MKL_NUM_THREADS=5 && export NUMEXPR_NUM_THREADS=5 &&
python ${REPO_DIR}/gmpi/eval/prepare_fake_data.py
--ckpt_path ${CKPT_DIR}/generator.pth
--seed ${SEED}
--save_dir ${GEO_DIR}
--nplanes ${N_PLANES}
--n_imgs ${N_GEO}
--task geometry
--exp_config ${CKPT_DIR}/config.pth
--save_depth 1
--dataset ${DATASET}
--truncation_psi ${TRUNCATION_PSI}
--stylegan2_sanity_check ${SANITY_CHECK}

eval "$(conda shell.bash hook)"
conda activate mtcnn_env
export MKL_NUM_THREADS=5 && export NUMEXPR_NUM_THREADS=5 &&
python ${REPO_DIR}/gmpi/eval/prepare_face_landmarks.py
--data_dir ${GEO_DIR}/geometry/rgb

eval "$(conda shell.bash hook)"
conda activate deep3d_pytorch
cd ${Deep3DFaceRecon_PATH}
python ${Deep3DFaceRecon_PATH}/estimate_pose_gmpi.py
--name=pretrained
--epoch=20
--gmpi_img_root ${GEO_DIR}/geometry/rgb
--gmpi_depth_root ${GEO_DIR}/geometry/depth
--gmpi_detect_root ${GEO_DIR}/geometry/rgb/detections

eval "$(conda shell.bash hook)"
conda activate gmpi
python ${REPO_DIR}/gmpi/eval/compute_geometry.py
--geo_dir ${GEO_DIR}/geometry
--angle_err 1

Script of training

bash ${GMPI_ROOT}/gmpi/eval/eval.sh ${GMPI_ROOT} FFHQ256 20220727_102024290372 ${Deep3DFaceRecon_PATH} nodebug

Error:

warnings.warn(incompatible_device_warn.format(device_name, capability, " ".join(arch_list), device_name))
Transfer BFM09 to BFM_model_front......
Traceback (most recent call last):
File "/home/x_fahkh/.conda/envs/deep3d_pytorch/lib/python3.6/site-packages/scipy/io/matlab/mio.py", line 39, in _open_file
return open(file_like, mode), True
FileNotFoundError: [Errno 2] No such file or directory: 'BFM/01_MorphableModel.mat'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/proj/cvl/users/x_fahkh/mn/ml-gmpi/Deep3DFaceRecon_pytorch/estimate_pose_gmpi.py", line 133, in
main(0, opt, opt.gmpi_img_root, opt.gmpi_depth_root, opt.gmpi_detect_root)
File "/proj/cvl/users/x_fahkh/mn/ml-gmpi/Deep3DFaceRecon_pytorch/estimate_pose_gmpi.py", line 64, in main
model = create_model(opt)
File "/proj/cvl/users/x_fahkh/mn/ml-gmpi/Deep3DFaceRecon_pytorch/models/init.py", line 65, in create_model
instance = model(opt)
File "/proj/cvl/users/x_fahkh/mn/ml-gmpi/Deep3DFaceRecon_pytorch/models/facerecon_model.py", line 95, in init
is_train=self.isTrain, default_name=opt.bfm_model
File "/proj/cvl/users/x_fahkh/mn/ml-gmpi/Deep3DFaceRecon_pytorch/models/bfm.py", line 40, in init
transferBFM09(bfm_folder)
File "/proj/cvl/users/x_fahkh/mn/ml-gmpi/Deep3DFaceRecon_pytorch/util/load_mats.py", line 34, in transferBFM09
original_BFM = loadmat(osp.join(bfm_folder, '01_MorphableModel.mat'))
File "/home/x_fahkh/.conda/envs/deep3d_pytorch/lib/python3.6/site-packages/scipy/io/matlab/mio.py", line 216, in loadmat
with _open_file_context(file_name, appendmat) as f:
File "/home/x_fahkh/.conda/envs/deep3d_pytorch/lib/python3.6/contextlib.py", line 81, in enter
return next(self.gen)
File "/home/x_fahkh/.conda/envs/deep3d_pytorch/lib/python3.6/site-packages/scipy/io/matlab/mio.py", line 19, in _open_file_context
f, opened = _open_file(file_like, appendmat, mode)
File "/home/x_fahkh/.conda/envs/deep3d_pytorch/lib/python3.6/site-packages/scipy/io/matlab/mio.py", line 45, in _open_file
return open(file_like, mode), True
FileNotFoundError: [Errno 2] No such file or directory: 'BFM/01_MorphableModel.mat'
0%| | 0/1023 [00:00<?, ?it/s]
Traceback (most recent call last):
File "/proj/cvl/users/x_fahkh/mn/ml-gmpi/gmpi/eval/compute_geometry.py", line 93, in
tmp_depth_err = compute_depth_err(tmp_aligned_depth_f, tmp_pred_depth_f, tmp_pred_mask_f)
File "/proj/cvl/users/x_fahkh/mn/ml-gmpi/gmpi/eval/compute_geometry.py", line 26, in compute_depth_err
depth = np.load(alinged_depth_f)
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/numpy/lib/npyio.py", line 416, in load
fid = stack.enter_context(open(os_fspath(file), "rb"))
FileNotFoundError: [Errno 2] No such file or directory: '/proj/cvl/users/x_fahkh/mn/ml-gmpi/ckpts/gmpi_pretrained/20220727_102024290372/planes_96_n_1024/psi_1.0/geometry/recon/aligned_depth/000000.npy'

RuntimeError: "slow_conv_transpose2d_out_cpu" not implemented for 'Half'

Hi. I'm trying to run this project on Google Colab with GPU runtime. After setting up the environment and downloading the source code and pretrain weights. I encounter the following error when rendering a single image:

Traceback (most recent call last):
  File "/content/ml-gmpi/gmpi/eval/vis/render_video.py", line 228, in <module>
    generator = setup_model(opt, config, metadata, mpi_xyz_input, mpi_xyz_only_z, vis_mesh=False, device=device)
  File "/content/ml-gmpi/gmpi/eval/common.py", line 120, in setup_model
    _ = stylegan2_misc.print_module_summary(generator, [z, c, mpi_xyz_input, mpi_xyz_only_z, n_g_out_planes])
  File "/content/ml-gmpi/gmpi/models/torch_utils/misc.py", line 216, in print_module_summary
    outputs = module(*inputs)
  File "/usr/local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1148, in _call_impl
    result = forward_call(*input, **kwargs)
  File "/content/ml-gmpi/gmpi/models/networks/networks_cond_on_pos_enc.py", line 1323, in forward
    img = self.synthesize(ws=ws, n_planes=n_planes, mpi_xyz_coords=mpi_xyz_coords, xyz_coords_only_z=xyz_coords_only_z,
  File "/content/ml-gmpi/gmpi/models/networks/networks_cond_on_pos_enc.py", line 1295, in synthesize
    img = self.synthesis(ws, xyz_coords=mpi_xyz_coords, enable_feat_net_grad=enable_syn_feat_net_grad, xyz_coords_only_z=xyz_coords_only_z, n_planes=n_planes, **synthesis_kwargs)
  File "/usr/local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1148, in _call_impl
    result = forward_call(*input, **kwargs)
  File "/content/ml-gmpi/gmpi/models/networks/networks_cond_on_pos_enc.py", line 1205, in forward
    x, img = block(x, img, cur_ws, xyz_coords=tmp_xyz_coords, xyz_coords_only_z=xyz_coords_only_z, n_planes=n_planes, enable_feat_net_grad=enable_feat_net_grad, **block_kwargs)
  File "/usr/local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1148, in _call_impl
    result = forward_call(*input, **kwargs)
  File "/content/ml-gmpi/gmpi/models/networks/networks_cond_on_pos_enc.py", line 782, in forward
    x = self.conv0(x, w_conv0, fused_modconv=fused_modconv, **layer_kwargs)
  File "/usr/local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1148, in _call_impl
    result = forward_call(*input, **kwargs)
  File "/content/ml-gmpi/gmpi/models/networks/networks_cond_on_pos_enc.py", line 417, in forward
    x = modulated_conv2d(x=x, weight=self.weight, styles=styles, noise=noise, up=self.up,
  File "/content/ml-gmpi/gmpi/models/torch_utils/misc.py", line 104, in decorator
    return fn(*args, **kwargs)
  File "/content/ml-gmpi/gmpi/models/networks/networks_cond_on_pos_enc.py", line 180, in modulated_conv2d
    x = conv2d_resample.conv2d_resample(x=x, w=weight.to(x.dtype), f=resample_filter, up=up, down=down, padding=padding, flip_weight=flip_weight)
  File "/content/ml-gmpi/gmpi/models/torch_utils/misc.py", line 104, in decorator
    return fn(*args, **kwargs)
  File "/content/ml-gmpi/gmpi/models/torch_utils/ops/conv2d_resample.py", line 136, in conv2d_resample
    x = _conv2d_wrapper(x=x, w=w, stride=up, padding=[pyt,pxt], groups=groups, transpose=True, flip_weight=(not flip_weight))
  File "/content/ml-gmpi/gmpi/models/torch_utils/ops/conv2d_resample.py", line 52, in _conv2d_wrapper
    return op(x, w, stride=stride, padding=padding, groups=groups)
  File "/content/ml-gmpi/gmpi/models/torch_utils/ops/conv2d_gradfix.py", line 44, in conv_transpose2d
    return torch.nn.functional.conv_transpose2d(input=input, weight=weight, bias=bias, stride=stride, padding=padding, output_padding=output_padding, groups=groups, dilation=dilation)
RuntimeError: "slow_conv_transpose2d_out_cpu" not implemented for 'Half'

The Colab notebook and its full output can be found here:
https://colab.research.google.com/drive/1Iw1yetX-1b1zRhGXa12tpjTT_Un9kkQ3?usp=sharing

Problem In training the FFHQ1024 model

Hi......

I have some problem in training the FFHQ1024 Model. I have been training the model on 8 NVIDIA A100 GPUs, 40GB Memory still I am getting a error after some iterations of training.

Progress to next stage:   0%|          | 657/200000 [2:05:43<602:34:30, 10.88s/it]�[A
Total progress:   0%|          | 1/3000 [2:06:06<6303:11:19, 7566.35s/it]
Total progress:   0%|          | 1/3000 [2:06:06<6303:11:48, 7566.36s/it]

Progress to next stage:   0%|          | 0/200000 [2:05:55<?, ?it/s]
[Experiment: ./experiments/seed_123-dist_8-FFHQ1024-torgba_cond_normalize_add_z-embed_func_modulated_lrelu-20220727_205418050892] [Epoch: 0/3000] [D loss: 0.7179927229881287] [G loss: 1.4626858234405518] [Step: 620] [Img Size: 1024] [Batch Size: 4] [TopK: 2] Loading extension module upfirdn2d_plugin...
Done setting up PyTorch plugin "upfirdn2d_plugin".

Progress to next stage:   0%|          | 0/200000 [2:05:55<?, ?it/s]
Loading extension module upfirdn2d_plugin...
Done setting up PyTorch plugin "upfirdn2d_plugin".


Total progress:   0%|          | 1/3000 [2:06:06<6303:14:46, 7566.42s/it]
Setting up PyTorch plugin "bias_act_plugin"...
Using /home/x_fahkh/.cache/torch_extensions as PyTorch extensions root...
Loading extension module bias_act_plugin...
Done setting up PyTorch plugin "bias_act_plugin".
Setting up PyTorch plugin "upfirdn2d_plugin"...
Using /home/x_fahkh/.cache/torch_extensions as PyTorch extensions root...
Loading extension module upfirdn2d_plugin...
Done setting up PyTorch plugin "upfirdn2d_plugin".

Progress to next stage:   0%|          | 0/200000 [2:05:55<?, ?it/s]
/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/multiprocessing/semaphore_tracker.py:144: UserWarning: semaphore_tracker: There appear to be 33 leaked semaphores to clean up at shutdown
  len(cache))
Traceback (most recent call last):
  File "/proj/cvl/users/x_fahkh/mn/ml-gmpi/run_gmpi.py", line 115, in <module>
    main()
  File "/proj/cvl/users/x_fahkh/mn/ml-gmpi/run_gmpi.py", line 49, in main
    run_exp(**vars(args))
  File "/proj/cvl/users/x_fahkh/mn/ml-gmpi/run_gmpi.py", line 110, in run_exp
    mp.spawn(train, args=(num_gpus, config, master_port, run_dataset), nprocs=num_gpus, join=True)
  File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 230, in spawn
    return start_processes(fn, args, nprocs, join, daemon, start_method='spawn')
  File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 188, in start_processes
    while not context.join():
  File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 136, in join
    signal_name=name
torch.multiprocessing.spawn.ProcessExitedException: process 6 terminated with signal SIGBUS

Can You Please help me out in this....

Problem in Importing upfirdn2d_plugin.so

hi, when I try to run this command:

export PYTHONPATH=${GMPI_ROOT}:${GMPI_ROOT}/gmpi/models:$PYTHONPATH && \
python ${GMPI_ROOT}/gmpi/eval/vis/render_video.py \
--ckpt_path ${OUTPUT_DIR}/generator.pth \
--output_dir ${OUTPUT_DIR} \
--seeds ${SEED} \
--nplanes 96 \
--truncation_psi ${TRUNCATION_PSI} \
--exp_config ${OUTPUT_DIR}/config.pth \
--render_single_image 1

Then I meet this error, and my cuda version is 11.1

ImportError: /data/run01/scz5914/.cache/torch_extensions/upfirdn2d_plugin/upfirdn2d_plugin.so: 
undefined symbol: _ZNSt15__exception_ptr13exception_ptr9_M_addrefEv
warnings.warn('Failed to build CUDA kernels for upfirdn2d. Falling back to slow reference implementation. Details:\n\n' + traceback.format_exc())

Fortunately, this error doesn't block the render image generating.
But I really hope to get faster inference speed.
So, do you know how to solve this problem?

PS: full error info

/HOME/scz5914/run/huangan_work/ml-gmpi/gmpi/models/torch_utils/ops/upfirdn2d.py:34: UserWarning: Failed to build CUDA kernels for upfirdn2d. Falling back to slow reference implementation. Details:

Traceback (most recent call last):
  File "/HOME/scz5914/run/huangan_work/ml-gmpi/gmpi/models/torch_utils/ops/upfirdn2d.py", line 32, in _init
    _plugin = custom_ops.get_plugin('upfirdn2d_plugin', sources=sources, extra_cuda_cflags=['--use_fast_math'])
  File "/HOME/scz5914/run/huangan_work/ml-gmpi/gmpi/models/torch_utils/custom_ops.py", line 110, in get_plugin
    torch.utils.cpp_extension.load(name=module_name, verbose=verbose_build, sources=sources, **build_kwargs)
  File "/HOME/scz5914/.conda/envs/gmpi/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1092, in load
    keep_intermediates=keep_intermediates)
  File "/HOME/scz5914/.conda/envs/gmpi/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1318, in _jit_compile
    return _import_module_from_library(name, build_directory, is_python_module)
  File "/HOME/scz5914/.conda/envs/gmpi/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1701, in _import_module_from_library
    module = importlib.util.module_from_spec(spec)
  File "<frozen importlib._bootstrap>", line 583, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1043, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: /data/run01/scz5914/.cache/torch_extensions/upfirdn2d_plugin/upfirdn2d_plugin.so: undefined symbol: _ZNSt15__exception_ptr13exception_ptr9_M_addrefEv

"RuntimeError: output is too large" when extracting meshes with 1024x1024 models

Hi, thanks for your excellent work! When I tried to use the command in README.md to extract a mesh with a 1024x1024 pre-trained model (i.e., FFHQ1024, MetFaces), I got the following error (I'm using a 40GB A100 GPU and extracting meshes with a low-resolution pre-trained model works properly.):

Traceback (most recent call last):
  File "/data/miniconda3/envs/env-3.8.8/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/data/miniconda3/envs/env-3.8.8/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/group/30042/jialexu/projects/ml-gmpi/gmpi/eval/vis/extract_mesh.py", line 302, in <module>
    main(opt)
  File "/group/30042/jialexu/projects/ml-gmpi/gmpi/eval/vis/extract_mesh.py", line 255, in main
    mesh = generate_mesh(
  File "/group/30042/jialexu/projects/ml-gmpi/gmpi/eval/vis/extract_mesh.py", line 95, in generate_mesh
    tmp_mpi_rgbas = gen(
  File "/data/miniconda3/envs/env-3.8.8/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/group/30042/jialexu/projects/ml-gmpi/gmpi/models/networks/networks_cond_on_pos_enc.py", line 1323, in forward
    img = self.synthesize(ws=ws, n_planes=n_planes, mpi_xyz_coords=mpi_xyz_coords, xyz_coords_only_z=xyz_coords_only_z,
  File "/group/30042/jialexu/projects/ml-gmpi/gmpi/models/networks/networks_cond_on_pos_enc.py", line 1295, in synthesize
    img = self.synthesis(ws, xyz_coords=mpi_xyz_coords, enable_feat_net_grad=enable_syn_feat_net_grad, xyz_coords_only_z=xyz_coords_only_z, n_planes=n_planes, **synthesis_kwargs)
  File "/data/miniconda3/envs/env-3.8.8/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/group/30042/jialexu/projects/ml-gmpi/gmpi/models/networks/networks_cond_on_pos_enc.py", line 1205, in forward
    x, img = block(x, img, cur_ws, xyz_coords=tmp_xyz_coords, xyz_coords_only_z=xyz_coords_only_z, n_planes=n_planes, enable_feat_net_grad=enable_feat_net_grad, **block_kwargs)
  File "/data/miniconda3/envs/env-3.8.8/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/group/30042/jialexu/projects/ml-gmpi/gmpi/models/networks/networks_cond_on_pos_enc.py", line 792, in forward
    img = upfirdn2d.upsample2d(img, self.resample_filter)
  File "/group/30042/jialexu/projects/ml-gmpi/gmpi/models/torch_utils/ops/upfirdn2d.py", line 343, in upsample2d
    return upfirdn2d(x, f, up=up, padding=p, flip_filter=flip_filter, gain=gain*upx*upy, impl=impl)
  File "/group/30042/jialexu/projects/ml-gmpi/gmpi/models/torch_utils/ops/upfirdn2d.py", line 163, in upfirdn2d
    return _upfirdn2d_cuda(up=up, down=down, padding=padding, flip_filter=flip_filter, gain=gain).apply(x, f)
  File "/group/30042/jialexu/projects/ml-gmpi/gmpi/models/torch_utils/ops/upfirdn2d.py", line 237, in forward
    y = _plugin.upfirdn2d(y, f, upx, upy, downx, downy, padx0, padx1, pady0, pady1, flip_filter, gain)
RuntimeError: output is too large

Do you have any advice to fix this error? Thanks in advance.

Problem in calculating the Identity metric

Hi....

I tried to get to calculate the identity metric but there are some dependency issue in the code. Can you Please help me out in this.

Eval.sh
eval "$(conda shell.bash hook)"
conda activate gmpi
export MKL_NUM_THREADS=5 && export NUMEXPR_NUM_THREADS=5 &&
python ${REPO_DIR}/gmpi/eval/prepare_fake_data.py
--ckpt_path ${CKPT_DIR}/generator.pth
--seed ${SEED}
--save_dir ${CONSIST_DIR}
--nplanes ${N_PLANES}
--n_imgs ${N_CONSIST}
--task consistency
--exp_config ${CKPT_DIR}/config.pth
--truncation_psi ${TRUNCATION_PSI}
--dataset ${DATASET}
--stylegan2_sanity_check ${SANITY_CHECK}

eval "$(conda shell.bash hook)"
conda activate deepface
python ${REPO_DIR}/gmpi/eval/compute_consistency.py
--input_dir ${CONSIST_DIR}/consistency
--n_imgs ${N_CONSIST}
--nproc 2

COMMAND TO RUN:
bash {GMPI_ROOT}/gmpi/eval/eval.sh ${GMPI_ROOT} FFHQ256 20220727_102024290372 {Deep3DFaceRecon_PATH} nodebug

ERROR :

Traceback (most recent call last):
File "/proj/cvl/users/x_fahkh/mn/ml-gmpi/gmpi/eval/compute_consistency.py", line 12, in
import tensorflow as tf
File "/home/x_fahkh/.conda/envs/deepfaces/lib/python3.7/site-packages/tensorflow/init.py", line 51, in
from ._api.v2 import compat
File "/home/x_fahkh/.conda/envs/deepfaces/lib/python3.7/site-packages/tensorflow/_api/v2/compat/init.py", line 37, in
from . import v1
File "/home/x_fahkh/.conda/envs/deepfaces/lib/python3.7/site-packages/tensorflow/_api/v2/compat/v1/init.py", line 30, in
from . import compat
File "/home/x_fahkh/.conda/envs/deepfaces/lib/python3.7/site-packages/tensorflow/_api/v2/compat/v1/compat/init.py", line 37, in
from . import v1
File "/home/x_fahkh/.conda/envs/deepfaces/lib/python3.7/site-packages/tensorflow/_api/v2/compat/v1/compat/v1/init.py", line 47, in
from tensorflow._api.v2.compat.v1 import lite
File "/home/x_fahkh/.conda/envs/deepfaces/lib/python3.7/site-packages/tensorflow/_api/v2/compat/v1/lite/init.py", line 9, in
from . import experimental
File "/home/x_fahkh/.conda/envs/deepfaces/lib/python3.7/site-packages/tensorflow/_api/v2/compat/v1/lite/experimental/init.py", line 8, in
from . import authoring
File "/home/x_fahkh/.conda/envs/deepfaces/lib/python3.7/site-packages/tensorflow/_api/v2/compat/v1/lite/experimental/authoring/init.py", line 8, in
from tensorflow.lite.python.authoring.authoring import compatible
File "/home/x_fahkh/.conda/envs/deepfaces/lib/python3.7/site-packages/tensorflow/lite/python/authoring/authoring.py", line 43, in
from tensorflow.lite.python import convert
File "/home/x_fahkh/.conda/envs/deepfaces/lib/python3.7/site-packages/tensorflow/lite/python/convert.py", line 29, in
from tensorflow.lite.python import util
File "/home/x_fahkh/.conda/envs/deepfaces/lib/python3.7/site-packages/tensorflow/lite/python/util.py", line 26, in
import flatbuffers
ModuleNotFoundError: No module named 'flatbuffers'

pose of AFHQ

Very nice work. How did you generate the camera poses for AFHQ dataset, can you give me a more detailed method?

I got error when I start to train

Hi, I got error below when I start to train model with this command CUDA_VISIBLE_DEVICES=2,3,4,5,6 python launch.py --run_dataset FFHQ256 --nproc_per_node 0 --task-type gmpi --run-type train master_port 8378 but I can't figure out the reason.

I guess this error is occurred inside train.py's 313 code line if rank == 0:
But I'm not sure. If anyone has solved the problem, please help!

Setting up PyTorch plugin "bias_act_plugin"...
Using /root/.cache/torch_extensions/py38_cu113 as PyTorch extensions root...
Detected CUDA files, patching ldflags
Emitting ninja build file /root/.cache/torch_extensions/py38_cu113/bias_act_plugin/build.ninja...
Building extension module bias_act_plugin...
Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N)
ninja: no work to do.
Loading extension module bias_act_plugin...
Done setting up PyTorch plugin "bias_act_plugin".
Traceback (most recent call last):
  File "/data/eden/ml-gmpi/run_gmpi.py", line 115, in <module>
    main()
  File "/data/eden/ml-gmpi/run_gmpi.py", line 49, in main
    run_exp(**vars(args))
  File "/data/eden/ml-gmpi/run_gmpi.py", line 110, in run_exp
    mp.spawn(train, args=(num_gpus, config, master_port, run_dataset), nprocs=num_gpus, join=True)
  File "/opt/conda/envs/gmpi/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 240, in spawn
    return start_processes(fn, args, nprocs, join, daemon, start_method='spawn')
  File "/opt/conda/envs/gmpi/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 198, in start_processes
    while not context.join():
  File "/opt/conda/envs/gmpi/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 140, in join
    raise ProcessExitedException(
torch.multiprocessing.spawn.ProcessExitedException: process 0 terminated with signal SIGSEGV
/opt/conda/envs/gmpi/lib/python3.8/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d

Query Regarding the evaluation code for FFHOQ512

Script for evaluating :
bash {GMPI_ROOT}/gmpi/eval/eval.sh {GMPI_ROOT} FFHQ512 20220727_104512601146 {Deep3DFaceRecon_PATH} nodebug

Can you Please help me in fixing the issue for evaluating the code for FFHQ512....

Error:
Load weights from /proj/cvl/users/x_fahkh/mn/ml-gmpi/ckpts/gmpi_pretrained/20220727_104512601146/generator.pth
Load weights from /proj/cvl/users/x_fahkh/mn/ml-gmpi/ckpts/gmpi_pretrained/20220727_104512601146/ema.pth
save_dir: /proj/cvl/users/x_fahkh/mn/ml-gmpi/ckpts/gmpi_pretrained/20220727_104512601146/planes_96_n_50000/psi_1.0/fid_kid/rgb
0%| | 0/50000 [00:00<?, ?it/s]
log: torch.Size([1, 96, 4, 512, 512]) (1, 512, 512, 3) (1, 512, 512, 1)
100%|█████████████████████████████████████████████████████████████████████████████████████████████████| 50000/50000 [3:22:49<00:00, 4.11it/s]

Compute FID/KID from
real: /proj/cvl/users/x_fahkh/mn/ml-gmpi/runtime_dataset/real_data/FFHQ512/FFHQ_real_res_512_n_50000
fake: /proj/cvl/users/x_fahkh/mn/ml-gmpi/ckpts/gmpi_pretrained/20220727_104512601146/planes_96_n_50000/psi_1.0/fid_kid/rgb

Creating feature extractor "inception-v3-compat" with features ['2048']
Extracting features from input1
Looking for samples non-recursivelty in "/proj/cvl/users/x_fahkh/mn/ml-gmpi/ckpts/gmpi_pretrained/20220727_104512601146/planes_96_n_50000/psi_1.0/fid_kid/rgb" with extensions png,jpg,jpeg
Found 50000 samples
Processing samples
Extracting features from input2
Looking for samples non-recursivelty in "/proj/cvl/users/x_fahkh/mn/ml-gmpi/runtime_dataset/real_data/FFHQ512/FFHQ_real_res_512_n_50000" with extensions png,jpg,jpeg
Found 71 samples
Traceback (most recent call last):
File "/proj/cvl/users/x_fahkh/mn/ml-gmpi/gmpi/eval/compute_fid_kid.py", line 29, in
verbose=True,
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch_fidelity/metrics.py", line 243, in calculate_metrics
featuresdict_2 = extract_featuresdict_from_input_id_cached(2, feat_extractor, **kwargs)
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch_fidelity/utils.py", line 372, in extract_featuresdict_from_input_id_cached
featuresdict = fn_recompute()
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch_fidelity/utils.py", line 360, in fn_recompute
return extract_featuresdict_from_input_id(input_id, feat_extractor, **kwargs)
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch_fidelity/utils.py", line 345, in extract_featuresdict_from_input_id
featuresdict = get_featuresdict_from_dataset(input, feat_extractor, batch_size, cuda, save_cpu_ram, verbose)
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch_fidelity/utils.py", line 111, in get_featuresdict_from_dataset
for bid, batch in enumerate(dataloader):
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 521, in next
data = self._next_data()
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1183, in _next_data
return self._process_data(data)
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1229, in _process_data
data.reraise()
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch/_utils.py", line 425, in reraise
raise self.exc_type(msg)
OSError: Caught OSError in DataLoader worker process 1.
Original Traceback (most recent call last):
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
data = fetcher.fetch(index)
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch_fidelity/datasets.py", line 31, in getitem
img = Image.open(path).convert('RGB')
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/PIL/Image.py", line 2822, in open
raise IOError("cannot identify image file %r" % (filename if filename else fp))
OSError: cannot identify image file '/proj/cvl/users/x_fahkh/mn/ml-gmpi/runtime_dataset/real_data/FFHQ512/FFHQ_real_res_512_n_50000/00070.png'

Can you Please have a look to this

Problem in Reproducing the Depth score

Hi.....

When I tried to calculate the Depth score for given pretrained model on FFHQ256.
The score where:

depth:  0.53399503 0.35273126 
angle:  0.004 0.006 

After training the model from scratch for FFHQ256
The score where:

depth:  0.5855465 0.41952634
angle:  0.004 0.008

After training the model from scratch for FFHQ512
The score where different as compare to scores given in the table

depth:  0.523077 0.33253828 
angle:  0.004 0.008

environment.yml error

Collecting package metadata (repodata.json): done
Solving environment: failed

ResolvePackageNotFound:

  • cudatoolkit=10.2

Problem in reproducing fid score

Thank you for amazing work again.
I have some trouble to reproducing fid score..

  1. I fail to download tfrecord and used 7GB public 256 dataset as a zip file.
    (https://www.kaggle.com/datasets/denislukovnikov/ffhq256-images-only)
  2. I guess the ffhq256x256.zip file format is same as preprocessed one.
  3. I trained with this data and checked the training score.
  4. the fid goes up when I train.. from 20 to 25
    Could you give me some advice about this situation?
    (I will try again with 1025 90G version with your advice..
    Also,, if you give me some personal help please email me.. I will so appreciate your help. [email protected]
    I really want to refer your research but.. dataset problem is not easy for me... )

Thank you so much.

Code for estimating pose for preprocessing (used in "Deep3DFaceRecon" directory)

In the TRAIN_EVAL.md, you used the following commands for estimating camera pose:

# For FFHQ
cd ${Deep3DFaceRecon_PATH}
python estimate_pose_ffhq.py --name=pretrained --epoch=20 --img_folder=${GMPI_ROOT}/runtime_dataset/dummy --gmpi_img_res ${RES} --gmpi_root ${GMPI_ROOT}

# For MetFace
cd ${Deep3DFaceRecon_PATH}
python estimate_pose_metfaces.py --name=pretrained --epoch=20 --img_folder=${GMPI_ROOT}/runtime_dataset/dummy --gmpi_root ${GMPI_ROOT} 

However, I can not find these codes in the Deep3DFaceRecon_pytorch repository.
I guess you newly made these python files. Could you share these files?

Great Work!!!!!! Few Queries

I have Some conceptual queries regarding the code:

When I put the random_pose = False in line 396 of mpi_rendering.py and pass the same pose as given by the dataloader([flat_w2c_mats_real] line 419 train.py ) to self.mpi() function [line 451 mpi_renderer.py] then after 6 iteration on 8 gpu the error arises .

Error:

pos: tensor([[0.5797, 0.0647, 0.1850]], device='cuda:0')

dir: tensor([[-0.6583, -0.1611, 0.7355]], device='cuda:0')

u: tensor([-1.0399, -1.0401, -1.0398, -1.0396], device='cuda:0')

v: tensor([-0.6758, -0.6710, -0.6656, -0.6603], device='cuda:0')

yaws: [[-0.6179566383361816]]

pitches: [[0.07507812976837158]]

Traceback (most recent call last):
File "/proj/cvl/users/x_fahkh/mn/debug-dmpi/gmpi/core/mpi.py", line 106, in homography
assert torch.min(u) >= -1, f"Ray's U direction goes out of plane at {distance}, min val {torch.min(u)}"
AssertionError: Ray's U direction goes out of plane at tensor([[1.1200]], device='cuda:0'), min val -1.0400704145431519

The question is that how is it possible that extrinsic parameter[flat_w2c_mats_real] of real image to leads out of plane of the rays.

Great Work!!!! Few queries regarding the evaluation code

Hi....

I have used same script as provided the documentation for the evaluation code
Script :
bash {GMPI_ROOT}/gmpi/eval/eval.sh {GMPI_ROOT} FFHQ256 20220727_102024290372 ${Deep3DFaceRecon_PATH} debug

But I am getting some error in calculating FID and KID Can you Please help me in this :

real_dir: /proj/cvl/users/x_fahkh/mn/ml-gmpi/runtime_dataset/real_data/FFHQ256/FFHQ_real_res_256_n_50000

Traceback (most recent call last):
File "/proj/cvl/users/x_fahkh/mn/ml-gmpi/gmpi/eval/prepare_fake_data.py", line 280, in
main(opt)
File "/proj/cvl/users/x_fahkh/mn/ml-gmpi/gmpi/eval/prepare_fake_data.py", line 96, in main
config = Config(init_dict=torch.load(opt.exp_config, map_location="cpu")["config"])
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch/serialization.py", line 594, in load
with _open_file_like(f, 'rb') as opened_file:
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch/serialization.py", line 230, in _open_file_like
return _open_file(name_or_buffer, mode)
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch/serialization.py", line 211, in init
super(_open_file, self).init(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: '/proj/cvl/users/x_fahkh/mn/ml-gmpi/ckpts/gmpi_pretrained/20220727_102024290372/config.pth'

Compute FID/KID from
real: /proj/cvl/users/x_fahkh/mn/ml-gmpi/runtime_dataset/real_data/FFHQ256/FFHQ_real_res_256_n_50000
fake: /proj/cvl/users/x_fahkh/mn/ml-gmpi/ckpts/gmpi_pretrained/20220727_102024290372/planes_96_n_50000/psi_1.0/fid_kid/rgb

Creating feature extractor "inception-v3-compat" with features ['2048']
Extracting features from input1
Traceback (most recent call last):
File "/proj/cvl/users/x_fahkh/mn/ml-gmpi/gmpi/eval/compute_fid_kid.py", line 29, in
verbose=True,
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch_fidelity/metrics.py", line 239, in calculate_metrics
featuresdict_1 = extract_featuresdict_from_input_id_cached(1, feat_extractor, **kwargs)
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch_fidelity/utils.py", line 372, in extract_featuresdict_from_input_id_cached
featuresdict = fn_recompute()
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch_fidelity/utils.py", line 360, in fn_recompute
return extract_featuresdict_from_input_id(input_id, feat_extractor, **kwargs)
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch_fidelity/utils.py", line 342, in extract_featuresdict_from_input_id
input = prepare_input_from_id(input_id, **kwargs)
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch_fidelity/utils.py", line 275, in prepare_input_from_id
return prepare_input_from_descriptor(input_desc, **kwargs)
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch_fidelity/utils.py", line 255, in prepare_input_from_descriptor
f'Input descriptor "input" field can be either an instance of Dataset, GenerativeModelBase class, or a string, '
File "/home/x_fahkh/.conda/envs/gmpi/lib/python3.7/site-packages/torch_fidelity/helpers.py", line 9, in vassert
raise ValueError(message)
ValueError: Input descriptor "input" field can be either an instance of Dataset, GenerativeModelBase class, or a string, such as a path to a name of a registered dataset (cifar10-train, cifar10-val, stl10-train, stl10-test, stl10-unlabeled), a directory with file samples, or a path to an ONNX or PTH (JIT) module

Can you Please help me in this......

RuntimeError: Unable to find a valid cuDNN algorithm to run convolution

Hello, I'm interested in your model. So I'm trying to rendering image by pretrained model.
I'm trying to render image and video at FFHQ512 dataset.
According to docs/TRAIN_EVAL.md, I understand that if I make ffhq512x512.zip by styleganv2-ada-pytorch and ffh1512_deep3dface_coeffs, then
I can render image, video and extrach mesh.
Screenshot from 2023-02-18 15-52-10

But when I apply render a image to get mpi results, this error came out.

RuntimeError: Unable to find a valid cuDNN algorithm to run convolution

I locate pretrained model files at ml-gmpi/ckpts/gmpi_pretrained/FFHQ512.
Could you tell me why this problem happen.
Thanks for your attention.

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.