写在前面
偶然看到,简单了解 博文为 SD 部署,以及简单使用,部署过程遇到问题解决 理解不足小伙伴帮忙指正对每个人而言,真正的职责只有一个:找到自我。然后在心中坚守其一生,全心全意,永不停息。所有其它的路都是不完整的,是人的逃避方式,是对大众理想的懦弱回归,是随波逐流,是对内心的恐惧 ——赫尔曼·黑塞《德米安》
Stable Diffusion 是一个先进文本转图像模型,可使用基本的自然语言提示创作复杂的作品
部署
安部署教程来自:
https://www.youtube.com/watch?v=onmqbI5XPH8&t=55s
下载并运行 Stable Diffusion
来从文本描述生成图像。
Git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
Download model / checkpoint: https://huggingface.co/runwayml/stable-diffusion-v1-5
Overview of different models: https://stable-diffusion-art.com/models/
Command to update Stable Diffusion WebUI automatically:Git pull
Git 下载
https://git-scm.com/downloads
window 命令行下载
PS C:\Users\NUC> winget install --id Git.Git -e --source winget
已找到 Git [Git.Git] 版本 2.43.0
此应用程序由其所有者授权给你。
Microsoft 对第三方程序包概不负责,也不向第-三方程序包授予任何许可证。
正在下载 https://github.com/git-for-windows/git/releases/download/v2.43.0.windows.1/Git-2.43.0-64-bit.exe
██████████████████████████████ 58.0 MB / 58.0 MB
已成功验证安装程序哈希
正在启动程序包安装...
已成功安装
PS C:\Users\NUC>
添加系统环境变量 C:\Program Files\Git\bin
C:\Program Files\Git\bin
关闭终端重新打开测试
PS C:\Users\NUC> git --version
git version 2.43.0.windows.1
Python 安装
https://www.python.org/downloads/release/python-3106/
window 命令行下载
PS C:\Users\NUC> winget install --id Python.Python.3.10 -e --source winget
已找到 Python 3.10 [Python.Python.3.10] 版本 3.10.11
此应用程序由其所有者授权给你。
Microsoft 对第三方程序包概不负责,也不向第三方程序包授予任何许可证。
正在下载 https://www.python.org/ftp/python/3.10.11/python-3.10.11-amd64.exe
██████████████████████████████ 27.6 MB / 27.6 MB
已成功验证安装程序哈希
正在启动程序包安装...
已成功安装
PS C:\Users\NUC>
添加系统环境变量
C:\Users\NUC\AppData\Local\Programs\Python\Python310
关闭终端重新打开测试
PS C:\Users\NUC> python --version
Python 3.10.11
PS C:\Users\NUC>
部署项目
克隆项目 git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
更新 pip
PS C:\Users\NUC\Documents\GitHub\stable-diffusion-webui> C:\Users\NUC\Documents\GitHub\stable-diffusion-webui\venv\Scripts\python.exe -m pip install --upgrade pip
设置全局的 pip 源
PS C:\Users\NUC\Documents\GitHub\stable-diffusion-webui> pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Writing to C:\Users\NUC\AppData\Roaming\pip\pip.ini
运行部署脚本(需要科学上网)
PS C:\Users\NUC\Documents\GitHub\stable-diffusion-webui> .\webui-user.bat
命令行下载基础模型
PS C:\Users\NUC\Documents\GitHub\stable-diffusion-webui\models\Stable-diffusion> wget -O v1-5-pruned-emaonly.ckpt https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.ckpt
PS C:\Users\NUC\Documents\GitHub\stable-diffusion-webui\models\Stable-diffusion> wget -O v1-5-pruned.ckpt https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned.ckpt
报错解决
OSError: Can't load tokenizer for 'openai/clip-vit-large-patch14'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'openai/clip-vit-large-patch14' is the correct path to a directory containing all relevant files for a CLIPTokenizer tokenizer.
解决办法:
http://www.chen-studio.com/archives/128.html
git clone https://huggingface.co/openai/clip-vit-large-patch14
huggingface 模型库命令行工具安装
部分模型需要在 huggingface
下载,一直下载不下来,后来登录了发现可以了
操作步骤
pip install huggingface_hub
You already have it if you installed transformers or datasets
huggingface-cli login
Log in using a token from huggingface.co/settings/tokens
Create a model or dataset repo from the CLI if needed
huggingface-cli repo create repo_name --type {model, dataset, space}
下载
PS C:\Users\NUC\Documents\GitHub\stable-diffusion-webui> pip install huggingface_hub
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
登录(需要提前使用谷歌账户注册)
PS C:\Users\NUC\Documents\GitHub\stable-diffusion-webui> huggingface-cli login
_| _| _| _| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _|_|_|_| _|_| _|_|_| _|_|_|_|
_| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _|
_|_|_|_| _| _| _| _|_| _| _|_| _| _| _| _| _| _|_| _|_|_| _|_|_|_| _| _|_|_|
_| _| _| _| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _|
_| _| _|_| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _| _| _| _|_|_| _|_|_|_|
To login, `huggingface_hub` requires a token generated from https://huggingface.co/settings/tokens .
Token can be pasted using 'Right-Click'.
Token:
Add token as git credential? (Y/n) Y
Token is valid (permission: read).
Your token has been saved in your configured git credential helpers (manager).
Your token has been saved to C:\Users\NUC\.cache\huggingface\token
Login successful
PS C:\Users\NUC\Documents\GitHub\stable-diffusion-webui>
前端页面报错 Expecting value: line 1 column 1 (char 0)
解决办法
https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/14037
上面的 issues
找到了解决办法
git pull
@echo off
set PYTHON=
set GIT=
set VENV_DIR=
set COMMANDLINE_ARGS= --xformers --no-gradio-queue
call webui.bat
启动脚本添加参数 : --xformers --no-gradio-queue
pip 下载报错
修改脚本部分代码,添加 pip 源,或者修改全局配置
C:\Users\NUC\Documents\GitHub\stable-diffusion-webui\modules\launch_utils.py
添加国内 pip 镜像,同时把科学上网关掉
下面为修改后的代码
index_url_line = f' --index-url {index_url}' if index_url != '' else ' -i https://pypi.tuna.tsinghua.edu.cn/simple'
这里希望直接使用可以直接下载封装好的包,不过没有试过
https://github.com/AUTOMATIC1111/stable-diffusion-webui/releases/tag/v1.0.0-pre
使用测试
运行启动脚本
PS C:\Users\NUC\Documents\GitHub\stable-diffusion-webui> .\webui-user.bat
venv "C:\Users\NUC\Documents\GitHub\stable-diffusion-webui\venv\Scripts\Python.exe"
Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
Version: v1.6.1
Commit hash: 4afaaf8a020c1df457bcf7250cb1c7f609699fa7
current transparent-background 1.2.9
Installing SD-CN-Animation requirement: scikit-image
Installing sd-webui-controlnet requirement: mediapipe
Installing sd-webui-controlnet requirement: svglib
Installing sd-webui-controlnet requirement: fvcore
Launching Web UI with arguments: --xformers --no-gradio-queue
dirname: C:\Users\NUC\Documents\GitHub\stable-diffusion-webui\localizations
localizations: {'zh_CN': 'C:\\Users\\NUC\\Documents\\GitHub\\stable-diffusion-webui\\extensions\\stable-diffusion-webui-localization-zh_CN\\localizations\\zh_CN.json'}
2023-12-19 03:19:35,825 - ControlNet - INFO - ControlNet v1.1.419
ControlNet preprocessor location: C:\Users\NUC\Documents\GitHub\stable-diffusion-webui\extensions\sd-webui-controlnet\annotator\downloads
2023-12-19 03:19:36,090 - ControlNet - INFO - ControlNet v1.1.419
Loading weights [cc6cb27103] from C:\Users\NUC\Documents\GitHub\stable-diffusion-webui\models\Stable-diffusion\v1-5-pruned-emaonly.ckpt
*Deforum ControlNet support: enabled*
Running on local URL: http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.
Startup time: 55.0s (prepare environment: 41.1s, import torch: 4.8s, import gradio: 2.1s, setup paths: 2.0s, initialize shared: 0.2s, other imports: 1.6s, setup codeformer: 0.2s, list SD models: 0.3s, load scripts: 1.8s, create ui: 0.8s, gradio launch: 0.2s).
Creating model from config: C:\Users\NUC\Documents\GitHub\stable-diffusion-webui\configs\v1-inference.yaml
Applying attention optimization: xformers... done.
Model loaded in 11.8s (load weights from disk: 5.4s, create model: 0.3s, apply weights to model: 2.3s, apply half(): 1.9s, load VAE: 0.2s, calculate empty prompt: 1.7s).
当前界面安装了一些插件,所以展示这样的,默认为橘黄色
模型获取网站:
https://civitai.com/models
简单测试
常见的正向反向提示词
反向:
DeepNegative,EasyNegativeV2,bad-hands-5,bad_prompt_version2,deformed,missing limbs,amputated,disfigured,poorly drawn face,mutation,mutated,ugly,disgusting,oversaturated,doubled face,b&w,black and white,sepia,freckles,no masks,duplicate image,paintings,sketches,(worst quality:2),(low quality:2),(normal quality:2),lowres,monochrome,grayscale,bad anatomy,(fat:1.2),tilted head,bad hands,error,missing fingers,extra digit,fewer digits,cropped,blurry,bad feet,jpeg (artifacts:1.2),
canvas frame, (high contrast:1.2), (over saturated:1.2), (glossy:1.1), ((disfigured)), ((bad art)), ((b&w)), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))), 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))), photoshop, video game, ugly, tiling, poorly drawn hands, (nsfw:1.2), nude, naked, pink nipples
正向:
high quality 3d rendering high resolution raytracing
(front focus),(in the dark:1.6),
(masterpiece:1.1),(highest quality:1.1),(HDR:1),ambient light,ultra-high quality,( ultra detailed original illustration),
film grain and (medium full shot:1.2) and 8K HD RAW photo
博文部分内容参考
© 文中涉及参考链接内容版权归原作者所有,如有侵权请告知,这是一个开源项目,如果你认可它,不要吝啬星星哦 ?
什么是LoRA模型,如何使用和训练LoRA模型?你想要的都在这!:https://zhuanlan.zhihu.com/p/624230991
项目地址: https://github.com/AUTOMATIC1111/stable-diffusion-webui
部署教程地址: https://www.youtube.com/watch?v=onmqbI5XPH8&t=55s
© 2018-2023 liruilonger@gmail.com, All rights reserved. 保持署名-非商用-相同方式共享(CC BY-NC-SA 4.0)