1 Star 0 Fork 104

于斌 / PaddleGAN

forked from PaddlePaddle / PaddleGAN 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
lap_style.md 6.51 KB
一键复制 编辑 原始数据 按行查看 历史
wangna11BD 提交于 2021-11-30 09:33 . fix lapstyle runtime (#502)

LapStyle

This repo holds the official codes of paper: "Drafting and Revision: Laplacian Pyramid Network for Fast High-Quality Artistic Style Transfer", which is accepted in CVPR 2021.

1 Paper Introduction

Artistic style transfer aims at migrating the style from an example image to a content image. Currently, optimization- based methods have achieved great stylization quality, but expensive time cost restricts their practical applications. Meanwhile, feed-forward methods still fail to synthesize complex style, especially when holistic global and local patterns exist. Inspired by the common painting process ofdrawing a draft and revising the details, this paper introduce a novel feed- forward method Laplacian Pyramid Network (LapStyle). LapStyle first transfers global style pattern in low-resolution via a Drafting Network. It then revises the local details in high-resolution via a Revision Network, which hallucinates a residual image according to the draft and the image textures extracted by Laplacian filtering. Higher resolution details can be easily generated by stacking Revision Networks with multiple Laplacian pyramid levels. The final stylized image is obtained by aggregating outputs ofall pyramid levels. We also introduce a patch discriminator to better learn local pattern adversarially. Experiments demonstrate that our method can synthesize high quality stylized images in real time, where holistic style patterns are properly transferred.

lapstyle_overview

2 Quick experience

Here four style images: | StarryNew | Stars | Ocean | Circuit|

python applications/tools/lapstyle.py --content_img_path ${PATH_OF_CONTENT_IMG} --style_image_path ${PATH_OF_STYLE_IMG}

Parameters

  • --content_img_path (str): path to content image.
  • --style_image_path (str): path to style image.
  • --output_path (str): path to output image dir, default value:output_dir.
  • --weight_path (str): path to model weight path, if weight_path is None, the pre-training model will be downloaded automatically, default value:None.
  • --style (str): style of output image, if weight_path is None, style can be chosen in starrynew, circuit, ocean and stars, default value:starrynew.

3 How to use

3.1 Prepare Datasets

To train LapStyle, we use the COCO dataset as content image set. You can choose one style image from starrynew, ocean, stars or circuit. Or you can choose any style image you like. Before training or testing, remember modify the data path of style image in the config file.

3.2 Train

Datasets used in example is COCO, you can also change it to your own dataset in the config file.

Note that train of lapstyle model does not currently support Windows system.

(1) Train the Draft Network of LapStyle under 128*128 resolution:

python -u tools/main.py --config-file configs/lapstyle_draft.yaml

(2) Then, train the Revision Network of LapStyle under 256*256 resolution:

python -u tools/main.py --config-file configs/lapstyle_rev_first.yaml --load ${PATH_OF_LAST_STAGE_WEIGHT}

(3) Further, you can train the second Revision Network under 512*512 resolution:

python -u tools/main.py --config-file configs/lapstyle_rev_second.yaml --load ${PATH_OF_LAST_STAGE_WEIGHT}

3.4 Test

When testing, you need to change the parameter validate/save_img in the configuration file to true to save the output image. To test the trained model, you can directly test the "lapstyle_rev_second", since it also contains the trained weight of previous stages:

python tools/main.py --config-file configs/lapstyle_rev_second.yaml --evaluate-only --load ${PATH_OF_WEIGHT}

4 Results

Style Stylized Results
starrynew chicago_stylized_starrynew
ocean chicago_ocean_512
stars chicago_stylized_stars_512
circuit chicago_stylized_circuit

5 Pre-trained models

We also provide several trained models.

model style path
lapstyle_circuit circuit lapstyle_circuit
lapstyle_ocean ocean lapstyle_ocean
lapstyle_starrynew starrynew lapstyle_starrynew
lapstyle_stars stars lapstyle_stars

References

@article{lin2021drafting,
  title={Drafting and Revision: Laplacian Pyramid Network for Fast High-Quality Artistic Style Transfer},
  author={Lin, Tianwei and Ma, Zhuoqi and Li, Fu and He, Dongliang and Li, Xin and Ding, Errui and Wang, Nannan and Li, Jie and Gao, Xinbo},
  booktitle={Computer Vision and Pattern Recognition (CVPR)},
  year={2021}
}
Python
1
https://gitee.com/ybinu/PaddleGAN.git
git@gitee.com:ybinu/PaddleGAN.git
ybinu
PaddleGAN
PaddleGAN
develop

搜索帮助