PaddleNLP ppdiffusers 自动生成兔了个兔海报
2023-01-18 16:07:35 来源:易采站长站 作者:
目录欢欢喜喜辞旧岁
目录
欢欢喜喜辞旧岁下载PaddleNLP
安装PaddleNLP
重启notebook
安装ppdiffusers
diffusion文图生成
选定diffusion模型
图片生成
海报合成
查看海报
欢欢喜喜辞旧岁
辞旧迎新之际,来 AI Studio 一起 #欢喜迎兔年# !分享不同新年风俗,共享一段快乐时光!
p>下面就开始我们的海报之旅
下载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文图生成
选定diwww.cppcns.comffusion模型
下面推荐了部分二次元模型,想要了解更多的模型可以 点开这里的链接!
%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()
以上就是PaddleNLP ppdiffusers 自动生成兔了个兔海报的详细内容,更多关于PaddleNLP ppdiffusers生成海报的资料请关注我们其它相关文章!
如有侵权,请发邮件到 [email protected]
最新图文推荐
相关文章
-
Pycharm永久激活教程(适用jetbrains全系列产品:Pycharm、Idea、WebStor
一.激活前注意事项 1.PyCharm尽量在官网下载:https://www.jetbrains.com/pycharm/download/ 2.本教程适用于PyCharm所有版本 3.本教程适用于jetbrains全系列产品(Pycharm、Idea、WebStorm、phpstorm、CLion、Rub2020-06-26
-
python+opencv+caffe+摄像头做目标检测的实例代码
首先之前已经成功的使用Python做图像的目标检测,这回因为项目最终是需要用摄像头的, 所以实现摄像头获取图像,并且用Python调用CAFFE接口来实现目标识别 首先是摄像头请选择支持2020-06-22
-
pycharm中导入模块错误时提示Try to run this command from the system ter
pycharm中导入模块错误时,提示:Try to run this command from the system terminal. Make sure that you use the correct version of ‘pip' installed for your Python interpreter located atpycharm工作路径。 安装好pycharm,而且2020-03-26
-
Python如何爬取微信公众号文章和评论(基于 Fiddler 抓包分析)
背景说明 感觉微信公众号算得是比较难爬的平台之一,不过一番折腾之后还是小有收获的。没有用Scrapy(估计爬太快也有反爬限制),但后面会开始整理写一些实战出来。简单介绍下本次2020-06-19