Git Product home page Git Product logo

discofacegan's Introduction

DiscoFaceGAN: Disentangled and Controllable Face Image Generation via 3D Imitative-Contrastive Learning

This is a tensorflow implementation of the following paper:

Disentangled and Controllable Face Image Generation via 3D Imitative-Contrastive Learning, CVPR 2020. (Oral)

Yu Deng, Jiaolong Yang, Dong Chen, Fang Wen, and Xin Tong

Paper: https://arxiv.org/abs/2004.11660

Abstract: We propose DiscoFaceGAN, an approach for face image generation of virtual people with DISentangled, precisely-COntrollable latent representations for identity of non-existing people, expression, pose, and illumination. We embed 3D priors into adversarial learning and train the network to imitate the image formation of an analytic 3D face deformation and rendering process. To deal with the generation freedom induced by the domain gap between real and rendered faces, we further introduce contrastive learning to promote disentanglement by comparing pairs of generated images. Experiments show that through our imitative-contrastive learning, the factor variations are very well disentangled and the properties of a generated face can be precisely controlled. We also analyze the learned latent space and present several meaningful properties supporting factor disentanglement. Our method can also be used to embed real images into the disentangled latent space. We hope our method could provide new understandings of the relationship between physical properties and deep image synthesis.

Features

● Factor disentanglement

When generating face images, we can freely change the four factors including identity, expression, lighting, and pose. The factor variations are highly disentangled: changing one factor does not affect others.

● Reference based generation

We achieve reference-based generation where we extract expression, pose and lighting from a given image and generate new identities with similar properties.

● Real image pose manipulation

We can use our method to embed a real image into the disentangled latent space and edit it, such as pose manipulation.

● Real image lighting editing

We can edit the lighting of a real image.

● Real image expression transfer

We can also achieve expression transfer of real images.

The training code of our model are mainly borrowed from StyleGAN, although our method can be applied to any form of GANs.

Testing requirements

  • Python 3.6. We recommend Anaconda3 with numpy 1.14.3 or newer.
  • Tensorflow 1.12 with GPU support.
  • CUDA toolkit 9.0 or newer, cuDNN 7.3.1 or newer.

Testing with pre-trained network

  1. Clone the repository:
git clone https://github.com/microsoft/DiscoFaceGAN.git
cd DiscoFaceGAN
  1. Generate images using pre-trained network:
# Generate face images with random variations of expression, lighting, and pose
python generate_images.py

# Generate face images with random variations of expression
python generate_images.py --factor 1

# Generate face images with random variations of lighting
python generate_images.py --factor 2

# Generate face images with random variations of pose
python generate_images.py --factor 3

Training requirements

  • Only Linux is supported.
  • Python 3.6. We recommend Anaconda3 with numpy 1.14.3 or newer.
  • Tensorflow 1.12 with GPU support.
  • CUDA toolkit 9.0 or newer, cuDNN 7.3.1 or newer.
  • One or more high-end NVIDIA GPUs. We recommend using at least 4 Tesla P100 GPUs for training.
  • Basel Face Model 2009 (BFM09).
  • Expression Basis provided by Guo et al.. The original BFM09 model does not handle expression variations so extra expression basis are needed.
  • tf_mesh_renderer provided by Genova et al.. We use the tool to render synthetic face images during training. We recommend using its older version because we find its latest version unstable during our training process.
  • Facenet provided by Sandberg et al. In our paper, we use a network to exrtact deep face features. This network model cannot be publicly released. As an alternative, we recommend using the Facenet model. We use the version 20170512-110547 trained on MS-Celeb-1M. Training process has been tested with this model to ensure similar results.
  • 3D face reconstruction network. We use the network to extract identity, expression, lighting, and pose coefficients.
  • Face parsing network provided by Lin et al.. We use the network to obtain hair segmentation masks during training.

Training preparation

  1. Download the Basel Face Model. Due to the license agreement of Basel Face Model, you have to submit an application on its home page. After getting the access to BFM data, download "01_MorphableModel.mat" and put it in "./renderer/BFM face model".
  2. Download the Expression Basis. You can find a link named "CoarseData" in the first row of Introduction part in their repository. Download and unzip the Coarse_Dataset.zip. Put "Exp_Pca.bin" in "./renderer/BFM face model".
  3. Install tf_mesh_renderer. For convenience, we provide a pre-compiled file of the library under tensorflow 1.12. Download the file and put it in "./renderer".
  4. Download the pre-trained weights of Facenet provided by Sandberg et al., unzip it and put all files in "./training/pretrained_weights/id_net".
  5. Download the pre-trained weights of 3D face reconstruction network, unzip it and put all files in "./training/pretrained_weights/recon_net".
  6. Download the pre-trained weights of face parser provided by Lin et al., unzip it and put all files in "./training/pretrained_weights/parsing_net".

Data pre-processing

  1. Download FFHQ dataset. Detect 5 facial landmarks for all images. We recommend using dlib or MTCNN. Save all images in <raw_image_path> and corresponding landmarks in <raw_lm_path>. Note that an image and its detected landmark file should have same name.
  2. Align images and extract coefficients for VAE and GAN training:
python preprocess_data.py --image_path=<raw_image_path> --lm_path=<raw_lm_path> --save_path=<save_path_for_processed_data>
  1. Convert the aligned images to multi-resolution TFRecords similar as in StyleGAN:
python dataset_tool.py create_from_images ./datasets/ffhq_align <save_path_for_processed_data>/img

Training networks

  1. We provide pre-trained VAEs for factors of identity, expression, lighting, and pose. To train new models from scratch, run:
cd vae

# train VAE for identity coefficients
python demo.py --datapath <save_path_for_processed_data>/coeff --factor id

# train VAE for expression coefficients
python demo.py --datapath <save_path_for_processed_data>/coeff --factor exp

# train VAE for lighting coefficients
python demo.py --datapath <save_path_for_processed_data>/coeff --factor gamma

# train VAE for pose coefficients
python demo.py --datapath <save_path_for_processed_data>/coeff --factor rot
  1. Train the Stylegan generator with imitative-contrastive learning scheme:
# Stage 1 with only imitative losses, training with 15000k images
python train.py 

# Stage 2 with both imitative losses and contrastive losses, training with another 5000k images
python train.py --stage 2 --run_id <stage1_model_id> --snapshot <stage1_model_snapshot> --kimg <stage1_model_snapshot> 
# For example
python train.py --stage 2 --run_id 0 --snapshot 14926 --kimg 14926

After training, the network can be used similarly as the provided pre-trained model:

# Generate face images with specific model
python generate_images.py --model <your_model_path.pkl>

We have trained the model using a configuration of 4 Tesla P100 GPUs. It takes 6d 15h for stage 1 and 5d 8h for stage 2.

Contact

If you have any questions, please contact Yu Deng ([email protected]) and Jiaolong Yang ([email protected])

License

Copyright © Microsoft Corporation.

Licensed under the MIT license.

Citation

Please cite the following paper if this model helps your research:

@inproceedings{deng2020disentangled,
	title={Disentangled and Controllable Face Image Generation via 3D Imitative-Contrastive Learning},
	author={Yu Deng and Jiaolong Yang and Dong Chen and Fang Wen and Xin Tong},
    booktitle={IEEE Computer Vision and Pattern Recognition},
    year={2020}
}

The real face images on this page are from the public FFHQ dataset released under Creative Commons BY-NC-SA 4.0 license. Detailed information can be found on its website.

discofacegan's People

Contributors

microsoft-github-operations[bot] avatar microsoftopensource avatar yangjiaolong avatar yudeng 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

discofacegan's Issues

what difference between W and W+ space ?

since the [1] paper: "Image2StyleGAN: How to Embed Images Into the StyleGAN Latent Space?" don't have an official implement and in the paper 3.3 just said:

W+ is a concatenation of 18 different 512-dimensional w vectors

so? W space is 1x18x512,what's the difference?

Conv2DCustomBackpropInputOp only supports NHWC.

For completeness, the entirety of the error message is as below--

2020-07-01 13:36:02.995480: E tensorflow/core/common_runtime/executor.cc:642] Executor failed to create kernel. Invalid argument: Conv2DCustomBackpropInputOp only supports NHWC.
[[{{node G_synthesis_2/cond/cond/cond/cond/128x128/Conv0_up/conv2d_transpose}}]]
Traceback (most recent call last):
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1365, in _do_call
return fn(*args)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1350, in _run_fn
target_list, run_metadata)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1443, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Conv2DCustomBackpropInputOp only supports NHWC.
[[{{node G_synthesis_2/cond/cond/cond/cond/128x128/Conv0_up/conv2d_transpose}}]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "generate_images.py", line 209, in
main()
File "generate_images.py", line 205, in main
fake = tflib.run(fake_images_out, {latents:lats,noise:noise_})
File "/home/region/Desktop/DisentangledFaceGAN/dnnlib/tflib/tfutil.py", line 26, in run
return tf.get_default_session().run(*args, **kwargs)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 956, in run
run_metadata_ptr)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1180, in _run
feed_dict_tensor, options, run_metadata)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1359, in _do_run
run_metadata)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1384, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Conv2DCustomBackpropInputOp only supports NHWC.
[[node G_synthesis_2/cond/cond/cond/cond/128x128/Conv0_up/conv2d_transpose (defined at /home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py:1748) ]]

Original stack trace for 'G_synthesis_2/cond/cond/cond/cond/128x128/Conv0_up/conv2d_transpose':
File "generate_images.py", line 209, in
main()
File "generate_images.py", line 186, in main
fake_images_out = truncate_generation(Gs,INPUTcoeff_w_noise,dlatent_average_id=average_w_id)
File "generate_images.py", line 89, in truncate_generation
fake_images_out = Gs.components.synthesis.get_output_for(dlatent_out_final, randomize_noise = False)
File "/home/region/Desktop/DisentangledFaceGAN/dnnlib/tflib/network.py", line 222, in get_output_for
out_expr = self._build_func(*final_inputs, **build_kwargs)
File "", line 570, in G_synthesis
File "", line 569, in grow
File "", line 563, in
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/ops/control_flow_ops.py", line 1224, in cond
orig_res_t, res_t = context_t.BuildCondBranch(true_fn)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/ops/control_flow_ops.py", line 1061, in BuildCondBranch
original_result = fn()
File "", line 568, in
File "", line 569, in grow
File "", line 563, in
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/ops/control_flow_ops.py", line 1224, in cond
orig_res_t, res_t = context_t.BuildCondBranch(true_fn)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/ops/control_flow_ops.py", line 1061, in BuildCondBranch
original_result = fn()
File "", line 568, in
File "", line 569, in grow
File "", line 563, in
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/ops/control_flow_ops.py", line 1224, in cond
orig_res_t, res_t = context_t.BuildCondBranch(true_fn)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/ops/control_flow_ops.py", line 1061, in BuildCondBranch
original_result = fn()
File "", line 568, in
File "", line 569, in grow
File "", line 563, in
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/ops/control_flow_ops.py", line 1224, in cond
orig_res_t, res_t = context_t.BuildCondBranch(true_fn)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/ops/control_flow_ops.py", line 1061, in BuildCondBranch
original_result = fn()
File "", line 568, in
File "", line 565, in grow
File "", line 534, in block
File "", line 191, in upscale2d_conv2d
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/ops/nn_ops.py", line 2204, in conv2d_transpose
name=name)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/ops/nn_ops.py", line 2275, in conv2d_transpose_v2
name=name)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_nn_ops.py", line 1407, in conv2d_backprop_input
name=name)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/framework/op_def_library.py", line 794, in _apply_op_helper
op_def=op_def)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 3357, in create_op
attrs, op_def, compute_device)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 3426, in _create_op_internal
op_def=op_def)
File "/home/region/anaconda3/envs/tod1/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1748, in init
self._traceback = tf_stack.extract_stack()

I searched online, and many seem to suggest that this is a CPU/GPU problem. However, I encountered the same issue on CPU and on GeForce RTX 2080 Ti. Any help would be appreciated. Thanks!

Windows Support

Does this project work on windows for using pre-trained models and linux is only for training or it doesn't support windows in any shape?

Also are you planning to add windows support?

How to generate a picture that has the same lighting as the reference sample

Thanks for your work a lot!I have trouble when I trying to generate a picture that has the same lighting as the reference.
I have tried the same method like #6

  1. utilizing the R_Net to extract the coefficient (257) of both source and reference image, and discarding the last three elements (254).
    2.Combining the identity coefficient of the source image with the other three factors coefficients of the reference image to generate a new coefficient for later face generation.
    3.Adding random noise to the above coefficient and utilizing the truncate_generation to obtain the manipulated results.
    however the generated images do not preserve both the identity information and other information of the source image.

source image

src

reference image

ref

generated image

res

I have also tired the method which optimize from an average latent vector in W+ space. I embed both source image and reference image into W+ space and update it using an Adam optimizer with 3000 iterations, and then I combine them using final_vector = tf.concat([src_vector[:, :8, :], ref_vector[:, 8:, :]], axis=1), but I get a output like this

generated image2

src_ref

Looking forward to your reply! I would appreciate it if you could provide a demo code.

NotFoundError: ./renderer/rasterize_triangles_kernel_1.so

When trying to run the preprocess_data.py script i get the following error message:

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
Traceback (most recent call last):
File "preprocess_data.py", line 12, in
from renderer import face_decoder
File "./renderer/face_decoder.py", line 7, in
from renderer import mesh_renderer
File "./renderer/mesh_renderer.py", line 25, in
from renderer import rasterize_triangles
File "./renderer/rasterize_triangles.py", line 30, in
rasterize_triangles_module = tf.load_op_library('./renderer/rasterize_triangles_kernel_1.so')
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/load_library.py", line 61, in load_op_library
lib_handle = py_tf.TF_LoadLibrary(library_filename)
tensorflow.python.framework.errors_impl.NotFoundError: ./renderer/rasterize_triangles_kernel_1.so: undefined symbol: _ZN10tensorflow14kernel_factory17OpKernelRegistrar12InitInternalEPKNS_9KernelDefEN4absl11string_viewEPFPNS_8OpKernelEPNS_20OpKernelConstructionEE

The environment is defined as per the guidelines mentioned in the repo. Any help would be appreciated. Thanks.

Reference based generation

Hi, thanks for your great work. I have some trouble when I run the reference-based generation task. First, FaceReconModel.ckpt is not found in the preprocess_data script. Second, how to convert the coefficient extracted in lamda space to the latent code in z space. Look forward to your reply.

I get negative vae loss

I'm tryting to train a model with my dataset, However I get negative vae loss, it seems quite strange.
Could you help me with this? Thanks!
vae training log with factor rot:

/usr/local/miniconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:523: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/usr/local/miniconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:524: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/usr/local/miniconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/usr/local/miniconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/usr/local/miniconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/usr/local/miniconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:532: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
Namespace(batch_size=64, cross_entropy_loss=False, datapath='../datasets/data/coeff', epochs=600, factor='rot', gpu=0, lr=0.0001, lr_epochs=150, lr_fac=0.5, output_path='./weights', root_folder='.', val=False, write_iteration=600)
46975
2022-04-14 10:43:10.860388: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2022-04-14 10:43:11.042504: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties:
name: NVIDIA Tesla P40 major: 6 minor: 1 memoryClockRate(GHz): 1.531
pciBusID: 0000:08:00.0
totalMemory: 23.88GiB freeMemory: 22.99GiB
2022-04-14 10:43:11.042551: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0
2022-04-14 10:43:11.427630: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix:
2022-04-14 10:43:11.427679: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988]      0
2022-04-14 10:43:11.427686: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0:   N
2022-04-14 10:43:11.427814: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 22300 MB memory) -> physical GPU (device: 0, name: NVIDIA Tesla P40, pci bus id: 0000:08:00.0, compute capability: 6.1)
Date: 2022-04-14 10:43:26       Epoch: [Stage 1][0/600] Loss: 2.7066.
Date: 2022-04-14 10:43:40       Epoch: [Stage 1][1/600] Loss: 2.4838.
Date: 2022-04-14 10:43:55       Epoch: [Stage 1][2/600] Loss: 2.2725.
Date: 2022-04-14 10:44:10       Epoch: [Stage 1][3/600] Loss: 2.0638.
Date: 2022-04-14 10:44:24       Epoch: [Stage 1][4/600] Loss: 1.8573.
Date: 2022-04-14 10:44:39       Epoch: [Stage 1][5/600] Loss: 1.6532.
Date: 2022-04-14 10:44:54       Epoch: [Stage 1][6/600] Loss: 1.4517.
Date: 2022-04-14 10:45:09       Epoch: [Stage 1][7/600] Loss: 1.2532.
Date: 2022-04-14 10:45:24       Epoch: [Stage 1][8/600] Loss: 1.0580.
Date: 2022-04-14 10:45:39       Epoch: [Stage 1][9/600] Loss: 0.8668.
Date: 2022-04-14 10:45:54       Epoch: [Stage 1][10/600]        Loss: 0.6800.
Date: 2022-04-14 10:46:08       Epoch: [Stage 1][11/600]        Loss: 0.4984.
Date: 2022-04-14 10:46:23       Epoch: [Stage 1][12/600]        Loss: 0.3226.
Date: 2022-04-14 10:46:38       Epoch: [Stage 1][13/600]        Loss: 0.1537.
Date: 2022-04-14 10:46:53       Epoch: [Stage 1][14/600]        Loss: -0.0077.
Date: 2022-04-14 10:47:07       Epoch: [Stage 1][15/600]        Loss: -0.1606.
Date: 2022-04-14 10:47:22       Epoch: [Stage 1][16/600]        Loss: -0.3031.
Date: 2022-04-14 10:47:37       Epoch: [Stage 1][17/600]        Loss: -0.4346.
Date: 2022-04-14 10:47:52       Epoch: [Stage 1][18/600]        Loss: -0.5539.
Date: 2022-04-14 10:48:07       Epoch: [Stage 1][19/600]        Loss: -0.6600.
Date: 2022-04-14 10:48:21       Epoch: [Stage 1][20/600]        Loss: -0.7503.
Date: 2022-04-14 10:48:37       Epoch: [Stage 1][21/600]        Loss: -0.8247.
Date: 2022-04-14 10:48:51       Epoch: [Stage 1][22/600]        Loss: -0.8824.
Date: 2022-04-14 10:49:06       Epoch: [Stage 1][23/600]        Loss: -0.9245.
Date: 2022-04-14 10:49:20       Epoch: [Stage 1][24/600]        Loss: -0.9519.
Date: 2022-04-14 10:49:35       Epoch: [Stage 1][25/600]        Loss: -0.9678.
Date: 2022-04-14 10:49:50       Epoch: [Stage 1][26/600]        Loss: -0.9839.
Date: 2022-04-14 10:50:05       Epoch: [Stage 1][27/600]        Loss: -1.0732.
Date: 2022-04-14 10:50:20       Epoch: [Stage 1][28/600]        Loss: -1.2186.
Date: 2022-04-14 10:50:34       Epoch: [Stage 1][29/600]        Loss: -1.2832.
Date: 2022-04-14 10:50:49       Epoch: [Stage 1][30/600]        Loss: -1.3243.
Date: 2022-04-14 10:51:04       Epoch: [Stage 1][31/600]        Loss: -1.3485.
Date: 2022-04-14 10:51:19       Epoch: [Stage 1][32/600]        Loss: -1.3644.
Date: 2022-04-14 10:51:34       Epoch: [Stage 1][33/600]        Loss: -1.3820.
Date: 2022-04-14 10:51:49       Epoch: [Stage 1][34/600]        Loss: -1.3819.

vae training log with factor gamma:

root@train-disco3-0:/data1/DiscoFaceGAN/vae# python demo.py --datapath ../datasets/data/coeff --factor gamma
/usr/local/miniconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:523: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/usr/local/miniconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:524: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/usr/local/miniconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/usr/local/miniconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/usr/local/miniconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/usr/local/miniconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:532: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
Namespace(batch_size=64, cross_entropy_loss=False, datapath='../datasets/data/coeff', epochs=600, factor='gamma', gpu=0, lr=0.0001, lr_epochs=150, lr_fac=0.5, output_path='./weights', root_folder='.', val=False, write_iteration=600)
46975
2022-04-14 10:42:52.898209: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2022-04-14 10:42:53.063619: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties:
name: NVIDIA Tesla P40 major: 6 minor: 1 memoryClockRate(GHz): 1.531
pciBusID: 0000:08:00.0
totalMemory: 23.88GiB freeMemory: 23.22GiB
2022-04-14 10:42:53.063673: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0
2022-04-14 10:42:53.419503: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix:
2022-04-14 10:42:53.419554: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988]      0
2022-04-14 10:42:53.419561: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0:   N
2022-04-14 10:42:53.419681: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 22532 MB memory) -> physical GPU (device: 0, name: NVIDIA Tesla P40, pci bus id: 0000:08:00.0, compute capability: 6.1)
Date: 2022-04-14 10:43:07       Epoch: [Stage 1][0/600] Loss: 23.9197.
Date: 2022-04-14 10:43:22       Epoch: [Stage 1][1/600] Loss: 21.9015.
Date: 2022-04-14 10:43:36       Epoch: [Stage 1][2/600] Loss: 19.9280.
Date: 2022-04-14 10:43:50       Epoch: [Stage 1][3/600] Loss: 17.9590.
Date: 2022-04-14 10:44:04       Epoch: [Stage 1][4/600] Loss: 15.9933.
Date: 2022-04-14 10:44:18       Epoch: [Stage 1][5/600] Loss: 14.0305.
Date: 2022-04-14 10:44:32       Epoch: [Stage 1][6/600] Loss: 12.0710.
Date: 2022-04-14 10:44:46       Epoch: [Stage 1][7/600] Loss: 10.1152.
Date: 2022-04-14 10:45:01       Epoch: [Stage 1][8/600] Loss: 8.1635.
Date: 2022-04-14 10:45:15       Epoch: [Stage 1][9/600] Loss: 6.2167.
Date: 2022-04-14 10:45:29       Epoch: [Stage 1][10/600]        Loss: 4.2754.
Date: 2022-04-14 10:45:44       Epoch: [Stage 1][11/600]        Loss: 2.3405.
Date: 2022-04-14 10:45:58       Epoch: [Stage 1][12/600]        Loss: 0.4129.
Date: 2022-04-14 10:46:12       Epoch: [Stage 1][13/600]        Loss: -1.5061.
Date: 2022-04-14 10:46:27       Epoch: [Stage 1][14/600]        Loss: -3.4153.
Date: 2022-04-14 10:46:41       Epoch: [Stage 1][15/600]        Loss: -5.3130.
Date: 2022-04-14 10:46:55       Epoch: [Stage 1][16/600]        Loss: -7.1975.
Date: 2022-04-14 10:47:10       Epoch: [Stage 1][17/600]        Loss: -9.0669.
Date: 2022-04-14 10:47:23       Epoch: [Stage 1][18/600]        Loss: -10.9186.
Date: 2022-04-14 10:47:38       Epoch: [Stage 1][19/600]        Loss: -12.7502.
Date: 2022-04-14 10:47:52       Epoch: [Stage 1][20/600]        Loss: -14.5583.
Date: 2022-04-14 10:48:07       Epoch: [Stage 1][21/600]        Loss: -16.3394.
Date: 2022-04-14 10:48:21       Epoch: [Stage 1][22/600]        Loss: -18.0895.
Date: 2022-04-14 10:48:36       Epoch: [Stage 1][23/600]        Loss: -19.8038.

Data Preprocessing for Training

My settings:

python == 3.6
tensorflow-gpu==1.12.0

both installed by conda.

I tried running python preprocess_data.py --image_path=<raw_image_path> --lm_path=<raw_lm_path> --save_path=<save_path_for_processed_data>

and got:

/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:523: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:524: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:532: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
Traceback (most recent call last):
  File "preprocess_data.py", line 12, in <module>
    from renderer import face_decoder
  File "/trainman-mount/trainman-storage-06c5b4b4-59b3-49f3-a31f-f513d0a7f027/2021_work/DiscoFaceGAN/renderer/face_decoder.py", line 7, in <module>
    from renderer import mesh_renderer
  File "/trainman-mount/trainman-storage-06c5b4b4-59b3-49f3-a31f-f513d0a7f027/2021_work/DiscoFaceGAN/renderer/mesh_renderer.py", line 25, in <module>
    from renderer import rasterize_triangles
  File "/trainman-mount/trainman-storage-06c5b4b4-59b3-49f3-a31f-f513d0a7f027/2021_work/DiscoFaceGAN/renderer/rasterize_triangles.py", line 30, in <module>
    rasterize_triangles_module = tf.load_op_library('/home/code-base/user_space/2021_work/DiscoFaceGAN/renderer/rasterize_triangles_kernel_1.so')
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/framework/load_library.py", line 60, in load_op_library
    lib_handle = py_tf.TF_LoadLibrary(library_filename)
tensorflow.python.framework.errors_impl.NotFoundError: /home/code-base/user_space/2021_work/DiscoFaceGAN/renderer/rasterize_triangles_kernel_1.so: undefined symbol: _ZN10tensorflow12OpDefBuilder4AttrESs

Could you help me with the issues? Thanks!

Rendering Images with Renderer

Hi, I have been trying to understand the effectiveness of imitative learning by using the face renderer Face3D() to render some faces.

Here are my codes:

from renderer.face_decoder import Face3D
from training.training_utils import z_to_lambda_mapping

FaceRender = Face3D()

minibatch_in = tf.placeholder(tf.int32, name='minibatch_in', shape=[])
resolution = tf.placeholder(tf.float32, name='resolution', shape=[]) # Try a tf-placeholder

latents = tf.random_normal([minibatch_in,128+32+16+3])
INPUTcoeff = z_to_lambda_mapping(latents)
INPUTcoeff_w_t = tf.concat([INPUTcoeff,tf.zeros([minibatch_in,3])], axis = 1)
render_img,render_mask,render_landmark,_ = FaceRender.Reconstruction_Block(INPUTcoeff_w_t,resolution,minibatch_in,progressive=True)

sess = tf.Session()
init = tf.global_variables_initializer()
sess.run(init)

res = 32
minibatch = 4
r_img, r_mask_, r_lmark = sess.run([render_img, render_mask, render_landmark], 
                                    {resolution: res, minibatch_in: minibatch})

I suppose r_img, r_mask, r_lmark would be the rendered the stuffs, yet it returns an error:

---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
   1333     try:
-> 1334       return fn(*args)
   1335     except errors.OpError as e:

/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/client/session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)
   1318       return self._call_tf_sessionrun(
-> 1319           options, feed_dict, fetch_list, target_list, run_metadata)
   1320 

/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/client/session.py in _call_tf_sessionrun(self, options, feed_dict, fetch_list, target_list, run_metadata)
   1406         self._session, options, feed_dict, fetch_list, target_list,
-> 1407         run_metadata)
   1408 

InvalidArgumentError: Input to reshape is a tensor with 428508 values, but the requested shape has 1714032
	 [[{{node cond/cond/cond/Reshape}} = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:GPU:0"](cond/cond/cond/cond/Reshape/Switch:1, cond/cond/cond/Reshape_1/shape)]]
	 [[{{node cond/cond/cond/cond/cond/GatherV2_2/_111}} = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_3747_cond/cond/cond/cond/cond/GatherV2_2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

During handling of the above exception, another exception occurred:

InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-9-63fad876710d> in <module>
      2 minibatch = 4
      3 r_img, r_mask_, r_lmark = sess.run([render_img, render_mask, render_landmark], 
----> 4                                     {resolution: res, minibatch_in: minibatch})

/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
    927     try:
    928       result = self._run(None, fetches, feed_dict, options_ptr,
--> 929                          run_metadata_ptr)
    930       if run_metadata:
    931         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
   1150     if final_fetches or final_targets or (handle and feed_dict_tensor):
   1151       results = self._do_run(handle, final_targets, final_fetches,
-> 1152                              feed_dict_tensor, options, run_metadata)
   1153     else:
   1154       results = []

/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/client/session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
   1326     if handle is None:
   1327       return self._do_call(_run_fn, feeds, fetches, targets, options,
-> 1328                            run_metadata)
   1329     else:
   1330       return self._do_call(_prun_fn, handle, feeds, fetches)

/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
   1346           pass
   1347       message = error_interpolation.interpolate(message, self._graph)
-> 1348       raise type(e)(node_def, op, message)
   1349 
   1350   def _extend_graph(self):

InvalidArgumentError: Input to reshape is a tensor with 428508 values, but the requested shape has 1714032
	 [[node cond/cond/cond/Reshape (defined at ../DiscoFaceGAN/renderer/face_decoder.py:303)  = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:GPU:0"](cond/cond/cond/cond/Reshape/Switch:1, cond/cond/cond/Reshape_1/shape)]]
	 [[{{node cond/cond/cond/cond/cond/GatherV2_2/_111}} = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_3747_cond/cond/cond/cond/cond/GatherV2_2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

Caused by op 'cond/cond/cond/Reshape', defined at:
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/traitlets/config/application.py", line 664, in launch_instance
    app.start()
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/ipykernel/kernelapp.py", line 619, in start
    self.io_loop.start()
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tornado/platform/asyncio.py", line 199, in start
    self.asyncio_loop.run_forever()
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/asyncio/base_events.py", line 442, in run_forever
    self._run_once()
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/asyncio/base_events.py", line 1462, in _run_once
    handle._run()
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/asyncio/events.py", line 145, in _run
    self._callback(*self._args)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tornado/ioloop.py", line 688, in <lambda>
    lambda f: self._run_callback(functools.partial(callback, future))
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tornado/ioloop.py", line 741, in _run_callback
    ret = callback()
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tornado/gen.py", line 814, in inner
    self.ctx_run(self.run)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tornado/gen.py", line 162, in _fake_ctx_run
    return f(*args, **kw)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tornado/gen.py", line 775, in run
    yielded = self.gen.send(value)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 358, in process_one
    yield gen.maybe_future(dispatch(*args))
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tornado/gen.py", line 234, in wrapper
    yielded = ctx_run(next, result)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tornado/gen.py", line 162, in _fake_ctx_run
    return f(*args, **kw)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 261, in dispatch_shell
    yield gen.maybe_future(handler(stream, idents, msg))
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tornado/gen.py", line 234, in wrapper
    yielded = ctx_run(next, result)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tornado/gen.py", line 162, in _fake_ctx_run
    return f(*args, **kw)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 538, in execute_request
    user_expressions, allow_stdin,
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tornado/gen.py", line 234, in wrapper
    yielded = ctx_run(next, result)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tornado/gen.py", line 162, in _fake_ctx_run
    return f(*args, **kw)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/ipykernel/ipkernel.py", line 302, in do_execute
    res = shell.run_cell(code, store_history=store_history, silent=silent)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/ipykernel/zmqshell.py", line 539, in run_cell
    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2867, in run_cell
    raw_cell, store_history, silent, shell_futures)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2895, in _run_cell
    return runner(coro)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/IPython/core/async_helpers.py", line 68, in _pseudo_sync_runner
    coro.send(None)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3072, in run_cell_async
    interactivity=interactivity, compiler=compiler, result=result)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3263, in run_ast_nodes
    if (await self.run_code(code, result,  async_=asy)):
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3343, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-7-d5186183c6b1>", line 4, in <module>
    render_img,render_mask,render_landmark,_ = FaceRender.Reconstruction_Block(INPUTcoeff_w_t,resolution,minibatch_in,progressive=True)
  File "../DiscoFaceGAN/renderer/face_decoder.py", line 65, in Reconstruction_Block
    lambda:
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 488, in new_func
    return func(*args, **kwargs)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2097, in cond
    orig_res_f, res_f = context_f.BuildCondBranch(false_fn)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1930, in BuildCondBranch
    original_result = fn()
  File "../DiscoFaceGAN/renderer/face_decoder.py", line 67, in <lambda>
    lambda:
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 488, in new_func
    return func(*args, **kwargs)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2097, in cond
    orig_res_f, res_f = context_f.BuildCondBranch(false_fn)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1930, in BuildCondBranch
    original_result = fn()
  File "../DiscoFaceGAN/renderer/face_decoder.py", line 69, in <lambda>
    lambda:
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 488, in new_func
    return func(*args, **kwargs)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2086, in cond
    orig_res_t, res_t = context_t.BuildCondBranch(true_fn)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1930, in BuildCondBranch
    original_result = fn()
  File "../DiscoFaceGAN/renderer/face_decoder.py", line 68, in <lambda>
    tf.cond(res<=32, lambda:self.Render_block(face_shape_t,norm_r,face_color,self.facemodel,32,16),
  File "../DiscoFaceGAN/renderer/face_decoder.py", line 303, in Render_block
    face_shape = tf.reshape(face_shape,[batchsize,n_vex,3])
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 6482, in reshape
    "Reshape", tensor=tensor, shape=shape, name=name)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 488, in new_func
    return func(*args, **kwargs)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3274, in create_op
    op_def=op_def)
  File "/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1770, in __init__
    self._traceback = tf_stack.extract_stack()

InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 428508 values, but the requested shape has 1714032
	 [[node cond/cond/cond/Reshape (defined at ../DiscoFaceGAN/renderer/face_decoder.py:303)  = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:GPU:0"](cond/cond/cond/cond/Reshape/Switch:1, cond/cond/cond/Reshape_1/shape)]]
	 [[{{node cond/cond/cond/cond/cond/GatherV2_2/_111}} = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_3747_cond/cond/cond/cond/cond/GatherV2_2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

Could you help me with this? Thanks in advance!

Pixelated images are generated instead of faces

Hi Yu,,

I'm glad to have stumbled on your GAN project. I followed the directions, installed the appropriate libraries and am able to run 'python generate_images.py' or 'python generate_images.py --factor 1' etc without any errors.

But it always generates pixelated images that don't resemble faces. Any ideas what's going on?

I'm a cognitive neuroscientist (MD, PhD) that thinks this could be a very useful tech for face recognition tasks/tests or emotional tests/tasks.

Best,
Omar

generate wrong pictures

Dear author,thanks for your great work,it‘s very helpful for me
But when I run the generate_images.py,I get very strange result
019_01
I download the pretrain .pkl file,and set --model=’network-snapshot-020126.pkl’ and =network-snapshot-020126.pkl
The former result is added,the latter result is a blank picture.
I think the reason of this phenomenon is not loading the pkl files fail or loading wrong file.
Is there something needs to notice I miss?I really want to know the answer.

questions on params of resolution and batch size

render_imgs,img_mask = tf.cond(res<=8, lambda:self.Render_block(face_shape_t,norm_r,face_color,self.facemodel,8,64),

Hi, the function "Render_block" referred above has two parameters, namely "res" and "batchsize"; but when calling this function, instead of using the "res" and "batchsize" from the function "Reconstruction_Block", you hardcoded different values for different resolution cases.

How does those hardcoded values match the batch size of others parameters of the function "Reconstruction_Block"?

I'm implementing the image embedding in your paper, what am I doing wrong?

Hey, so let me start by saying this is some impressive work! I've decided to take the challenge of implementing the image embedding + editing from your paper. I feel like I understand what I need to do, but I'm not getting good results.

Let me say that I have the W+ state for an embedded image. I used the dataset you used in your code to do the embedding with the system provided by Stylegan Encoder (https://github.com/Puzer/stylegan-encoder.git). It's in the shape of [1, 14, 512], and I get the correct image out after running it through the synthesis function Gs.components.synthesis.get_output_for(dlatents, randomize_noise = False).

So if I understand your paper and the Image2StyleGAN paper correctly, what I have is the W+ state of the image. According to your paper, I should be able to implement the following:

Screen Shot 2020-07-04 at 1 28 56 PM

Screen Shot 2020-07-04 at 3 47 14 PM is the image I'm trying to encode

Screen Shot 2020-07-04 at 3 47 51 PM was the process I went through to encode said image with Stylegan Encoder

Screen Shot 2020-07-04 at 3 48 37 PM is the [1, 14, 512] shape that I got from said Stylegan Encoder process

Screen Shot 2020-07-04 at 3 49 18 PM is the Gs.components.synthesis.get_output_for func

and

Screen Shot 2020-07-04 at 3 49 48 PM

is equal to

Screen Shot 2020-07-04 at 3 45 57 PM

Now, for my implementation. I'm currently trying to manipulate one of the theta (ROT) variables.

In order to do this I have hijacked the truncate_generation function. I felt it was the best spot to implement this.

Here is how I have implemented it:

def truncate_generation(Gs,inputcoeff,rate=0.7,dlatent_average_id=None):
    embedded_w_plus_space = np.reshape(np.load('embedded.npy'),[1,14,512]).astype(np.float32) # embedded image
    embedded_w_plus_space = tf.constant(embedded_w_plus_space)

    # INPUTcoeff = tf.concat([IDcoeff,EXPcoeff,Rotcoeff,GAMMAcoeff], axis = 1)
    # INPUTcoeff = tf.concat([INPUTcoeff, noise_], axis = 1)
    # final shape = [160, 64, 3, 27, 32]

    id_exp_zero = tf.zeros([1,160+64])
    rand_rot_isolate = tf.concat([inputcoeff[:,160+64:160+64+1], tf.zeros([1, 2])], axis=1)
    gamma_noise_zero = tf.zeros([1,27+32])

    lambda_i_equals_a = tf.concat([id_exp_zero, rand_rot_isolate, gamma_noise_zero],axis=1)
    lambda_i_equals_b = lambda_i_equals_a * 0.0

    w_i_equals_a = Gs.components.mapping.get_output_for(lambda_i_equals_a, None ,is_training=False, is_validation = True)
    w_i_equals_b = Gs.components.mapping.get_output_for(lambda_i_equals_b, None ,is_training=False, is_validation = True)

    delta_w_iab = w_i_equals_a - w_i_equals_b #w(a) - w(b)

    x_t_pre_synth = embedded_w_plus_space + delta_w_iab

    x_t = Gs.components.synthesis.get_output_for(x_t_pre_synth, randomize_noise = False)
    x_t = tf.clip_by_value((x_t+1)*127.5,0,255)
    x_t = tf.transpose(x_t,perm = [0,2,3,1])

    return x_t 

Am I on the right track? Can you give me some hints? Thanks! Let me know if you want me to explain anything further.

Camera params

Hi, I don't understand the zoom like operation here , what is the value 1.22 in scale?

FaceReconModel.ckpt

Can you provide the FaceReconModel.ckpt? I can't find it from the givn link. Thank you very much.

_pickle.UnpicklingError: invalid load key, '<'.

Hi,
While running python generate_images.py, the below error was encountered. Could you please help

Traceback (most recent call last):
File "generate_images.py", line 199, in
main()
File "generate_images.py", line 158, in main
Gs = load_Gs(url_pretrained_model_ffhq)
File "generate_images.py", line 136, in load_Gs
_G, _D, Gs = pickle.load(f)
_pickle.UnpicklingError: invalid load key, '<'.

Many thanks for considering my request.

Format of dlib detection

Great work! In the "Data pre-processing" stage, it is required that 5 facial landmarks are detected for all images. I wonder in what format should I save the results of this detection. Thanks!

training crash

Hi, I tried with tensorflow-gpu=1.12.0, but I experienced a "Segmentation fault", while the first fakes002364.png has been saved.

==================================
Building TensorFlow graph...
Stage1: Imitative learning...

Stage1: Imitative learning...

Stage1: Imitative learning...

Stage1: Imitative learning...

Setting up snapshot image grid...
Training...

Segmentation fault (core dumped)

pre-trained model~

can you provide per-trained model in this project directly? I can't download it from google drive~
thank you so much

About the Parsing net output

hi, There are three channels for parsing network output. The third channel represents hair segmentation result. What do the first two channels represent? Thanks

I need help! Could not load dynamic library 'libnvinfer.so.6' and 'libnvinfer_plugin.so.6'

Thanks for sharing the training code! the result of DiscoFace GAN is awesome!

However, when I test the project following the readme, An error occured:

2021-02-03 12:23:02.634079: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer.so.6'; dlerror: libnvinfer.so.6: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/opt/conda/lib
2021-02-03 12:23:02.634189: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer_plugin.so.6'; dlerror: libnvinfer_plugin.so.6: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/opt/conda/lib
2021-02-03 12:23:02.634202: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:30] Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
Traceback (most recent call last):
File "generate_images.py", line 10, in
from training import misc
File "/ml_workspace/caishuxiao/DiscoFaceGAN-master/training/misc.py", line 20, in
from training import dataset
File "/ml_workspace/caishuxiao/DiscoFaceGAN-master/training/dataset.py", line 15, in
import dnnlib.tflib as tflib
File "/ml_workspace/caishuxiao/DiscoFaceGAN-master/dnnlib/tflib/init.py", line 8, in
from . import autosummary
File "/ml_workspace/caishuxiao/DiscoFaceGAN-master/dnnlib/tflib/autosummary.py", line 31, in
from . import tfutil
File "/ml_workspace/caishuxiao/DiscoFaceGAN-master/dnnlib/tflib/tfutil.py", line 34, in
def shape_to_list(shape: Iterable[tf.Dimension]) -> List[Union[int, None]]:
AttributeError: module 'tensorflow' has no attribute 'Dimension'

So which TensorRT version should I install? Or How to fix "'tensorflow' has no attribute 'Dimension'"

./renderer/rasterize_triangles_kernel_1.so could not find

Hi, Great work first! Excited to execute the training script, but got stuck at the first step while running python preprocess_data.py -h. It gives the following error

tensorflow.python.framework.errors_impl.NotFoundError: ./renderer/rasterize_triangles_kernel_1.so: cannot open shared object file: No such file or directory

when trying to load './renderer/rasterize_triangles_kernel_1.so' in DisentangledFaceGAN/renderer/rasterize_triangles.py, line 30. I guess this .so file was forgotten to upload by mistake.

About the Parsing net inference code

Hello.
Thank you for your great work.
I'm currently try to use Face Parsing net of Lin et al. method to get face and hairear segmentation map like following image.

3_0718_2_vis_pre_seg

But the output of network is not desirable...
(+) I get (256, 256, 3) segmentation map although input image is (512, 512, 3).

3_0718_2_vis_cur_seg

My code for getting network is as following:

def get_pretrained_face_parser(sess=None):
    graph_input_img = tf.placeholder(dtype=tf.float32)
    graph_facial_landmark = tf.placeholder(dtype=tf.float32, shape=[1, 68, 2])
    graph_face_parsing = Parsing(graph_input_img, graph_facial_landmark)
    graph = tf.get_default_graph()
    if not sess:
        sess = tf.Session()
        sess.run(tf.global_variables_initializer())
    # get variable list
    var_list = tf.trainable_variables()
    g_list = tf.global_variables()
    bn_moving_vars = [g for g in g_list if 'moving_mean' in g.name]
    bn_moving_vars += [g for g in g_list if 'moving_variance' in g.name]
    var_list +=bn_moving_vars
    parser_vars = [v for v in var_list if 'FaceParser' in v.name]
    # restore weight provided by Lin et al.
    saver_parser = tf.train.Saver(var_list=parser_vars)
    saver_parser.restore(sess, os.path.join('./training/pretrained_weights/parsing_net','faceparser_public'))
    return sess, graph, graph_face_parsing, graph_input_img, graph_facial_landmark

Also I use Preprocess function from preprocess/preprocess_utils.py. Is there some suggestion to utilize your code?

I already check #19
Have a nice day.

Weird artifacts in generated images

Hi, first of all, I would like to say you guys did an amazing work. So I was generating images with the code given and in some of the cases it's generating some weird artifact in the images(sometimes the skin is kind of cartoonish, the colours are out of the line or some patches over face). I am not talking about extreme pose variation or illumination. So my question is , anyhow can we control such faces not to generate?

Stage1 Training

Hi, I tried to do stage-1 training from scratch via python3 train.py and got the output as:

/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:523: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type,(1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:524: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type,(1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type,(1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type,(1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type,(1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/opt/conda/envs/discofacegan_env/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:532: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type,(1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
Creating the run dir: results/00004-sgan-ffhq256-4gpu
Copying files to the run dir
dnnlib: Running training.training_loop.training_loop() on localhost...

Calling Function: training.training_loop.training_loop

Streaming data using training.dataset.TFRecordDataset...
Dataset shape = [3, 256, 256]
Dynamic range = [0, 255]
Label size    = 0
---Debugging---
The run directory is: results/87
Traceback (most recent call last):
  File "train.py", line 121, in <module>
    main()
  File "train.py", line 116, in main
    dnnlib.submit_run(**kwargs)
  File "/trainman-mount/trainman-storage-06c5b4b4-59b3-49f3-a31f-f513d0a7f027/2021_work/DiscoFaceGAN/dnnlib/submission/submit.py", line 290, in submit_run
    run_wrapper(submit_config)
  File "/trainman-mount/trainman-storage-06c5b4b4-59b3-49f3-a31f-f513d0a7f027/2021_work/DiscoFaceGAN/dnnlib/submission/submit.py", line 242, in run_wrapper
    util.call_func_by_name(func_name=submit_config.run_func_name, submit_config=submit_config, **submit_config.run_func_kwargs)
  File "/trainman-mount/trainman-storage-06c5b4b4-59b3-49f3-a31f-f513d0a7f027/2021_work/DiscoFaceGAN/dnnlib/util.py", line258, in call_func_by_name
    return func_obj(*args, **kwargs)
  File "/trainman-mount/trainman-storage-06c5b4b4-59b3-49f3-a31f-f513d0a7f027/2021_work/DiscoFaceGAN/training/training_loop.py", line 139, in training_loop
    network_pkl = misc.locate_network_pkl(resume_run_id, resume_snapshot)
  File "/trainman-mount/trainman-storage-06c5b4b4-59b3-49f3-a31f-f513d0a7f027/2021_work/DiscoFaceGAN/training/misc.py", line 135, in locate_network_pkl
    pkls = list_network_pkls(run_id_or_run_dir_or_network_pkl)
  File "/trainman-mount/trainman-storage-06c5b4b4-59b3-49f3-a31f-f513d0a7f027/2021_work/DiscoFaceGAN/training/misc.py", line 118, in list_network_pkls
    run_dir = locate_run_dir(run_id_or_run_dir)
  File "/trainman-mount/trainman-storage-06c5b4b4-59b3-49f3-a31f-f513d0a7f027/2021_work/DiscoFaceGAN/training/misc.py", line 115, in locate_run_dir
    raise IOError('Cannot locate result subdir for run', run_id_or_run_dir)
OSError: [Errno Cannot locate result subdir for run] 87

Could you help me with this? Thanks!

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.