# Stylized Neural Painting
[Preprint](<https://arxiv.org/abs/2011.08114>) | [Project Page](<https://jiupinjia.github.io/neuralpainter/>) | [Colab Runtime 1](<https://colab.research.google.com/drive/1XwZ4VI12CX2v9561-WD5EJwoSTJPFBbr?usp=sharing/>) | [Colab Runtime 2](<https://colab.research.google.com/drive/1ch_41GtcQNQT1NLOA21vQJ_rQOjjv9D8?usp=sharing/>)
### Official Pytorch implementation of the preprint paper "Stylized Neural Painting", in arXiv:2011.08114.
We propose an image-to-painting translation method that generates vivid and realistic painting artworks with controllable styles. Different from previous image-to-image translation methods that formulate the translation as pixel-wise prediction, we deal with such an artistic creation process in a vectorized environment and produce a sequence of physically meaningful stroke parameters that can be further used for rendering. Since a typical vector render is not differentiable, we design a novel neural renderer which imitates the behavior of the vector renderer and then frame the stroke prediction as a parameter searching process that maximizes the similarity between the input and the rendering output. Experiments show that the paintings generated by our method have a high degree of fidelity in both global appearance and local textures. Our method can be also jointly optimized with neural style transfer that further transfers visual style from other images.

In this repository, we implement the complete training/inference pipeline of our paper based on Pytorch and provide several demos that can be used for reproducing the results reported in our paper. With the code, you can also try on your own data by following the instructions below.
The implementation of the sinkhorn loss in our code is partially adapted from the project [SinkhornAutoDiff](https://github.com/gpeyre/SinkhornAutoDiff).
### License
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title"> Stylized Neural Painting</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://www-personal.umich.edu/~zzhengxi/">Zhengxia Zou</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
### One-min video result
[](https://www.youtube.com/watch?v=oerb-nwrXhk)
## Requirements
See [Requirements.txt](Requirements.txt).
## Setup
1. Clone this repo:
```bash
git clone https://github.com/jiupinjia/stylized-neural-painting.git
cd stylized-neural-painting
```
2. Download one of the pretrained neural renderers from Google Drive (1. [oil-paint brush](https://drive.google.com/file/d/1sqWhgBKqaBJggl2A8sD1bLSq2_B1ScMG/view?usp=sharing), 2. [watercolor ink](https://drive.google.com/file/d/19Yrj15v9kHvWzkK9o_GSZtvQaJPmcRYQ/view?usp=sharing), 3. [marker pen](https://drive.google.com/file/d/1XsjncjlSdQh2dbZ3X1qf1M8pDc8GLbNy/view?usp=sharing), 4. [color tapes](https://drive.google.com/file/d/162ykmRX8TBGVRnJIof8NeqN7cuwwuzIF/view?usp=sharing)), and unzip them to the repo directory.
```bash
unzip checkpoints_G_oilpaintbrush.zip
unzip checkpoints_G_rectangle.zip
unzip checkpoints_G_markerpen.zip
unzip checkpoints_G_watercolor.zip
```
## To produce our results
#### Photo to oil painting

- Progressive rendering
```bash
python demo_prog.py --img_path ./test_images/apple.jpg --canvas_color 'white' --max_m_strokes 500 --max_divide 5 --renderer oilpaintbrush --renderer_checkpoint_dir checkpoints_G_oilpaintbrush
```
- Rendering directly from mxm image grids
```bash
python demo.py --img_path ./test_images/apple.jpg --canvas_color 'white' --max_m_strokes 500 --m_grid 5 --renderer oilpaintbrush --renderer_checkpoint_dir checkpoints_G_oilpaintbrush
```
#### Photo to marker-pen painting

- Progressive rendering
```bash
python demo_prog.py --img_path ./test_images/diamond.jpg --canvas_color 'black' --max_m_strokes 500 --max_divide 5 --renderer markerpen --renderer_checkpoint_dir checkpoints_G_markerpen
```
- Rendering directly from mxm image grids
```bash
python demo.py --img_path ./test_images/diamond.jpg --canvas_color 'black' --max_m_strokes 500 --m_grid 5 --renderer markerpen --renderer_checkpoint_dir checkpoints_G_markerpen
```
#### Style transfer

- First, you need to generate painting and save stroke parameters to output dir
```bash
python demo.py --img_path ./test_images/sunflowers.jpg --canvas_color 'white' --max_m_strokes 500 --m_grid 5 --renderer oilpaintbrush --renderer_checkpoint_dir checkpoints_G_oilpaintbrush --output_dir ./output
```
- Then, choose a style image and run style transfer on the generated stroke parameters
```bash
python demo_nst.py --renderer oilpaintbrush --vector_file ./output/sunflowers_strokes.npz --style_img_path ./style_images/fire.jpg --content_img_path ./test_images/sunflowers.jpg --canvas_color 'white' --renderer_checkpoint_dir checkpoints_G_oilpaintbrush --transfer_mode 1
```
You may also specify the --transfer_mode to switch the transfer mode (0: transfer color only, 1: transfer both color and texture)
Also, please note that in the current version, the style transfer are not supported by the progressive rendering mode. We will be working on this feature in the near future.
#### Generate 8-bit graphic artworks

```bash
python demo_8bitart.py --img_path ./test_images/monalisa.jpg --canvas_color 'black' --max_m_strokes 300 --max_divide 4
```
## Google Colab
Here we also provide a minimal working example of the inference runtime of our method. Check out the following runtimes and see your result on Colab.
[Colab Runtime 1](https://colab.research.google.com/drive/1XwZ4VI12CX2v9561-WD5EJwoSTJPFBbr?usp=sharing/) : Image to painting translation (progressive rendering)
[Colab Runtime 2](https://colab.research.google.com/drive/1ch_41GtcQNQT1NLOA21vQJ_rQOjjv9D8?usp=sharing/) : Image to painting translation with image style transfer
## To retrain your neural renderer
You can also choose a brush type and train the stroke renderer from scratch. The only thing to do is to run the following common. During the training, the ground truth strokes are generated on-the-fly, so you don't need to download any external dataset.
```bash
python train_imitator.py --renderer oilpaintbrush --net_G zou-fusion-net --checkpoint_dir ./checkpoints_G --vis_dir val_out --max_num_epochs 400 --lr 2e-4 --batch_size 64
```
## Citation
If you use this code for your research, please cite our paper:
``````
@inproceedings{zou2020stylized,
title={Stylized Neural Painting},
author={Zhengxia Zou and Tianyang Shi and Shuang Qiu and Yi Yuan and Zhenwei Shi},
year={2020},
eprint={2011.08114},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
``````

龙年行大运
- 粉丝: 1402
- 资源: 3960
最新资源
- 基于多目标优化的物流与冷链车辆路径规划与优化研究:考虑时间窗、成本与碳排放的遗传算法改进及多配送中心策略,基于多目标优化的物流与冷链车辆路径规划与优化算法研究,matlab车辆路径优化vrp,车辆路径
- 零基础入门转录组下游分析-机器学习算法之boruta(筛选特征基因)教程配套资源
- 基于Comsol的三维晶体轴压模拟:应用三维Voronoi算法与泰森多边形晶格分布的模型研究,基于三维Voronoi算法的comsol模型中三维晶体轴压模拟与泰森多边形晶格分布研究,comsol三维晶
- 双极性SPWM单相全桥逆变电路仿真模型:电压电流双闭环控制,直流输入电压范围广泛,输出交流峰值电压可调,高效频率控制技术在1-200hz之间 ,双极性SPWM单相全桥逆变电路仿真模型:电压电流双闭环控
- MATLAB程序实现:多无人船协同围捕控制算法-3船围捕运动船只仿真,距离监控与学习参考,MATLAB程序实现:多无人船协同围捕控制算法-3船围捕运动船只仿真与距离动态调整,MATLAB程序:多个
- QQPinyin QQ拼音输入法安装包版本,主要用于在Windows系统上安装和使用QQ拼音输入法
- log4cplus-2.0.8动态库,静态库
- FX3U定位与气缸FB块直接调用修改范例:新颖写法展现清晰思路,FB块学习宝典 ,FX3U定位与气缸FB块编程范例:开放访问,新颖写法展现清晰思路,FX3U的定位和气缸的FB块,没有密码,可以随便直接
- 2018年世界排名前50的餐厅.zip
- 六电池智能均衡系统:高精度、快速均衡的Buck-Boost电路解决方案,高效电池均衡技术:快速精准调节BuckBoost电路,提升电池性能与寿命,6个电池均衡,buckboost电路,精度高,均衡速度
- 零基础入门转录组下游分析-机器学习算法之boruta(训练模型)教程配套资源
- springboot091创新创业教育中心项目申报管理系统a_zip.zip
- 智能同步控制程序:S7-200 Smart在卷板材生产线与造纸设备的应用,多机同步控制与速度频率同步程序-专为卷板材生产线和造纸设备设计,速度同步频率同步程序 s7-200smart程序 适合卷板材
- 2021年世界幸福指数.zip
- file-download sftp
- MATLAB环境下多领域应用的高效变分模态分解算法优化研究:涵盖金融时间序列、地震微震信号、机械振动等多类信号的处理,MATLAB环境下多领域应用的高效变分模态分解算法优化研究:涵盖金融时间序列、地震
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


