开源
Stylized Neural Painting :AI图像生成水彩绘画
来源:元经纪     阅读:1245
网站管理员
发布于 2023-01-29 09:44
查看主页

概述

我们提出了一种图像到绘画的翻译方法,可以生成具有可控风格的生动逼真的绘画作品。不同于以往将翻译表述为逐像素预测的图像到图像翻译方法,我们在矢量化环境中处理这种艺术创作过程,并生成一系列具有物理意义的笔画参数,这些参数可进一步用于渲染。由于典型的矢量渲染是不可微分的,我们设计了一种新颖的神经渲染器,它模仿矢量渲染器的行为,然后将笔画预测构建为参数搜索过程,最大限度地提高输入和渲染输出之间的相似性。实验表明,我们的方法生成的绘画在全局外观和局部纹理方面都具有高度的保真度。

在此存储库中,我们基于 Pytorch 实现了论文的完整训练/推理管道,并提供了几个可用于重现论文中报告结果的演示。使用代码,您还可以按照以下说明尝试自己的数据。

我们代码中 sinkhorn 损失的实现部分改编自SinkhornAutoDiff项目。

一分钟视频结果

[hidecontent type="logged" desc="隐藏内容:登录后可查看"]

CPU 模式更新(2020 年 11 月 29 日)

现在支持 PyTorch-CPU 模式!您可以在没有任何 GPU 卡的情况下在本地机器上试用。

轻量级渲染器更新(2020 年 11 月 26 日)

我们提供了一些轻量级渲染器,用户现在可以在其中轻松生成具有更多笔画细节的高分辨率绘画。使用轻量级渲染,渲染速度也提高了很多(快了 3 倍)。此更新还解决了在内存有限(例如 4GB)的 GPU 卡上运行我们的演示时内存不足的问题。

请查看以下内容了解更多详情。

要求

请参阅Requirements.txt

设置

  1. 克隆这个回购:
git clone https://github.com/jiupinjia/stylized-neural-painting.git 
cd stylized-neural-painting
  1. 从 Google Drive 下载一种预训练神经渲染器(1.油画笔,2.水彩墨水,3.记号笔,4 .彩色胶带),并将它们解压缩到 repo 目录。
unzip checkpoints_G_oilpaintbrush.zip
unzip checkpoints_G_rectangle.zip
unzip checkpoints_G_markerpen.zip
unzip checkpoints_G_watercolor.zip
  1. 我们还提供了一些轻量级渲染器,用户可以在其 GPU 内存有限的本地机器上生成高分辨率绘画。请随意下载并将它们解压缩到您的 repo 目录。(1.油画笔(轻量),2.水彩墨水(轻量),3.记号笔(轻量),4 .彩色胶带(轻量))。
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
  • 使用轻量级渲染器进行渐进式渲染(具有更低的 GPU 内存消耗和更快的速度)
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
  • 直接从 mxm 图像网格渲染
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
  • 使用轻量级渲染器进行渐进式渲染(具有更低的 GPU 内存消耗和更快的速度)
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
  • 直接从 mxm 图像网格渲染
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:传输颜色和纹理)

另外请注意,在当前版本中,渐进式渲染模式不支持样式转换。我们将在不久的将来开发此功能。

生成 8 位图形作品

python demo_8bitart.py --img_path ./test_images/monalisa.jpg --canvas_color 'black' --max_m_strokes 300 --max_divide 4

通过 SSH 运行

如果您想通过 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]

 
免责声明:本文为用户发表,不代表网站立场,仅供参考,不构成引导等用途。 开源
全面对标Meta Ray-ban!小米首款AI眼镜今日揭晓
方大特钢两项管理创新成果获奖
安兔兔揭晓4月份5000元以上手机性价比排行榜:红魔 10 Pro+一骑绝尘
塔防经典游戏《植物大战僵尸3》iOS端开启预约:定档7月18日
高难度!深圳众擎实现全球首例人形机器人前空翻

首页

分类

定制方案

消息

我的