本模型选自Paint by Example, 根据示例图片对原始图片的mask区域进行自适应地替换。
Paint by Example 是基于stable diffusion 模型的一个图像编辑算法,根据示例图片对原始图片的mask区域进行自适应地替换。
本模型适用范围为室外自然场景;
在ModelScope框架上,提供输入图片,即可通过简单的Pipeline调用来使用。
安装好基础modelscope环境后,安装paint-ldm:
pip install paint-ldm -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html
from PIL import Image
import cv2
from modelscope.outputs import OutputKeys
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
input_location = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/image_paint_by_example/image/example_1.png'
input_mask_location = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/image_paint_by_example/mask/example_1.png'
reference_location = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/image_paint_by_example/reference/example_1.jpg'
input = {
'img':input_location,
'mask':input_mask_location,
'reference':reference_location,
}
paintbyexample = pipeline(Tasks.image_paintbyexample, model='damo/cv_stable-diffusion_paint-by-example')
result = paintbyexample(input)
vis_img = result[OutputKeys.OUTPUT_IMG]
cv2.imwrite("result.png", vis_img)
如果你觉得这个该模型对有所帮助,请考虑引用下面的相关的论文:
@article{yang2022paint,
title={Paint by Example: Exemplar-based Image Editing with Diffusion Models},
author={Binxin Yang and Shuyang Gu and Bo Zhang and Ting Zhang and Xuejin Chen and Xiaoyan Sun and Dong Chen and Fang Wen},
journal={arXiv preprint arXiv:2211.13227},
year={2022}
}