我正在参与「兔了个兔」构思投稿大赛,详情请看:「兔了个兔」构思投稿大赛
欢欢喜喜辞旧岁
辞旧迎新之际,来 AI Studio 一起 #欢喜迎兔年# !同享不同新年风俗,同享一段快乐韶光!
下面就开端我们的海报之旅
下载PaddleNLP
from IPython.display import clear_output
%cd ~
!git clone -b develop https://github.com/PaddlePaddle/PaddleNLP.git
clear_output() # 整理很长的内容
装置PaddleNLP
%cd ~/PaddleNLP
!pip install -e ./
clear_output() # 整理很长的内容
print('装置结束, 请重启内核')
装置结束, 请重启内核
重启notebook
装置ppdiffusers
%cd ~/PaddleNLP/ppdiffusers/
!pip install -r ~/PaddleNLP/ppdiffusers/requirements.txt
clear_output() # 整理很长的内容
print('装置结束, 请重启内核')
装置结束, 请重启内核
diffusion文图生成
选定diffusion模型
下面引荐了部分二次元模型,想要了解更多的模型可以 点开这里的链接!
ppdiffusers支持的模型称号 | huggingface对应的模型地址 | Tips备注 |
---|---|---|
Linaqruf/anything-v3.0 (引荐!) | huggingface.co/Linaqruf/an… | 二次元模型! |
hakurei/waifu-diffusion-v1-3 (引荐!) | huggingface.co/hakurei/wai… | Waifu v1-3的模型,主要合适画二次元图像!(比照v1-2更好!) |
MoososCap/NOVEL-MODEL (引荐!) | huggingface.co/MoososCap/N… | 二次元模型! |
Baitian/momocha (引荐!) | 无 | 二次元模型! |
Baitian/momoco (引荐!) | 无 | 二次元模型! |
hequanshaguo/monoko-e (引荐!) | 无 | 二次元模型! |
%cd ~/PaddleNLP/ppdiffusers
/home/aistudio/PaddleNLP/ppdiffusers
import paddle
from ppdiffusers import StableDiffusionPipeline
# 加载模型
pipe = StableDiffusionPipeline.from_pretrained("Linaqruf/anything-v3.0")
图片生成
# prompt: 戴眼镜坐在电脑边敲代码穿唐装的兔子, 心爱,大眼睛,高清毛绒
prompt = "rabbit wear glasses beside the computer is writting code in Tang costume for the Spring Festival is cute, big-eyed, high-definition plush"
images = pipe(prompt, guidance_scale=7.5, height=768, width=768)
print(len(images.images))
image = images.images[0]
image.save("/home/aistudio/0.png")
海报合成
%cd ~
import cv2
def merge():
back_img_path = '底图.png'
# 加载底图模板
back_img = cv2.imread(back_img_path, cv2.IMREAD_UNCHANGED) # 捕获图像1
print('底图尺度: ', back_img.shape)
# 加载生成图
fore_img = cv2.imread('0.png', cv2.IMREAD_UNCHANGED)
fore_img = cv2.resize(fore_img, (600, 600))
rows, cols, channels = fore_img.shape
print('生成图尺度: ', fore_img.shape)
dx, dy = 75, 390
print('dx + rows, dy + cols', dx + rows, dy + cols)
print(back_img[dy:dy + cols, dx:dx + rows].shape)
# 合并
back_img[dy:dy + cols, dx:dx + rows] = fore_img
merge_img_path = '海报.png'
# 保存
cv2.imwrite(merge_img_path, back_img)
return merge_img_path
merge()
/home/aistudio
底图尺度: (1334, 750, 3)
生成图尺度: (600, 600, 3)
dx + rows, dy + cols 675 990
(600, 600, 3)
'海报.png'
查看海报
import cv2
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
img = cv2.imread("海报.png", -1)#读取的是bgr格局
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.imshow(img)
plt.show()