Coder Social home page Coder Social logo

unpaired-portrait-drawing's Introduction

Unpaired Portrait Drawing Generation via Asymmetric Cycle Mapping

We provide PyTorch implementations for our CVPR 2020 paper "Unpaired Portrait Drawing Generation via Asymmetric Cycle Mapping". paper, suppl.

This project generates multi-style artistic portrait drawings from face photos using a GAN-based model.

[Jittor implementation]

Our Proposed Framework

Sample Results

From left to right: input, output(style1), output(style2), output(style3)

Prerequisites

  • Linux or macOS
  • Python 3
  • CPU or NVIDIA GPU + CUDA CuDNN

Installation

  • To install the dependencies, run
pip install -r requirements.txt

Colab

A colab demo is here.

Test steps (apply a pretrained model)

    1. Download pre-trained models from BaiduYun(extract code:c9h7) or GoogleDrive and rename the folder to checkpoints.
    1. Test for example photos: generate artistic portrait drawings for example photos in the folder ./examples using
# with GPU
python test_seq_style.py
# without GPU
python test_seq_style.py --gpu -1

The test results will be saved to a html file here: ./results/pretrained/test_200/index3styles.html. The result images are saved in ./results/pretrained/test_200/images3styles, where real, fake1, fake2, fake3 correspond to input face photo, style1 drawing, style2 drawing, style3 drawing respectively.

    1. To test on your own photos: First use an image editor to crop the face region of your photo (or use an optional preprocess here). Then specify the folder that contains test photos using option --dataroot, specify save folder name using option --savefolder and run the above command again:
# with GPU
python test_seq_style.py --dataroot [input_folder] --savefolder [save_folder_name]
# without GPU
python test_seq_style.py --gpu -1 --dataroot [input_folder] --savefolder [save_folder_name]
# E.g.
python test_seq_style.py --gpu -1 --dataroot ./imgs/test1 --savefolder 3styles_test1

The test results will be saved to a html file here: ./results/pretrained/test_200/index[save_folder_name].html. The result images are saved in ./results/pretrained/test_200/images[save_folder_name]. An example html screenshot is shown below:

You can contact email [email protected] for any questions.

Train steps

    1. Prepare for the dataset: 1) download face photos and portrait drawings from internet (e.g. resources). 2) align, crop photos and drawings & 3) prepare nose, eyes, lips masks according to preprocess instructions. 3) put aligned photos under ./datasets/portrait_drawing/train/A, aligned drawings under ./datasets/portrait_drawing/train/B, masks under A_nose,A_eyes,A_lips,B_nose,B_eyes,B_lips respectively.
    1. Train a 3-class style classifier and extract the 3-dim style feature (according to paper). And save the style feature of each drawing in the training set in .npy format, in folder ./datasets/portrait_drawing/train/B_feat

A subset of our training set is here.

    1. Train our model
sh ./scripts/train.sh

Models are saved in folder checkpoints/portrait_drawing

Citation

If you use this code for your research, please cite our paper.

@inproceedings{YiLLR20,
  title     = {Unpaired Portrait Drawing Generation via Asymmetric Cycle Mapping},
  author    = {Yi, Ran and Liu, Yong-Jin and Lai, Yu-Kun and Rosin, Paul L},
  booktitle = {{IEEE} Conference on Computer Vision and Pattern Recognition (CVPR '20)},
  pages     = {8214--8222},
  year      = {2020}
}

Acknowledgments

Our code is inspired by pytorch-CycleGAN-and-pix2pix.

unpaired-portrait-drawing's People

Contributors

yiranran 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

unpaired-portrait-drawing's Issues

training error

hi I'm trying to train with your provided subset and here is the error:

Original Traceback (most recent call last):
File "/opt/conda/lib/python3.10/site-packages/torch/utils/data/_utils/worker.py", line 308, in _worker_loop
data = fetcher.fetch(index)
File "/opt/conda/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 51, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/opt/conda/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 51, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/jovyan/Unpaired-Portrait-Drawing-master/data/unaligned_mask_stylecls_dataset.py", line 45, in getitem
A_mask_img = Image.open(os.path.join(self.auxdir_A+'_nose',basenA))
File "/opt/conda/lib/python3.10/site-packages/PIL/Image.py", line 3243, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: './portrait_drawing_subset/train/A_nose/inthewild-ia_portrait_10033_resized-checkpoint.png'
what shuld I do?
thank you!

Colab

Your project looks awesome. Thanks for releasing it. It would be great if you mad a Colab file (and link to it in the readme) as an example so that less tech savvy people could play around with it.

about test

你好,我按照requirements配了环境,下载了pre-trained model,执行了readme里的测试代码,但是没有result文件夹生成,如果用test.py测试的话您知道应该用什么代码吗,因为好像涉及很多需要设定的--

Dataset?

In paper "We collect face photos and APDrawings from the Internet and construct a training corpus of 798 face photos and 625 delicate portrait line drawings, and a test set of 154 face photos." is this crawled web dataset available?

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.