引言
Stable Diffusion的食用指南
0 Windows安装
- 安装
miniconda, 具体安装地址- 默认安装
- 配置下载源
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16<!-- 1. 设置阿里源为默认源 -->
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
<!-- 该源可解决tb-nightly的问题 -->
<!-- 还原默认源 -->
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple
<!-- 其他源 -->
https://pypi.tuna.tsinghua.edu.cn/simple
https://mirrors.aliyun.com/pypi/simple/
https://mirrors.163.com/pypi/simple/
https://pypi.douban.com/simple/
https://mirror.baidu.com/pypi/simple/
https://pypi.mirrors.ustc.edu.cn/simple/
https://mirrors.huaweicloud.com/repository/pypi/simple/
https://mirrors.cloud.tencent.com/pypi/simple/ - 创建虚拟环境
1
conda create --name sd-webui python=3.10.6
- 激活虚拟环境
1
conda activate sd-webui
- 安装
git - 安装
cuda及cuDNN, 详见Windows深度学习环境配置 git克隆Stable Diffusion WebUI项目至本地, 注意终端的地址为本地合适的地址1
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
- 进入项目文件夹,运行
Stable Diffusion WebUI, 首次运行会安装对应的库1
2
3
4
5<!-- 切换目录 -->
cd stable-diffusion-webui
<!-- 运行 -->
webui-user.bat - 安装插件
- 插件源
- https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui-extensions/master/index.json
- https://gitee.com/hmy394481125/stable-diffusion-webui-extensions/raw/master/index.json
- https://gitee.com/kalicyh/stable-diffusion-webui-extensions/raw/master/AUTOMATIC1111_stable-diffusion-webui-extensions_master_index.json
- https://gitee.com/ethanyu/stable-diffusion-webui-extensions/raw/master/index.json
- 操作
- 打开
Stable Diffusion WebUI的Settings,找到Extensions,点击Install,输入插件源地址,点击Install即可 - 安装插件后,需要重启
Stable Diffusion WebUI才能生效
- 打开
- 推荐插件
- [x] stable-diffusion-webui-localization-zh_Hans 简体中文语言包
- [ ] Booru tag autocompletion 自动补全标签
- [ ] Stable Diffusion WebUI EasyNegative 一键生成负面标签
- [x] sd-webui-controlnet ControlNet插件
- [x] openpose-editor 编辑自定义POSE
- [x] stable-diffusion-webui-wd14-tagger 提取tag提示词
- [ ] clip-interrogator-ext
- [ ] sd-webui-lora-black-weight
- 插件源
1 Ubuntu安装
2 ControlNet使用方法
- 部分模型说明
- canny主要是边缘检测,属于比较通用的模型
- Openpose就是传说中的姿势控制专用模型
- Scribble是手稿模型,适合随手涂鸦然后生成一个精美的画面,可玩性高
3 Ubuntu调教
- 在Ubuntu中可使用
supervisord配置sd-webui进程实现开机自启动- 帮助命令
1
2
3
4
5启动命令:supervisord ctl start stable-webui
关闭命令:supervisord ctl stop stable-webui
重启命令:supervisord ctl restart stable-webui
查看状态:supervisord ctl status stable-webui
查看日志:tail -f /var/log/stable-webui.log - 安装方式
- 文件
/etc/supervisor/conf.d/stable-webui.conf1
2
3
4
5
6
7
8
9
10
11
12
13
14<!-- 编辑文件 -->
vim /etc/supervisor/conf.d/stable-webui.conf
<!-- 文件内容 -->
[program:stable-webui]
command=/usr/local/miniconda3/bin/python3 launch.py --xformers --no-half-vae --listen --port 8080 --api --enable-insecure-extension-access --opt-channelslast --administrator
process_name=%(program_name)s
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/stable-webui.log,/dev/stdout
stdout_events_enabled=true
environment=SHELL=/bin/bash
directory=/hy-tmp/stable-diffusion-webui/
user=root
- 文件
- 设置
supervisord开机自启动cd /usr/lib/systemd/system/which supervisord,which supervisorctl,vi supervisord.service建立supervisord.service文件内容1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#supervisord.service
[Unit]
Description=Supervisor daemon
[Service]
Type=forking
ExecStart=/usr/local/bin/supervisord -c /etc/supervisord.conf
ExecStop=/usr/local/bin/supervisorctl shutdown
ExecReload=/usr/local/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target- 启动服务
systemctl enable supervisord,systemctl start supervisord - 查看服务状态
systemctl status supervisord - 验证是否开机自启动
systemctl is-enabled supervisord
- 帮助命令
4 模型下载
-
国内使用镜像站下载
- 推荐使用
huggingface-cli进行下载1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18<!-- 安装依赖 python>3.8 -->
pip install -U huggingface_hub hf-transfer
<!-- Windows设置环境变量 -->
setx HF_HUB_ENABLE_HF_TRANSFER 1
setx HF_ENDPOINT https://hf-mirror.com
<!-- Linux设置环境变量 -->
export HF_HUB_ENABLE_HF_TRANSFER=1
vim ~/.bashrc
# 在打开文件中的最后一行添加
export HF_ENDPOINT="https://hf-mirror.com"
<!-- 下载模型 -->
huggingface-cli download --token [访问令牌] --resume-download --local-dir-use-symlinks False [模型名] --local-dir [保存位置] - 使用
git clone1
2
3
4
5
6
7
8
9<!-- 安装 git lfs -->
git lfs install
<!-- 直接git clone -->
git clone ....
<!-- 不下载大的文件配置方法 -->
setx GIT_LFS_SKIP_SMUDGE 1
export GIT_LFS_SKIP_SMUDGE=1
- 推荐使用
-
推荐模型
- SmilingWolf/wd-v1-4-vit-tagger-v2
- SmilingWolf/wd-v1-4-swinv2-tagger-v2
- SmilingWolf/wd-v1-4-vit-tagger
- lllyasviel/ControlNet-v1-1
- xyn-ai/anything-v4.0
- stablediffusionapi/anything-v5
- stablediffusionapi/anything-midjourney
- Joeythemonster/anything-midjourney-v-4-1
- gsdf/Counterfeit-V3.0
- gsdf/Counterfeit-V2.5
5 注意事项
- 注意事项
- 模型文件在
stable-diffusion-webui\models中, 首次运行需要下载模型文件 - webui-user.bat修改说明
1
2
3
4
5
6
7
8<!-- 解决RuntimeError: "LayerNormKernelImpl" not implemented for 'Half' -->
COMMANDLINE_ARGS=--skip-torch-cuda-test --precision full --no-half
<!-- torch.cuda.OutOfMemoryError: CUDA out of memory -->
COMMANDLINE_ARGS=--medvram 或者--lowvram
<!-- No module 'xformers'. Proceeding without it. -->
COMMANDLINE_ARGS=--xformers - 模型推荐
- https://huggingface.co/gsdf/Counterfeit-V2.5 配合EasyNegative使用,上面的萝姬就是用这个模型,很好看,tag写起来也简单
- https://huggingface.co/andite/anything-v4.0 祖师爷,出图质量稳定,插图风格很不错
- https://huggingface.co/datasets/gsdf/EasyNegative 用这个负面tag就可以写很简单了
- https://huggingface.co/TASUKU2023/Chilloutmix 真人模型,不过我没怎么用过,还是喜欢二次元的图,不过之后可能研究配合Lora玩赛博COS
- 插件推荐:
- https://github.com/DominikDoom/a1111-sd-webui-tagcomplete 可以自动补全标签,有助于写出更准确的tags
- 模型文件在