![cover](https://img-blog.csdnimg.cn/img_convert/f82298f93d21f7f30e8770abf2c7458e.jpeg)
【PaddlePaddle Hackathon 4】AIGC 诺艾尔生成器
【PaddlePaddle Hackathon 第四期】No.105 作品提交:基于PaddleNLP PPDiffusers 训练诺艾尔生成器,现在支持应用体验,10s一张图!
★★★ 本文源自AlStudio社区精品项目,【点击此处】查看更多精品内容 >>>
赛题链接:https://aistudio.baidu.com/aistudio/competition/detail/860/0/introduction
issue榜单:https://github.com/PaddlePaddle/PaddleNLP/issues/4775
【队名】:一根外向的腿毛
【模型简介】:通过’Neolle with xxxx’的语句生成原神角色诺艾尔的图片,主要集中在面部,例如’Neolle with blue flower’会返回一张带有蓝色花朵的诺艾尔面部图片。
【模型链接】:https://huggingface.co/Liyulingyue/Neolle_Face_Generator
【AI Studio 项目】:https://aistudio.baidu.com/aistudio/projectdetail/5912535
简介
基于 Linaqruf/anything-v3.0 训练,采用DreamBooth的技术并使用a photo of Neolle
文本进行了训练。
用于微调的图片共10张,均为原神角色诺艾尔,batch_size取1,学习率是5e-6,共训练1000步。
提示词通常应该包含Neolle
,一些示例:Noelle with glasses
, Noelle with dark hair, beautiful eyes
, Noelle, queen style
示例
Prompt | num inference steps | guidance scale | 生成结果 |
---|---|---|---|
Noelle with glasses | 50 | 5 | ![]() |
Noelle with sunglasses | 100 | 10 | ![]() |
Noelle with dark hair, beautiful eyes | 50 | 5 | ![]() |
Noelle with dark hair, beautiful eyes | 50 | 5 | ![]() |
Noelle with yellow flowers | 100 | 7.5 | ![]() |
Noelle with blue eyes | 100 | 7.5 | ![]() |
Noelle with long hair | 100 | 7.5 | ![]() |
Noelle, 20 years old | 100 | 10 | ![]() |
Noelle, queen style | 200 | 10 | ![]() |
Noelle in spring | 200 | 2.5 | ![]() |
Noelle in the chair | 50 | 5 | ![]() |
Noelle playing basketball | 50 | 5 | ![]() |
Noelle with ponytail | 100 | 7.5 | ![]() |
Noelle in autumn | 100 | 7.5 | ![]() |
Twins Noelle | 100 | 7.5 | ![]() |
Noelle with cat ears, blue hair | 200 | 10 | ![]() |
快速体验
由于Aistudio不支持保存这么大的模型,必须从hugging face拉取模型到本地,或者从数据集解压。
# 从hugging face拉取权重,不推荐,实在太慢了
# ! git lfs install
# ! git clone https://huggingface.co/Liyulingyue/Neolle_Face_Generator
# 解压权重
! unzip /home/aistudio/data/data208848/dream_outputs.zip -d Neolle_Face_Generator
# 安装依赖
! pip install -U paddlenlp ppdiffusers visualdl safetensors --user
from ppdiffusers import StableDiffusionPipeline
# 加载模型
model_path = "/home/aistudio/Neolle_Face_Generator/dream_outputs"
pipe = StableDiffusionPipeline.from_pretrained(model_path)
# 提示词,生成一个带猫耳,绿色头发的诺艾尔
prompt = "Noelle with cat ears, green hair"
# 生成
image = pipe(prompt, num_inference_steps=50,guidance_scale=10).images[0]
# 保存
image.save("/home/aistudio/test.jpg")
# 展示图片
pg")
# 展示图片
image.show()
0%| | 0/50 [00:00<?, ?it/s]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-9JbPeC2C-1682652734615)(main_files/main_6_1.png)]
训练流程
准备数据
在网上找大约10张左右的岩王帝姬的盛世美颜,在根目录下建立文件夹Neolle
,将找到的图片放在该文件夹下即可。无需调整文件名,文件后缀为.jpg
或者.png
。图片内容尽量保持具有相同特征,例如都是诺艾尔的脸部正面照片,角度各有微小的变化。
本项目虽然附带了一些图片,但是这些图片仅仅能够支撑程序运行,想要复现相同的效果需要自行在网上收集图片。
获取代码
# 拉取paddlenlp的代码
! git clone -b develop https://github.com/PaddlePaddle/PaddleNLP.git
安装库
!pip install -U paddlenlp ppdiffusers visualdl safetensors --user
训练
更多模型和参数参考下述链接,这里采用Linaqruf/anything-v3.0作为基础模型。需要注意,一味的增加数据量和迭代次数不能够起到很好的效果。
https://github.com/PaddlePaddle/PaddleNLP/tree/develop/ppdiffusers
# Linaqruf/anything-v3.0
%cd ~/PaddleNLP/ppdiffusers/examples/dreambooth
! python -u train_dreambooth.py \
--pretrained_model_name_or_path="Linaqruf/anything-v3.0" \
--instance_data_dir="/home/aistudio/Neolle" \
--output_dir="/home/aistudio/dream_outputs" \
--instance_prompt="a photo of Neolle" \
--resolution=512 \
--train_batch_size=1 \
--gradient_accumulation_steps=1 \
--learning_rate=5e-6 \
--lr_scheduler="constant" \
--lr_warmup_steps=0 \
--max_train_steps=1000 \
--random_flip \
--train_text_encoder \
--checkpointing_steps=500
创建预测模型
from ppdiffusers import StableDiffusionPipeline
# 我们所需加载的模型地址,这里我们输入了训练时候使用的 output_dir 地址
model_path = "/home/aistudio/dream_outputs"
pipe = StableDiffusionPipeline.from_pretrained(model_path)
生成图片
需要设定参数共三个
- prompt:提示语
- num_inference_steps: 推理轮次,越高越耗时,能够提高画作结果的精细程度
- guidance_scale:训练图片的影响度,如果无法满足提示词描述的场景,可以降低该值
# 提示词,生成一个带猫耳,绿色头发的诺艾尔
prompt = "Noelle with cat ears, green hair"
# 生成
image = pipe(prompt, num_inference_steps=50,guidance_scale=10).images[0]
# 保存
image.save("/home/aistudio/test.jpg")
# 展示图片
image.show()
0%| | 0/50 [00:00<?, ?it/s]
更多推荐
所有评论(0)