更多精彩内容,欢迎观看:
探索 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 如何想出好的prompt:https://stable-diffusion-art.com/how-to-come-up-with-good-prompts-for-ai-image-generation/#Some_good_keywords_for_you
- 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 下载inpaiting模型;
- 2 可以生成图片后点击send img2img,也可以自己上传到img2img;
- 3 用刷子进行绘制想要修改的区域,刷完之后,重新生成。
其中的一些参数:
模型记得选择SDv1.5修复模型(sd-v1-5-inpainting.ckpt)。
- 训练自己的模型?
可以直接在Colab云端训练,本地也不用配置环境,训练也很快:
想在本地训练:
- 1 确定要训练模型的唯一标识(起个名字),以及这个模型所对应的类型(class);
比如如果想要训练一个狗的模型,那么狗就是对应的类型(class),然后可以给这个狗起一个名字。名字尽量不要太容易重复;
- 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 text cfg: 越大代表生成的内容越接近我们的文字描述
- 2 image cfg: 越大代表越接近我们的原始图片,越小代表可以越不按照原始图片生成
下面是一些常用的指令模板:
- Change the Style to (an artist or style name)
- Have her/him (doing something)
- Make her/him look like (an object or person)
- Turn the (something in the photo) into a (new object)
- Add a (object)
- Add a (object) on (something in the photo)
- Replace the (object) with (another object)
- Put them in (a scene or background)
- Make it (a place, background or weather)
- Apply (a emotion or something on a person)
有时候重新表达指令可以改善结果(例如,“turn him into a dog”与“make him a dog”与“as a dog”)。 增加 steps 的值有时可以改善结果。 人脸看起来奇怪? Stable Diffusion自编码器在图像中人脸较小的情况下会有问题。尝试:裁剪图像,使人脸在画面中占据更大的部分。
资料地址:
- 模型下载地址:https://huggingface.co/timbrooks/instruct-pix2pix/resolve/main/instruct-pix2pix-00-22000.ckpt
- 线上体验地址: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主要用在女性身材生成上比较擅长: |
微调模型 |
Lora iu |
默认是SD模型,可以下载这个模型,F222主要用在女性身材生成上比较擅长: |
我做的事情:
- 1 下载并使用F222模型;
- 2 参考其他水底美女提示符,修改人物生成要用的人物;
- 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