论文复现丨基于ModelArts进行图像风格化绘画

时间:2022-12-23 10:17:05
摘要:这个 notebook 基于论文「Stylized Neural Painting, arXiv:2011.08114.」提供了最基本的「图片生成绘画」变换的可复现例子。

本文分享自华为云社区《基于ModelArts进行图像风格化绘画》,作者: HWCloudAI 。

项目首页 | GitHub | 论文

ModelArts 项目地址:https://developer.huaweicloud.com/develop/aigallery/notebook/detail?id=b4e4c533-e0e7-4167-94d0-4d38b9bcfd63

 

下载代码和模型

import os
import moxing as mox
mox.file.copy('obs://obs-aigallery-zc/clf/code/stylized-neural-painting.zip','stylized-neural-painting.zip')
os.system('unzip stylized-neural-painting.zip')
cd stylized-neural-painting
import argparse

import torch
torch.cuda.current_device()
import torch.optim as optim

from painter import *
# 检测运行设备
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
# 配置
parser = argparse.ArgumentParser(description='STYLIZED NEURAL PAINTING')
args = parser.parse_args(args=[])
args.img_path = './test_images/sunflowers.jpg' # 输入图片路径
args.renderer = 'oilpaintbrush' # 渲染器(水彩、马克笔、油画笔刷、矩形) [watercolor, markerpen, oilpaintbrush, rectangle]
args.canvas_color = 'black' # 画布底色 [black, white]
args.canvas_size = 512 # 画布渲染尺寸,单位像素
args.max_m_strokes = 500 # 最大笔划数量
args.m_grid = 5 # 将图片分割为 m_grid x m_grid 的尺寸
args.beta_L1 = 1.0 # L1 loss 权重
args.with_ot_loss = False # 设为 True 以通过 optimal transportation loss 提高收敛。但会降低生成速度
args.beta_ot = 0.1 # optimal transportation loss 权重
args.net_G = 'zou-fusion-net' # 渲染器架构
args.renderer_checkpoint_dir = './checkpoints_G_oilpaintbrush' # 预训练模型路径
args.lr = 0.005 # 笔划搜寻的学习率
args.output_dir = './output' # 输出路径