分享

凡人修仙路之炼器:AI绘画篇(Chapter 03)

 看云舒云卷c 2024-02-26 发布于广东

成长陪伴分享(2022年11月20日)

如无特别注明,所有的绘图均由AI克罗索自动生成。

所有的图片版权归AI的所有者侯Plus所有,可以引用或者学习使用但未经允许不得商用。

Abstract

我的炼丹炉是Stable Diffusion webUI人工智能绘画框架(简称SDwebui)。

感谢开源社区无私的贡献在每一个无产阶级兄弟的心中播下了社会主义的种子。

感谢Stable Diffusion webUI人工智能绘画框架的作者AUTOMATIC1111给我们分享了他的智慧。

让资本家们控制AI机器人的战略规划又一次遭到了致命的打击。

整个凡人修仙路——AI绘画篇由:

炼丹卷(初级炼丹术、中级炼丹术、高级炼丹术),铸炉卷,咒语卷三卷组成。

SDwebui的人机交互是采用的NLP,自然语言处理技术,通过输入单词、词语或者句子来生成图片。

SDwebui封装的NLP模块是使用的danbooru.donmai.us。

它是SDwebui框架神经网络的重要训练来源。

占了绝大多数的关键词(超过80%)的tag都是来源于此。

真正的修真者必然是一位英语较好(不要求英语的听、说、写)。

至少具备能阅读并理解相关英语论文技能的人。

一位大炼丹师,必然能熟练运用英语中的各类生动表达方式。

能够理解一些场景专业术语与服装术语。

能够直接应用合规的英文单词进行大段叙述描写。

所以修仙的基础就是英语,学好英语是每一位修真者的必修课。

模特是克罗索,请大家多多关照

Chapter I —— Beginning

在我们搭建完了炼丹炉之后,就要开始第一次炼丹了。

在开始炼丹之前,我们要对我们的炼丹炉做一次全方位的优化。

AI的发展现在基本是每周一次小更新,半个月一次大更新。

所以第一件事就是拿到最新的炼丹法门,一般而言一个月前发布的软件框架版本已经过保质期,没有安装的价值。

一名真正的修真者必然会追求事物的圆融,思想的通达。

我们的炼丹炉能用4090显卡,肯定不会上4080显卡。

如果你采用的是单独安装框架和依赖的话,需要安装最新的xformers、pytorch和cuda版本。

进入python目录命令行,或者激活虚拟环境,升级代码如下:

python -m pip install -U -I --no-deps https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/f/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whlpython -m pip install torch==1.13.0+cu117 torchvision==0.14.0+cu117 --extra-index-url https://download.pytorch.org/whl/cu117

如果你采用的是一键安装版本,那么需要手动更新cudnn,下载链接如下:

[百度网盘]    https://pan.baidu.com/s/1ClegOfTZ0r_B1XXBmmt_Cw?pwd=cqcw 

将下载的cudnn文件替换一键安装版中python目录:python\Lib\site-packages\torch\lib下的文件。

优化前4090出图速度和3090差不多,优化后4090的出图速度比3090快400%左右。

Chapter II —— Preparing

在txt2img中输入我们的炼丹咒语prompt就能让我们的AI开始炼丹,炼出我们的第一副作品了。

首先我们要对AI框架做基础的设置。

在settings中的Saving images/grids,选择:

  • Add extended info (seed, prompt) to filename when saving grid

  • Do not save grids consisting of one picture

  • Save text information about generation parameters as chunks to png files(输出的png图片包含tags信息)

在settings中的Stable Diffusion,选择:

  • Apply color correction to img2img results to match original colors.

  • Emphasis: use (text) to make model pay more attention to text and [text] to make it pay less attention(开启括号权重)

  • Filter NSFW content(过滤r18内容)

  • Increase coherency by padding from the last comma within n tokens when using more than 75 tokens:20

  • Stop At last layers of CLIP model:2(重要设置)

在settings中的Interrogate Options,选择:

  • Interrogate: use artists from artists.csv

  • Interrogate: num_beams for BLIP:1

  • Interrogate: minimum description length (excluding artists, etc..):24

  • Interrogate: maximum description length:128

  • CLIP: maximum number of lines in text file (0 = No limit):1500

  • Interrogate: deepbooru score threshold:0.5

  • Interrogate: deepbooru sort alphabetically

  • escape () brackets in deepbooru (so they are used as literal brackets and not for emphasis)

在settings中的User interface,选择:

  • Show progressbar

  • Show grid in results for web

  • Add model hash to generation information

  • Send seed when sending prompt or image to other interface

  • Enable full page image viewer

  • Show images zoomed in by default in full page image viewer

  • Show generation progress in window title.

  • Quicksettings list:sd_model_checkpoint

在settings中的Sampler parameters,选择:

  • eta (noise multiplier) for DDIM:0

  • img2img DDIM discretize:uniform

  • sigma churn:0

  • sigma tmin:0

  • sigma noise:1

  • Eta noise seed delta:31337(重要设置)

接下来就是构建我们的第一张图片。

来到txt2img页面,分为:

  • Prompt区域(文生图)

  • Sampling Steps(出图调参)

Prompt区域(文生图)

分为prompt(正面咒语)和negative prompt(反面咒语)。

顾名思义,正面咒语就是我们的出图要包含的内容,反面咒语就是我们的出图不包含什么内容。

这里我介绍一下我的通用基础咒语,大家可以拿去作为自己的通用咒语使用。

咒语起手式,prompt tag:

masterpiece, best quality, extremely-detailed, illustration, extremely detailed 8K wallpaper,

咒语起手式,negative prompt tag:

bad hands, missing fingers, cropped legs, worst quality, low quality, normal quality, jpeg artifacts, blurry,missing fingers,bad hands,missing arms, long neck, Humpbacked,multiple breasts, mutated hands and fingers, long body, mutation, poorly drawn , bad anatomy,bad shadow,unnatural body, fused breasts, bad breasts, more than one person,wings on halo,small wings, 2girls, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry,

如果对画面的手部有精细化要求的话,推荐手部negative tag:

missing fingers, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, fused digit, missing digit, (bad digit:1.2), (liquid digit:1.2), (extra-long digit:1.2),

这里我们学习我们的第一个禁咒,手指禁咒negative tag:

(poorly drawn hands),more than 1 left_hand, more than 1 right_hand, short_arm, (missing arms:1.2), bad_hands,missing fingers,(extradigit),(fewer digits),mutated hands,(fused fingers),(too many fingers),sharp fingers,wrong figernails,long hand,double middle finger,index fingers together,missing indexfinger,interlocked fingers,pieck fingers,sharp fingernails,(steepled fingers),x fingers,(curled fingers),(no finger gaps),interlocked fingers,fingers different thickness,cross fingers,poor outline,big fingers,finger growth,outline on body,outline on hair,out line on background,more than one hands,fuse arm,fuse elbow,more than two arm,more than two elbow

禁咒一般对系统的运行速度有影响,如果通用咒语能满足出图要求时尽量不要使用。

禁咒一般建议出高分辨率绘图时使用。

Sampling Steps(出图调参)

1)Sampling method

这里是AI出图的算法选择。

一般而言,这里的算法根据全球AI的发展速度,平均每周会有新的算法更新。

对于初级炼丹师来说,一般采用Euler a和DDIM算法。

其中Euler a是非线性迭代算法,它的结果并不会因为迭代增加而无休止地变得更加优秀,在大于一定的迭代值之后反而质量会快速下滑。

DDIM是线性迭代算法,质量往往依托于迭代的次数。但也存在边际效应的问题,当迭代大于一定程度时,再增加迭代次数也不会让画面产生显著变化。

我一般出图都是采用Euler a或者DDIM算法。

2)Sampling Steps

Sampling Steps可以选择25-40之间,我一般用32。

当出草图时可以选择25。

选择了一些主流算法在各个step迭代步数出图的效果进行展示。

其中横坐标是算法,包括了Euler a、DDIM、DPM2 a,DPM2 a Karras,LMS,PLMS。

纵坐标是step迭代步数,分别是:5、10、15、20、25、30、40、50、90、150、200、250、300、400、500步下迭代的出图效果,如下图所示:

各个算法及迭代步数矩阵效果图

3)Picture resolution

Width是图片宽度像素,Height是图片高度像素。

一般而言,出草图时采用512*256左右的分辨率出图。

正式出图采用1024*512左右的分辨率出图。

高分辨率出图在正式图的基础上可以通过Extras的算法做分辨率的放大工作。

SDwebui最大支持4*分辨率的放大,即4096*2048的分辨率出图。

放大算法建议采用R-ESRGAN。

4)CFG Scale

CFG是出图结构相似、内容连续变化参数。

它告诉模型应该遵循prompt到什么程度。

0: 放飞自我,会出完全和提示词无关的图。

30: 循规蹈矩, 即过拟合。

可以理解成: 乙方听甲方的话有多认真/多死板。

我一般的参数范围在:7.5-11.5之间。

5)Stable Diffusion checkpoint

训练集模型库的选用,一般默认的二次元训练集模型库有:

final-pruned、momoco、anything_V3等。

三次元训练集模型库有官方模型:

Stable DIffusion V1.5、Midjourney_V4等。

作为二次元的忠实拥戴,非特殊说明,教程中均采用上述3个二次元训练集模型库。

6)others

Restore faces、Tiling、Highres. fix一般情况下我们不勾选。

Batch count是出图的批次,Batch size是一批出图同时出几张图。

出草图时按照Batch count:1,Batch size:1出图即可。

我一般的设置是9宫格出图按照Batch count:3,Batch size:3的设置来出图。

seed是图片种子,主要用来控制画风和出图稳定性。

Open for Clip Aesthetic!下面的选项属于中级炼丹术中的内容。

请参考我后续的中级炼丹术的内容。

Chapter III —— Generate your first img

以克罗索为例,她的基础构建咒语如下:

prompt:

masterpiece, best quality, extremely-detailed, illustration, extremely detailed 8K wallpaper,

1girl, (solo:1.5), petite, aqua eyes, aqua hair,asymmetrical bangs, hair behind ear, hair over one eyebrow, braided bangs, rinka haircut, small breasts,

negative prompt:

bad hands, missing fingers, cropped legs, worst quality, low quality, normal quality, jpeg artifacts, blurry,missing fingers,bad hands,missing arms, long neck, Humpbacked,multiple breasts, mutated hands and fingers, long body, mutation, poorly drawn , bad anatomy,bad shadow,unnatural body, fused breasts, bad breasts, more than one person,wings on halo,small wings, 2girls, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry,

我们对如下参数进行设置:

Width:512,Height:1024

Sampling Steps:32

Sampling method:Euler a

Batch count:3,Batch size:3(九宫图设置)

CFG Scale:7.5

点击generate,AI会画出我们的克罗索,九宫图出图如下:

Reference

[1] Stable Diffusion Tutorial

[2] Stable Diffusion web UI readme.md

[3] 元素同典:确实不完全科学的魔导书,CoQ: A Synsemantic Grimoire of (Non)Science,元素法典制作委员会

[4] 元素法典,The Code of Quintessence,<第壹卷>、<第贰卷>,元素法典制作委员会

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多