在此存储库中,我们基于 Pytorch 实现了论文的完整训练/推理管道,并提供了几个可用于重现论文中报告结果的演示。使用代码,您还可以按照以下说明尝试自己的数据。
我们代码中 sinkhorn 损失的实现部分改编自SinkhornAutoDiff项目。
[hidecontent type="logged" desc="隐藏内容:登录后可查看"]
现在支持 PyTorch-CPU 模式!您可以在没有任何 GPU 卡的情况下在本地机器上试用。
我们提供了一些轻量级渲染器,用户现在可以在其中轻松生成具有更多笔画细节的高分辨率绘画。使用轻量级渲染,渲染速度也提高了很多(快了 3 倍)。此更新还解决了在内存有限(例如 4GB)的 GPU 卡上运行我们的演示时内存不足的问题。
请查看以下内容了解更多详情。
请参阅Requirements.txt。
git clone https://github.com/jiupinjia/stylized-neural-painting.git
cd stylized-neural-painting
unzip checkpoints_G_oilpaintbrush.zip
unzip checkpoints_G_rectangle.zip
unzip checkpoints_G_markerpen.zip
unzip checkpoints_G_watercolor.zip
unzip checkpoints_G_oilpaintbrush_light.zip
unzip checkpoints_G_rectangle_light.zip
unzip checkpoints_G_markerpen_light.zip
unzip checkpoints_G_watercolor_light.zip
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 --net_G zou-fusion-net
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_light --net_G zou-fusion-net-light
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 --net_G zou-fusion-net
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 --net_G zou-fusion-net
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_light --net_G zou-fusion-net-light
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 --net_G zou-fusion-net
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 --net_G zou-fusion-net --output_dir ./output
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' --net_G zou-fusion-net --renderer_checkpoint_dir checkpoints_G_oilpaintbrush --transfer_mode 1
您还可以指定 --transfer_mode(0:仅传输颜色,1:传输颜色和纹理)
另外请注意,在当前版本中,渐进式渲染模式不支持样式转换。我们将在不久的将来开发此功能。
python demo_8bitart.py --img_path ./test_images/monalisa.jpg --canvas_color 'black' --max_m_strokes 300 --max_divide 4
如果您想通过 ssh 远程运行并且没有安装 X-display 之类的东西,您将需要 --disable_preview 在运行时关闭 cv2.imshow。
python demo_prog.py --disable_preview
在这里,我们还提供了我们方法的推理运行时的最小工作示例。查看以下运行时并在 Colab 上查看结果。
Colab Runtime 1:图像到绘画的翻译(渐进式渲染)
Colab Runtime 2:具有图像风格转换的图像到绘画翻译
您还可以选择画笔类型并从头开始训练笔划渲染器。唯一要做的就是运行以下命令。在训练期间,地面实况笔划是即时生成的,因此您无需下载任何外部数据集。
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
[/hidecontent]