探索 StableDiffusion:生成高质量图片学习及应用(中)

简介: 探索 StableDiffusion:生成高质量图片学习及应用(中)

更多精彩内容,欢迎观看:

探索 StableDiffusion:生成高质量图片学习及应用(上):

https://developer.aliyun.com/article/1263239?groupCode=taobaotech


  • 一些参考prompt


negtive提示符:


ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, bad anatomy, watermark, signature, cut off, low contrast, underexposed, overexposed, bad art, beginner, amateur, distorted face

((((ugly)))), (((duplicate))), ((morbid)), ((mutilated)), [out of frame], extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), ((ugly)), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))), out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), (((long neck)))


  1. 1 如何想出好的prompt:https://stable-diffusion-art.com/how-to-come-up-with-good-prompts-for-ai-image-generation/#Some_good_keywords_for_you
  2. 2负面提示符:https://stable-diffusion-art.com/how-to-use-negative-prompts/#Negative_prompt_with_Stable_Diffusion_v15


 生成高质量的图片进阶?


  • 图片修复 (inpaiting)


https://stable-diffusion-art.com/inpainting-remove-extra-limbs/

  1. 1 下载inpaiting模型;
  2. 2 可以生成图片后点击send img2img,也可以自己上传到img2img;
  3. 3 用刷子进行绘制想要修改的区域,刷完之后,重新生成。


其中的一些参数:


模型记得选择SDv1.5修复模型(sd-v1-5-inpainting.ckpt)。


  • 训练自己的模型?


可以直接在Colab云端训练,本地也不用配置环境,训练也很快:

https://colab.research.google.com/github/Linaqruf/kohya-trainer/blob/main/kohya-LoRA-dreambooth.ipynb#scrollTo=WNn0g1pnHfk5


想在本地训练:

  1. 参考:https://github.com/bmaltais/kohya_ss
  2. 训练教程:https://stable-diffusion-art.com/dreambooth/


  1. 1 确定要训练模型的唯一标识(起个名字),以及这个模型所对应的类型(class);
比如如果想要训练一个狗的模型,那么狗就是对应的类型(class),然后可以给这个狗起一个名字。名字尽量不要太容易重复;
  1. 2 准备把图片制作有有固定尺寸,创建一个目录:_一次可以训练多个概念
  2. 3 开始训练、选择在colab上训练是最方便的方式,本地就省去了很多配置。
    以上要准备的内容简单说就是:图片、类型、唯一名字
    https://colab.research.google.com/github/Linaqruf/kohya-trainer/blob/main/kohya-LoRA-dreambooth.ipynb#scrollTo=kh7CeDqK4l3Y


按照colab正常操作就行;最终会输出一份训练的模型到你的Google Driver中。然后自己在本地测试:

prompt:a woman, hitokomoru , with a cat on her head  

negtive: (worst quality:2), (low quality:2),disfigured, ugly, old, wrong finger


使用自己的Lora VS  不使用Lora

还有一次可以训练多个概念,把文件件组织好就行了


  • 图片编辑 pix2pix


编辑配置文件configs/instruct-pix2pix.yaml,改为如下内容:



use_ema: true   // 默认为false    load_ema: true


denoising 改为1.0, 抽样使用Euler a算法;

常用参数:

  1. 1 text cfg: 越大代表生成的内容越接近我们的文字描述
  2. 2 image cfg:  越大代表越接近我们的原始图片,越小代表可以越不按照原始图片生成


下面是一些常用的指令模板:

  1. Change the Style to (an artist or style name)
  2. Have her/him (doing something)
  3. Make her/him look like (an object or person)
  4. Turn the (something in the photo) into a (new object)
  5. Add a (object)
  6. Add a (object) on (something in the photo)
  7. Replace the (object) with (another object)
  8. Put them in (a scene or background)
  9. Make it (a place, background or weather)
  10. Apply (a emotion or something on a person)


有时候重新表达指令可以改善结果(例如,“turn him into a dog”与“make him a dog”与“as a dog”)。 增加 steps 的值有时可以改善结果。 人脸看起来奇怪? Stable Diffusion自编码器在图像中人脸较小的情况下会有问题。尝试:裁剪图像,使人脸在画面中占据更大的部分。


资料地址:

  1. 模型下载地址:https://huggingface.co/timbrooks/instruct-pix2pix/resolve/main/instruct-pix2pix-00-22000.ckpt
  2. 线上体验地址:https://huggingface.co/spaces/timbrooks/instruct-pix2pix


  • 使用脚本


Stable Diffusion的webUI中默认有一些脚本,可以方便我们尝试一些不同的生成方式。

  • 常见生成人物问题与处理


 StableDiffusion生成图片演示


  • 水底美女文字生成 text2img


水下摄影肖像,iu1,裙子,美丽的详细女孩,极其详细的眼睛和脸,美丽的详细眼睛,闭着嘴,黑色的头发,锁骨,裸露的肩膀,长睫毛,飘逸的头发,气泡,阳光穿过水面,逼真,照片般的真实感,由泰德·格兰博拍摄,最高品质。

正面提示:underwater photography portrait,  iu1, dress, beautiful detailed girl, extremely detailed eyes and face, beautiful detailed eyes, closed mouth, black hair, collarbone, bare shoulders, longeyelashes, floating hair,  bubbles,  sun light breaking through water surface, realistic, photorealistic, by ted grambeau, best quality


反面提示:(worst quality:2), (low quality:2), (normal quality:2) , goggles, sun glasses, hand, extra fingers, fewer fingers, strange fingers, bad hand



参数

参数说明

CFG scale

8

值越大,越符合你的prompt,范围为1~30;默认为7.


个人测试:

5以下看起来不好看

Sampling steps

20

理论上越大,图片质量越高,但是可能会带来模糊

Image size

512×512


Seed

-1

Face restoration

Codeformer

勾选面部修复

Sampling method

DPM++ 2M Karas


Model

F222

默认是SD模型,可以下载这个模型,F222主要用在女性身材生成上比较擅长:

https://huggingface.co/acheong08/f222/blob/main/f222.ckpt

微调模型

Lora iu

https://civitai.com/models/11722/iu

默认是SD模型,可以下载这个模型,F222主要用在女性身材生成上比较擅长:

https://huggingface.co/acheong08/f222/blob/main/f222.ckt


我做的事情:

  1. 1 下载并使用F222模型;
  2. 2 参考其他水底美女提示符,修改人物生成要用的人物;
  3. 3 微调提示符,多次生成;


  • 西湖风景后期处理 img2img


原始照片:

生成prompt:

第一张prompt: ((Sunset)) , (Lake  Gold) , Boat Center, Mountain, Tree in left, realistic, photorealistic, , 8K,Wide-angle, (expansive:1.5) , a combination of red, orange, pink, and purple.

negtive: (worst quality:2), (low quality:2)


第二张:a sunset over a body of water with a tree branch hanging over it and the sun reflecting in the water, a photo, Arthur Pan, dau-al-set, tranquil


第三张:two ducks swimming in a pond with fish in the water and a fish in the water behind them,, an impressionist painting, Emperor Huizong of Song, cloisonnism, tone mapping


第四张:a field of colorful flowers with green stems and yellow and red flowers in the middle of the field,, a jigsaw puzzle, Bob Thompson, color field, rich vivid colors



  • 人像卡通化测试 img2img


prompt:a young man holding a durian fruit in his hand , portrait ,detailed eyes, hyperrealistic

negtive prompt:  (worst quality:2), (low quality:2),disfigured, ugly, old

模型:AnythingV3;


Denoising strength从0.1依次升高,第一张为原图;


Denoising strength: 0.4~0.7(可以看到从0.5的噪声强度开始,AI已经开始自由发挥了,虽然也会参考原图)

Denoising strength: 0.8~0.9 (基本完全自由发挥)


依旧是上个原图,换为midjourney v4模型,Denoising strength测试0.2, 0.4, 0.6, 0.8相同的提示词,换个模型之后整体风格大变;

  • 图片编辑测试  pix2pix


TextCFG固定:7.5,调整ImageCFG;


Put him in beach



  • 控制人物姿势 ControlNet


提示:A girl, showing her muscles, detailed face , realistic ,8k  

negtive prompht: (worst quality:2), (low quality:2),disfigured, ugly, old,nsfw


除了控制姿势,还可以控制人物的表情,这里我们只是控制人物的姿势;


  • 图片Inpaiting测试  img2img



给“模特”戴项链:


A girl, (necklace:1.5), showing her muscles, detailed face , realistic ,8k  


给“模特”戴墨镜:

A girl, (sunglasses:1.5), showing her muscles, detailed face , realistic ,8k  


更多精彩内容,欢迎观看:

探索 StableDiffusion:生成高质量图片学习及应用(下):

https://developer.aliyun.com/article/1263237?groupCode=taobaotech




相关文章
|
9月前
|
人工智能 自然语言处理 前端开发
AI 绘画Stable Diffusion 研究(十)sd图生图功能详解-精美二维码的制作
AI 绘画Stable Diffusion 研究(十)sd图生图功能详解-精美二维码的制作
661 1
|
2天前
|
人工智能 编解码 内存技术
手把手教你生成一幅好看的AI图片
想要生成一幅好看的AI图片,但是却不知道如何下手?只会1girl的你现在是不是很烦恼?别急,看这篇文章就够了。
手把手教你生成一幅好看的AI图片
|
24天前
|
机器学习/深度学习 PyTorch 算法框架/工具
【从零开始学习深度学习】47. Pytorch图片样式迁移实战:将一张图片样式迁移至另一张图片,创作自己喜欢风格的图片【含完整源码】
【从零开始学习深度学习】47. Pytorch图片样式迁移实战:将一张图片样式迁移至另一张图片,创作自己喜欢风格的图片【含完整源码】
|
2月前
|
人工智能
MidJourney以图生图的详细教程(含6种案例介绍)(下)
MidJourney以图生图的详细教程(含6种案例介绍)
|
2月前
|
人工智能
MidJourney以图生图的详细教程(含6种案例介绍)(上)
MidJourney以图生图的详细教程(含6种案例介绍)
|
9月前
|
机器学习/深度学习
基于Aidlux的图片相似度对比
利用深度神经网络,提取印章深度特征,同时学习印章之间的相似度,自己与自己相似,自己与其它不相似。
|
2月前
|
存储 人工智能 算法
基于向量检索服务与ModelScope模型搭建文本搜图片---魏红斌版
【1月更文挑战第9天】综合产品理解和实操经验,总结向量检索服务的综合水平
98876 4
基于向量检索服务与ModelScope模型搭建文本搜图片---魏红斌版
|
2月前
|
机器学习/深度学习 人工智能 Cloud Native
秒速出图!体验 TensorRT 加速 Stable Diffusion 图像创作
秒速出图!体验 TensorRT 加速 Stable Diffusion 图像创作
140335 14
|
2月前
Midjourney如何使用
Midjourney如何使用
84 0
|
9月前
|
SQL 弹性计算 人工智能
文生图-AIGC:在云上从0开始搭建Stable Diffusion文生图Streamlit网页版
本文描述在阿里云上从0开始构建个人的文生图应用。网页采用streamlit实现,文生图模型使用了阿里云Lindorm AI数据服务平台上部署Stable Diffusion来实现。 Streamlit使用起来非常简便,可以让开发者快速(短则几十分钟即可)搭建一个具备公网访问能力的网页。尤其在人工智能开发上,可使用Streamlit快速搭建应用环境,让开发人员将更多精力集中在人工智能本身,本文从0开始详细讲解整个应用的构建过程,代码实现了一个简洁的具备公网访问能力的网页版文生图应用。