前言

好久没更了,最近又发现好玩的AI工具,分享给大家。

Stable Diffusion是一款功能异常强大的AI图片生成器。它支持文字生成图片,图片转图片,使用各种各样的模型来达到你想要的效果,还能训练你自己的专属模型。 简单来说,即使你没有绘画功底,只要文笔叙说的够详细准确也可以画出自己想要的图片,甚至超乎你的想象。

  • 先转一波别人使用此工具生成的图:

骨架分析重绘图片

国风图

  • 自己部署生成的图片,个人电脑显存只有4g,只能生成384*384的小图

国风

电脑硬件要求

  1. Windows系统
  2. 有独立显卡,并且是NVDIA卡,显存至少4个G。
  3. 硬盘留有足够的空间,该程式占用30个G左右(包括模型)

网络要求:可能需要魔法上网

当然,mac系统,AMD显卡,显存少的情况也有方法安装使用,不过多少会出问题,而且功能不全,严重影响使用体验。

安装步骤

选择一个路径(最好放在C盘,以免后续出问题),新建stable-diffusion-webui-master文件夹,在这个文件夹下解压刚刚下载的stable-diffusion-webui-master .zip

  • 显卡显存大于8G的忽略这步。显存小于8G修改上一步解压文件里面的webui-user.bat
1
2
3
4
5
6
7
8
9
@echo off

set PYTHON=
set GIT=
set VENV_DIR=
set COMMANDLINE_ARGS=--xformers --medvram

call webui.bat

显存4—6G修改成以上

显存不到2G把--medvram改成--lowvram

这样可以减少系统的负担,提高图片的运算速率。

  • 双击运行webui-user.bat等待安装,会花费挺长时间安装,全部的安装环境大概10个G

可能出现的问题:

Couldn‘t install gfpgan,以下是报错代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Installing gfpgan
Traceback (most recent call last):
File "D:\Work\stable-diffusion-webui\launch.py", line 324, in <module>
prepare_environment()
File "D:\Work\stable-diffusion-webui\launch.py", line 239, in prepare_environment
run_pip(f"install {gfpgan_package}", "gfpgan")
File "D:\Work\stable-diffusion-webui\launch.py", line 106, in run_pip
return run(f'"{python}" -m pip {args} --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}")
File "D:\Work\stable-diffusion-webui\launch.py", line 74, in run
raise RuntimeError(message)
RuntimeError: Couldn't install gfpgan.
Command: "D:\Work\stable-diffusion-webui\venv\Scripts\python.exe" -m pip install git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 --prefer-binary
Error code: 1
stdout: Collecting git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379
Cloning https://github.com/TencentARC/GFPGAN.git (to revision 8d2447a2d918f8eba5a4a01463fd48e45126a379) to c:\users\cheapmeow\appdata\local\temp\pip-req-build-ww9pc8i8

stderr: Running command git clone --filter=blob:none --quiet https://github.com/TencentARC/GFPGAN.git 'C:\Users\CheapMeow\AppData\Local\Temp\pip-req-build-ww9pc8i8'
error: RPC failed; curl 28 Recv failure: Connection was reset
fatal: expected flush after ref listing
error: subprocess-exited-with-error

git clone --filter=blob:none --quiet https://github.com/TencentARC/GFPGAN.git 'C:\Users\CheapMeow\AppData\Local\Temp\pip-req-build-ww9pc8i8' did not run successfully.
exit code: 128

See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

git clone --filter=blob:none --quiet https://github.com/TencentARC/GFPGAN.git 'C:\Users\CheapMeow\AppData\Local\Temp\pip-req-build-ww9pc8i8' did not run successfully.
exit code: 128

See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

[notice] A new release of pip available: 22.2.1 -> 22.3.1
[notice] To update, run: D:\Work\stable-diffusion-webui\venv\Scripts\python.exe -m pip install --upgrade pip

解决办法1

找到stable-diffusion-webui-master文件夹下launch.py,打开编辑这个文件

在所有https://github.com前面添加https://ghproxy.com/。下面是修改好的。修改后保存文件.

删除stable-diffusion-webui-master文件夹下的venv文件夹(只要报错没有流畅安装完成,再次双击webui-user.bat运行之前都要删除这个文件)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def prepare_environment():
global skip_install

torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117")
requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt")
commandline_args = os.environ.get('COMMANDLINE_ARGS', "")

xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.16rc425')
gfpgan_package = os.environ.get('GFPGAN_PACKAGE', "git+https://ghproxy.com/https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379")
clip_package = os.environ.get('CLIP_PACKAGE', "git+https://ghproxy.com/https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1")
openclip_package = os.environ.get('OPENCLIP_PACKAGE', "git+https://ghproxy.com/https://github.com/mlfoundations/open_clip.git@bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b")

stable_diffusion_repo = os.environ.get('STABLE_DIFFUSION_REPO', "https://ghproxy.com/https://github.com/Stability-AI/stablediffusion.git")
taming_transformers_repo = os.environ.get('TAMING_TRANSFORMERS_REPO', "https://ghproxy.com/https://github.com/CompVis/taming-transformers.git")
k_diffusion_repo = os.environ.get('K_DIFFUSION_REPO', 'https://ghproxy.com/https://github.com/crowsonkb/k-diffusion.git')
codeformer_repo = os.environ.get('CODEFORMER_REPO', 'https://ghproxy.com/https://github.com/sczhou/CodeFormer.git')
blip_repo = os.environ.get('BLIP_REPO', 'https://ghproxy.com/https://github.com/salesforce/BLIP.git')

stable_diffusion_commit_hash = os.environ.get('STABLE_DIFFUSION_COMMIT_HASH', "47b6b607fdd31875c9279cd2f4f16b92e4ea958e")
taming_transformers_commit_hash = os.environ.get('TAMING_TRANSFORMERS_COMMIT_HASH', "24268930bf1dce879235a7fddd0b2355b84d7ea6")
k_diffusion_commit_hash = os.environ.get('K_DIFFUSION_COMMIT_HASH', "5b3af030dd83e0297272d861c19477735d0317ec")
codeformer_commit_hash = os.environ.get('CODEFORMER_COMMIT_HASH', "c5b4593074ba6214284d6acd5f1719b6c5d739af")
blip_commit_hash = os.environ.get('BLIP_COMMIT_HASH', "48211a1594f1321b00f14c9f7a5b4813144b2fb9")

解决方案2

假如没有其它报错,成功安装后会出现本地链接网址,把网址复制到浏览器就能访问。不要退出cmd!!!

成功安装

  • 添加中文语言包

https://github.com/VinsonLaro/stable-diffusion-webui-chinese

把上面的地址粘贴在下图的第三步,点击install

安装中文包

重启web-ui

重启web-ui

选择Settings,选择user interface,选择chinese-all-0220

改中文

应用设置,重载UI

保存设置

文字生成图片界面介绍

文转图

模型

模型推荐

  • 人体骨架分析模型control_sd15_openpose,作用是可以把真人图片上传到web-ui,分析出图片中人物的姿势骨架,然后重新绘图。
  • 国风模型guofeng3_v32:生成的人物,符合国人审美,富有中国元素
  • anythion4.0:比较适合绘制动漫风格人物
  • stablydiffuseds_26

AI模型

  1. https://huggingface.co/
  2. https://civitai.com/

提示词

提示词(prompt):图中想要出现的内容。

标配提示词:masterpiece,best quality

反向提示词(negative prompt):图中不想要的内容

提示词可以使用翻译软件翻译成英语直接用,也可以使用TAG来展示,一个提示词后面一个逗号,复杂的语法,比如(),and,or,:,[]等怎么使用可以自己拓展了解。提示词越靠前,优先级越高,把重点想画的内容放在最前面。比如masterpiece,best quality的意思是大师级,高质量绘画,把它们放在最前面,出来的图片质量就会比较好。

提示词在线网站

提示词示例

正向提示词

1
4 girls,4 girls on the beach,back to the sea,White dress,beautiful white gauze skirt,bikini,intricate,elegant,highly detailed,digita painting,concept art,summer lights,queen,sunset,orange sky,pink nightgown,simple background,soft light<lora:dalcefopainting_Lora300:1>

反向提示词

1
nude,naked,hands,cartoon,thick strokes,((disfigured)),((bad art)),((deformed)),((poorly drawn)),((extra limbs)),((close up)),((b&w)),weird colors,blurry,complex

正向提示词

1
1girl, beautiful, realistic

反向提示词

1
(((simple background))),monochrome ,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, lowres, bad anatomy, bad hands, text, error, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, ugly,pregnant,vore,duplicate,morbid,mut ilated,tran nsexual, hermaphrodite,long neck,mutated hands,poorly drawn hands,poorly drawn face,mutation,deformed,blurry,bad anatomy,bad proportions,malformed limbs,extra limbs,cloned face,disfigured,gross proportions, (((missing arms))),(((missing legs))), (((extra arms))),(((extra legs))),pubic hair, plump,bad legs,error legs,username,blurry,bad feet

在线体验使用

推荐阅读

  • 本地部署 AI作画工具 stable-diffusion-webui 多种模型 可生成NSFW

https://www.tjsky.net/tutorial/457

  • AI绘画指南 stable diffusion webui (SD webui)如何设置与使用

https://www.tjsky.net/tutorial/488

  • Stable Diffusion2.1+WebUI的安装与使用(极详细)

https://www.bilibili.com/read/cv20466834