Giter Club home page Giter Club logo

psgan's Introduction

PSGAN

Code for our CVPR 2020 oral paper "PSGAN: Pose and Expression Robust Spatial-Aware GAN for Customizable Makeup Transfer".

Contributed by Wentao Jiang, Si Liu, Chen Gao, Jie Cao, Ran He, Jiashi Feng, Shuicheng Yan.

This code was further modified by Zhaoyi Wan.

In addition to the original algorithm, we added high-resolution face support using Laplace tranformation.

Checklist

  • more results
  • video demos
  • partial makeup transfer example
  • interpolated makeup transfer example
  • inference on GPU
  • training code

Requirements

The code was tested on Ubuntu 16.04, with Python 3.6 and PyTorch 1.5.

For face parsing and landmark detection, we use dlib for fast implementation.

If you are using gpu for inference, do make sure you have gpu support for dlib.

Test

Run python3 demo.py or python3 demo.py --device cuda for gpu inference.

Train

  1. Download training data from link, and move it to sub directory named with "data". (For BaiduYun users, you can download the data here. Password: rtdd)

Your data directory should be looked like:

data
├── images
│   ├── makeup
│   └── non-makeup
├── landmarks
│   ├── makeup
│   └── non-makeup
├── makeup.txt
├── non-makeup.txt
├── segs
│   ├── makeup
│   └── non-makeup
  1. python3 train.py

Detailed configurations can be located and modified in configs/base.yaml, where command-line modification is also supportted.

*Note: * Although multi-GPU training is currently supported, due to the limitation of pytorch data parallel and gpu cost, the numer of adopted gpus and batch size are supposed to be the same.

More Results

MT-Dataset (frontal face images with neutral expression)

MWild-Dataset (images with different poses and expressions)

Video Makeup Transfer (by simply applying PSGAN on each frame)

Citation

Please consider citing this project in your publications if it helps your research. The following is a BibTeX reference. The BibTeX entry requires the url LaTeX package.

@InProceedings{Jiang_2020_CVPR,
  author = {Jiang, Wentao and Liu, Si and Gao, Chen and Cao, Jie and He, Ran and Feng, Jiashi and Yan, Shuicheng},
  title = {PSGAN: Pose and Expression Robust Spatial-Aware GAN for Customizable Makeup Transfer},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
  month = {June},
  year = {2020}
}

@article{liu2021psgan++,
  title={PSGAN++: robust detail-preserving makeup transfer and removal},
  author={Liu, Si and Jiang, Wentao and Gao, Chen and He, Ran and Feng, Jiashi and Li, Bo and Yan, Shuicheng},
  journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
  volume={44},
  number={11},
  pages={8538--8551},
  year={2021},
  publisher={IEEE}
}

Acknowledge

Some of the codes are built upon face-parsing.PyTorch and BeautyGAN.

You are encouraged to submit issues and contribute pull requests.

psgan's People

Contributors

wanzysky avatar wtjiang98 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

psgan's Issues

white spots in the generated image

49_2048_fake

When training with the code of this repo, my generated images always have white spots. Does anyone have the similar results? And how to avoid it?

Thanks

partial makeup example

Thank you for your paper!

The partial makeup method to solve the existing limitations was quite impressive.

Could you please post a specific example or an example code about it?

Histogram Loss Doesn't Match Paper

in the PSGAN paper the makeup loss is denoted as using an l2 loss
image

However, in the implementation an L1 criterion is used.

Which loss is correct?

RuntimeError: 'weight' must be 2-D

I try the project, run it, but error, the notify below. how to fix it?
Traceback (most recent call last):
File "D:\test\PSGAN-master\demo.py", line 72, in
main()
File "D:\test\PSGAN-master\demo.py", line 57, in main
image, face = inference.transfer(source, reference, with_face=True)
File "D:\test\PSGAN-master\psgan\inference.py", line 33, in transfer
source_input, face, crop_face = self.preprocess(source)
File "D:\test\PSGAN-master\psgan\preprocess.py", line 141, in call
mask = self.face_parse.parse(cv2.resize(np_image, (512, 512)))
File "D:\test\PSGAN-master\faceutils\mask\main.py", line 37, in parse
parsing = torch.nn.functional.embedding(parsing, self.dic)
File "D:\test\PSGAN-master\venv\lib\site-packages\torch\nn\functional.py", line 2199, in embedding
return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
RuntimeError: 'weight' must be 2-D

the performance of demo

I tried to run the demo and used some other pictures from the Internet. The results i got are not as good as the paper showed. The eye shadow part cannot be transferred. Should i change the config or train the model by myself to get a better result?

Pre-trained models

hi~ I'm new to this field, I have some issues about training, G.pth in /assets/models, What does it do? I see the codes solver.py have load it, but this folder doesn't include D_A.pth, D_B.pth, it'is necessary to train? I delete G.pth when I train this model, but results still looks good, only adv loss seems no change. sincerely look forward your detailed reply,Thanks.
image

Test result

I tried to run the code for PSGAN, and when I tested it with the G.pth generated by training, the results were very bad.like this.It is quite different from the test results you provided.I don't know what's wrong, so I'm asking for your advice.Please reply to me when you have time. Thank you very much.

learning rate

I find that G_lr and D_lr are 2e-5 in code, but in paper is 2e-4, i guess 2e-5 is to adapt finetune process, because i find when i run the code, the model will load the pretrained model, is that right? thanks.

import dlib ImportError: /usr/lib/libcblas.so.3: undefined symbol: ATL_zger2u

I have installed dlib, but cannot import
$python makeup/main.py
Traceback (most recent call last):
File "makeup/main.py", line 16, in
import faceutils as futils
File "/data00/chengjuntong/PSGAN/makeup/../faceutils/init.py", line 4, in
from . import dlibutils as dlib
File "/data00/chengjuntong/PSGAN/makeup/../faceutils/dlibutils/init.py", line 3, in
from .main import detect, crop, landmarks
File "/data00/chengjuntong/PSGAN/makeup/../faceutils/dlibutils/main.py", line 7, in
import dlib
ImportError: /usr/lib/libcblas.so.3: undefined symbol: ATL_zger2u

Histogram loss on lip and eyes

Hi, thanks for your wonderful works.
When I am trying to implement your code, I found that the histogram loss on lip and eyes are always 0. This issue leads to inaccuracy on makeup transfer of lipstick and eyeshadow. I tried but failed to find out the possible problem in codes. Can you do me a favor? I did not change codes in calculating histogram loss.

G-A-eye-loss-his
G-A-lip-loss-his

Download makeup-wild Dataset

Hi, I tried to get the Makeup-wild dataset, but the link shows that the file was not found, how can I get it again?

Pretrain model

Hello. Thank you for such a great paper. Could you release the pretrained model for the test? Thank you!

PSGAN++

When can psgan + + code be released?

Error occurred when i run demo.py

Traceback (most recent call last):
File "/mnt/sdb/longwei.xu/PSGAN/demo.py", line 72, in
main()
File "/mnt/sdb/longwei.xu/PSGAN/demo.py", line 57, in main
image, face = inference.transfer(source, reference, with_face=True)
File "/mnt/sdb/longwei.xu/PSGAN/psgan/inference.py", line 33, in transfer
source_input, face, crop_face = self.preprocess(source)
File "/mnt/sdb/longwei.xu/PSGAN/psgan/preprocess.py", line 141, in call
mask = self.face_parse.parse(cv2.resize(np_image, (512, 512)))
File "/mnt/sdb/longwei.xu/PSGAN/faceutils/mask/main.py", line 37, in parse
parsing = torch.nn.functional.embedding(parsing, self.dic)
File "/mnt/sdb/longwei.xu/anaconda3/lib/python3.9/site-packages/torch/nn/functional.py", line 2044, in embedding
return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
RuntimeError: 'weight' must be 2-D

parse.shape:
torch.Size([512, 512])
parse
tensor([[ 0, 0, 0, ..., 17, 17, 17],
[ 0, 0, 0, ..., 17, 17, 17],
[ 0, 0, 0, ..., 17, 17, 17],
...,
[17, 17, 17, ..., 16, 16, 16],
[17, 17, 17, ..., 16, 16, 16],
[17, 17, 17, ..., 16, 16, 16]])

Is it possible for higher resolution?

The default resolution is 256. But if there exsisting dataset of high resoluiton such as 512, is it possilbe to train generator that can produce result of high resolution when I change some config and hyperparameter in the code?

Download training dataset

Hi,
I tried to download the dataset in the link that was supplied but it appears that the file has either been removed or that I need some special authentication for it. How can I use this dataset?

Some advice about license compliance

Hello, such a nice repository benefits me a lot and so kind of you to make it open source!

Question
There’s some possible legal issues on the license of your repository when you combine numerous third-party packages.
For instance, torch, numpy and requests you imported are licensed with BSD License, BSD License and Apache Software License, respectively.
However, the MIT License of your repository are less strict than above package licenses, which has violated the whole license compatibility in your repository and may bring legal and financial risks.

Advice
You can select another proper license for your repository, or write a custom license with license exception if some license terms couldn’t be summed up consistently.

Best wishes!

how to get attention map?

Thanks for you excellent works. There has picture about attention map in your paper. I have some questions about this attention weight, but i don't know how to use this weight to visualize attention map at any-point in source image . Could you release this part of the code? Thanks
image

运行时出现以下问题,请问是什么原因?

G:\Anaconda3\python.exe G:/PSGAN-master/makeup/main.py
Traceback (most recent call last):
File "G:/PSGAN-master/makeup/main.py", line 129, in
images = [preprocess(image) for image in images]
File "G:/PSGAN-master/makeup/main.py", line 129, in
images = [preprocess(image) for image in images]
File "G:/PSGAN-master/makeup/main.py", line 69, in preprocess
face = futils.dlib.detect(image)
File "G:\PSGAN-master\faceutils\dlibutils\main.py", line 14, in detect
return detector(np.asarray(image), 1)
RuntimeError: Expected writable numpy.ndarray with shape set.

Process finished with exit code 1

the problem of AMM Module

Thank you for your excellent work!
When I read the code, I find the implementation is not same as paper says. After gamma and beta are calculated, follow the paper, we should do: Vx * gamma + beta, but the code is: Vx * (1 + gamma) * beta, why need this add operation?
Moreover, why after get gamma_s and beta_s, then do gamma_s * mask_s, beta_s * mask_s, i can not find it in the paper.
Thanks, looking forward to your reply.

License

Hi, can you please provide an open source license with the repo?
Thank you!

Smart_Path

Hello @wanzysky and @wtjiang98 ,
during the demo running I found this error:

from smart_path import smart_path
ModuleNotFoundError: No module named 'smart_path'

Error when training data for the model

When i run train.py, an error is shown " layers.append(SpectralNorm(nn.Conv2d(3, conv_dim, kernel_size=4, stride=2, padding=1)))
TypeError: init() takes 1 positional argument but 2 were given
from Net.py file. Seems there is a bug in the code? Thanks.
"

How to get different makeup level?

In the paper, looks like it is mentioned that the result can have different makeup heaviness. Is this implemented in current code version?

landmark and segments file

Hi!

Your project is interesting so I want to train more about the data.

But I have a question because I have no deep knowledge of this field.

If i want to train more data, Should I have to make landmark and segments? ( Is this a necessary file for training? )

And Is it right ? ( segs = segments )

Thanks !

生成的图片不太对

很麻烦再一次打扰您, 我按照readme的教程从头开始训练,迭代了一段时间,发现生成的fake_A总是将脸部变成黑色,请问一下,我是哪里出了什么问题,谢谢。
就比如下面所示:
image

还有我发现在得到weight使用稀疏张量会减慢模型训练速度,是否可以注释掉:

weight = weight[weight_ind[0], weight_ind[1], weight_ind[2]]

ret = torch.sparse.FloatTensor(weight_ind, weight, torch.Size([3, HW, HW]))

y = torch.bmm(weight.to_dense(), g_source)--------> y = torch.bmm(weight, g_source)

[When you plan to commit training code]

Hello @wtjiang98,
Thanks alot for implementing PSGAN. I just wonder when you plan to commit the training code.
I am just very new at GAN in general but I am quite interested in that and plan to implement the training code but I think it will take me along time to finish coding and more importantly make it work as in the paper. But if you will release the training code soon, it is very useful for me to know.
Thanks and sorry because it is not actually an issue

ImportError: cannot import name 'load_state_dict_from_url' from 'torchvision.models.vgg'

When I tried to run demo.py I got the following error.
The problem is that load_state_dict_from_url, model_urls, cfgs were deprecated in more recent version of torchvision.
You can resolve this by changing demo.py in the following way:
replace
from torchvision.models.vgg import load_state_dict_from_url, model_urls, cfgs
with
import torchvision.models as models

and replace

def _vgg(arch, cfg, batch_norm, pretrained, progress, **kwargs):
    if pretrained:
        kwargs['init_weights'] = False
    model = VGG(make_layers(cfgs[cfg], batch_norm=batch_norm), **kwargs)
    if pretrained:
        state_dict = load_state_dict_from_url(model_urls[arch],
                                              progress=progress)
        model.load_state_dict(state_dict)
    return model
def vgg16(pretrained=False, progress=True, **kwargs):
    r"""VGG 16-layer model (configuration "D")
    `"Very Deep Convolutional Networks For Large-Scale Image Recognition" <https://arxiv.org/pdf/1409.1556.pdf>`_

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
        progress (bool): If True, displays a progress bar of the download to stderr
    """
    return _vgg('vgg16', 'D', False, pretrained, progress, **kwargs)

with

def vgg16(pretrained=False, progress=True, **kwargs):
    """
    VGG 16-layer model (configuration "D")
    "Very Deep Convolutional Networks For Large-Scale Image Recognition" <https://arxiv.org/pdf/1409.1556.pdf>

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
        progress (bool): If True, displays a progress bar of the download to stderr
    """
    # The `models.vgg16` function now directly supports loading a pretrained model
    # with the `pretrained` and `progress` arguments.
    model = models.vgg16(pretrained=pretrained, progress=progress, **kwargs)
    return model

I spent a lot of time to figure this out, hopefully someone else will read this and won't loose as much time.

CUDA out of memory

Hello,
I use a RTX2080ti to train the dataset you provided and do not change any code, but an "CUDA out of memory" error occurred in the program. Could you give some help? Thank you !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.