安装 python 环境
安装 miniconda
这个是用来管理python版本的,他可以实现python的多版本切换。
1.下载地址 Miniconda — conda documentation
安装完成后,开始-输入mini-找到miniconda3打开
- 配置库包下载镜像,加快网络速度(替换下载库包地址为国内的清华镜像站)
执行下面
conda config --set show_channel_urls yes
生成.condarc 文件,路径 C:\Users\xxxx\.condarc
,输入下面内容
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
清理索引缓存
conda config --set show_channel_urls yes
conda clean -i
创建 python 3.10.6 虚拟环境
conda create -name stable-diffusion-webui python=3.10.6
安装完成
激活环境
conda activate stable-diffusion-webui
升级pip,并设置pip的默认库包下载地址为清华镜像。
python -m pip install --upgrade pip
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pytorch
pytorch 库分下面两种安装方式:Previous PyTorch Versions | PyTorch
conda
# CUDA 11.6
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.6 -c pytorch -c nvidia
# CUDA 11.7
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.7 -c pytorch -c nvidia
# CPU Only
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 cpuonly -c pytorch
pip
whl 文件下载地址 download.pytorch.org/whl/torch_s… download.pytorch.org/whl/torch/ download.pytorch.org/whl/torch/
# ROCM 5.2 (Linux only)
pip3 install torch torchvision torchaudio --extra-index-url
pip install torch==1.13.1+rocm5.2 torchvision==0.14.1+rocm5.2 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/rocm5.2
# CUDA 11.6
pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116
# CUDA 11.7
pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu117
# CPU only
pip install torch==1.13.1+cpu torchvision==0.14.1+cpu torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cpu
验证 cuda 版本安装是否成
import torch
torch.cuda.is_available()
安装 stable-diffusion-webui
下载源码
- 安装 git 工具
- clone 源码
git clone --depth 1 https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
下载模型
runwayml/stable-diffusion-v1-5 · Hugging Face
模型存放路径:models/Stable-diffusion
运行
(sdwebui_py_3106) D:\workspace\project\stablediffusion\sdwebui\sdwebui-src>webui-user.bat
venv "D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\Scripts\Python.exe"
Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)]
Commit hash: 22bcc7be428c94e9408f589966c2040187245d81
Installing requirements for Web UI
set PYTHON="D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\Scripts\Python.exe"
Launching Web UI with arguments: --no-half
No module 'xformers'. Proceeding without it.
Loading weights [db220d90e5] from D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\models\Stable-diffusion\chilloutmix-Ni-non-ema-fp32.safetensors
Creating model from config: D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\configs\v1-inference.yaml
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Applying cross attention optimization (Doggettx).
Textual inversion embeddings loaded(0):
Model loaded in 140.3s (load weights from disk: 44.0s, create model: 0.5s, apply weights to model: 7.4s, move model to device: 4.4s, hijack: 61.6s, load textual inversion embeddings: 22.4s).
Running on local URL: http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.
Startup time: 484.6s (import torch: 2.9s, import gradio: 2.4s, import ldm: 1.0s, other imports: 289.6s, setup codeformer: 0.2s, load scripts: 46.8s, load SD checkpoint: 140.7s, create ui: 0.9s, gradio launch: 0.1s).
环境变量
- PYTHON: 设置 python 路径
- VENV_DIR: 设置 python 虚拟环境路径,默认是 venv, 设置为 - 表示不创建虚拟环境运行脚本。
- COMMANDLINE_ARGS: 添加主程序运行参数
- TORCH_COMMAND: 安装 pytorch 的命令b
- REQS_FILE: 默认值 requirements_version.txt 。设置依赖文件名, launch.py 使用其安装依赖
- CUDA_VISIBLE_DEVICES: select gpu to use for your instance on a system with multiple gpus. For example if you want to use secondary gpu, put "1".
(add a new line to webui-user.bat not in COMMANDLINE_ARGS):
set CUDA_VISIBLE_DEVICES=0
Alternatively, just use--device-id
flag in COMMANDLINE_ARGS. - TRANSFORMERS_CACHE: path to where transformers library will download and keep its files related to the CLIP model
推荐通过编辑 webui-user.bat 文件 设置运行时的环境变量
@echo off
set PYTHON=
set GIT=
@REM VENV_DIR 设置为 - 表示不创建虚拟环境运行脚本
set VENV_DIR=-
@REM --no-half 半精度 --api 启动 API
set COMMANDLINE_ARGS=--no-half --api
@REM set COMMANDLINE_ARGS=--allow-code --xformers --skip-torch-cuda-test --no-half-vae --api --ckpt-dir A:\\stable-diffusion-checkpoints
call webui.bat
命令参数
Use the --share
option to run online. You will get a xxx.app.gradio link. This is the intended way to use the program in collabs. You may set up authentication for said gradio shared instance with the flag --gradio-auth username:password
, optionally providing multiple sets of usernames and passwords separated by commas.
Use --listen
to make the server listen to network connections. This will allow computers on the local network to access the UI, and if you configure port forwarding, also computers on the internet.
Use --port xxxx
to make the server listen on a specific port, xxxx being the wanted port. Remember that all ports below 1024 need root/admin rights, for this reason it is advised to use a port above 1024. Defaults to port 7860 if available.
依赖介绍
依赖安装
launch.py 中的 prepare_environment 方法中有如下代码,进行依赖安装
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")
xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.16rc425')
gfpgan_package = os.environ.get('GFPGAN_PACKAGE', "git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379")
clip_package = os.environ.get('CLIP_PACKAGE', "git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1")
openclip_package = os.environ.get('OPENCLIP_PACKAGE', "git+https://github.com/mlfoundations/open_clip.git@bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b")
stable_diffusion_repo = os.environ.get('STABLE_DIFFUSION_REPO', "https://github.com/Stability-AI/stablediffusion.git")
taming_transformers_repo = os.environ.get('TAMING_TRANSFORMERS_REPO', "https://github.com/CompVis/taming-transformers.git")
k_diffusion_repo = os.environ.get('K_DIFFUSION_REPO', 'https://github.com/crowsonkb/k-diffusion.git')
codeformer_repo = os.environ.get('CODEFORMER_REPO', 'https://github.com/sczhou/CodeFormer.git')
blip_repo = os.environ.get('BLIP_REPO', 'https://github.com/salesforce/BLIP.git')
python 依赖库
webui.bat 会先切换到 venv 的虚拟环境,然后 launch.py 中的 prepare_environment 方法中会使用 python -m pip 安装下列依赖库:
- clip: 将文本和图像映射到潜空间(latent space),所以由两个编码器组成:
GitHub - openai/CLIP: CLIP (Contrastive Language-Image Pretraining), Predict the most relevant text snippet given an image
GitHub - pharmapsychotic/clip-interrogator: Image to prompt with BLIP and CLIP
- 图像编码器:ResNet-50作为基础模型,采用的Transformer共有5组,它们依次是ResNet-50,ResNet-100 以及按照EfficientNet的 ResNet-50x4,ResNet-50x16,ResNet-50x64。;ViT 共ViT-B/32,ViT-B/16以及ViT-L/14三个模型
- 文本编码器:使用的是Transformer[5],它共有12层,512的隐层节点数以及8个头
- openclip: stability AI 关于 clip 的开源实现。
[GitHub - mlfoundations/open_clip: An open source implementation of CLIP.] (github.com/mlfoundatio…)
- xformers: 加速图片生成并降低显存占用,该库仅适用于N卡,代价是输出图像不稳定,有可能比不开Xformers略差
使用: COMMANDLINE_ARGS 中添加参数 --xformers [GitHub - facebookresearch/xformers: Hackable and optimized Transformers building blocks, supporting a composable construction.] 由于之前处于开发早期, xformers 需要手动编译,门槛较高,并不方便使用.但在2023年1月23号, Stable Diffusion webUI 替换了使用的 Xformers 版本 ,无论是Linux 还是 Windows ,现在仅需使用一行命令即可完成下载安装(github.com/facebookres…) upgrading torch, torchvision, xformers (windows), to use cu117 by petalas · Pull Request #5939 · AUTOMATIC1111/stable-diffusion-webui · GitHub
其他优化介绍:
stablediffusion webui的 Optimizations · AUTOMATIC1111/stable-diffusion-webui Wiki · GitHub huggingface的Diffusers库文档的optimization huggingface.co
- GFPGAN: 腾讯开发的人脸复原算法,利用生成式脸部先验应用到真实世界的人脸复原中。这些先验隐式封装在一个预训练的 GAM 模型中。
使用:可以在设置界面选择:CodeFormer 和 GFPGAN 都是面部修复的AI模型,可以修改权重值。 GitHub - TencentARC/GFPGAN: GFPGAN aims at developing Practical Algorithms for Real-world Face Restoration.
github repo 依赖
lanuch.py 中的 prepare_environment 使用 git clone 依赖库的仓库到 repositories 目录中。
- stable-diffusion-stability-ai:sdwebui 的核心模块,是一个潜空间生成图的扩散模型算法 stable diffusion 的实现。
源码: GitHub - Stability-AI/stablediffusion: High-Resolution Image Synthesis with Latent Diffusion Models 源码:github.com/CompVis/sta… 模型: runwayml/stable-diffusion-v1-5 · Hugging Face
- taming-transformers: stablediffusion的高分辨率图像的生成实现,基于 VQGAN——利用基于CNN的有效归纳偏置,并结合Transformer结构的表达能力。
- k-diffusion: 用于指代Katherine Crowson's k-diffusion项目中实现的Karras 2022论文中提及的的相关采样器。当前常用的采样器中,除了DDIM、PLMS与UniPC之外的采样器均来自于k-diffusion。 为SD提供samplers(采样器)SDE(随机微分方程)和ODE(常微分方程)
- BLIP: interrogate CLIP的依赖。主要特点是结合了encoder和decoder,形成了统一的理解和生成多模态模型,sdwebui 中利用 BLIP 进行图片预处理,进行图片打标。
使用:Stable Diffusion webui-训练-图像预处理-BLIP 中图片打标工具 源码:github.com/salesforce/…
- CodeFormer: 与 GFPGAN 同样是人脸复原算法。南洋理工大学S-Lab实验室发表在
NeurIPS 2022
的一篇著作。这是一种基于Transformer
的预测网络,能够对低质量人脸的全局组成和上下文进行建模以进行编码预测,即使在输入信息严重缺失的情况下也能复原出与目标人脸非常接近的自然人脸图像
使用:可以在设置界面选择:CodeFormer 和 GFPGAN 都是面部修复的AI模型,可以修改权重值。 源码:github.com/sczhou/Code… 模型:detection_Resnet50_Final.pth parsing_parsenet.pth 两个预训练模型参数权重文件;Release CodeFormer V0.1.0 Release · sczhou/CodeFormer · GitHub
模型介绍
常见模型下载平台:
- Hugging Face – The AI community building the future.
- civitai : 又称 C 站。主要是 stable diffusion 模型,以及其微调模型, 大量 lora 模型。
模型后缀解析:
- .ckpt, .pt, .pth: pytorch 的标准模型保存格式,容易遭受Pickle反序列化攻击。
- .safetensors: safetensors格式可与Pytorch的模型相互格式转换,内容数据无区别。拥有更高的安全性;加载速度更快
模型类型
基础模型:基础模型是标准的 latent-diffusion 模型,拥有完整的 TextEncoder, U-Net, VAE 三部分。训练大模型需要较大的显卡算力
- 编码器:作用是将输入的图像编码成 latent vector, 以供 diffusion 使用。主要是 ResNet 系列模型,比如 ResNet-50, ResNet-101 等。
- 解码器:作用是将 diffustion 生成的 latent vector 解码成图片。主要使用反卷积网络(transposed convolutional network)。
- 隐向量模型:该模型生成的 latent vector 输入到解码器中,经过 diffusion 步骤生成图片。主要使用的隐向量模型主要是正态分布的噪声(Gaussion Noise)。
- Context Model: 生成以 prompt 为条件的 latent vector, 引导图片的生成。主要使用模型是 openClip 或者 openAI clip ,该模型可以选择性使用。
- 融合模型(Fusion Model): 可以选择融合编码器、解码器和上下文模型,得到更强的生成能力。主要的融合模型是 France et .al的模型(利用MoCo训练得到的编码器)。
stable diffusion 基础模型使用 ckpt,safetensors 文件。模型体积较大,一般单个模型的大小在 7GB 左右。模型位置:models\Stable-diffusion\ 目录。文件包括:
- ResNet系列的编码器文件
- 反卷积解码器文件
- CLIP或OpenAI的上下文模型文件(可选)
- Fusion模型的融合编码器文件(可选)
这些模型 ckpt 文件一起训练优化,生成 stable diffusion 模型。可以根据需要选择相应模型组合使用
Checkpoint模型是SD能够绘图的基础模型。必须搭配基础模型才能使用。不同的基础模型,其画风和擅长的领域会有侧重。 目前比较流行和常见的checkpoint模型有Anything系列(v3、v4.5、v5.0),AbyssOrangeMix3, ChilloutMix, Deliberate, majicMIX, 国风系列等等。这些checkpoint模型是从Stable Diffusion基本模型训练而来的,目前大多数模型都是从 v1.4 或 v1.5 训练的。它们使用其他数据进行训练,以生成特定风格或对象的图像。
微调模型:
微调模型一般都是截取大模型的某一特定部分。常见微调模型:Textual inversion(Embedding), Hypernetwork, Lora, Dreambooth
- Embedding: 常见后缀 pt 格式,文件体积一般只有几 KB。模型位置: embeddings
- Hypernetwork: 常见后缀 pt 格式,大小一般几十 MB。模型位置:models\hypernetworks
- LoRA: 常见后缀 safetensors, ckpt。 模型位置: models/Lora
- Dreambooth
模型目录
基础
- Stable-diffusion:基础 sd 模型, 常用基础模型: stable-diffusion-v1-5, chilloutmix_Ni;
runwayml/stable-diffusion-v1-5 · Hugging Face CompVis/stable-diffusion · Hugging Face CompVis/stable-diffusion · Hugging Face
- VAE-approx
- VAE: VAE (Variational Auto-Encoder 变分自动编码器)模型有两部分,分别是一个编码器和一个解码器,常用于AI图像生成,在潜在扩散模型(Latent Diffusion Models)组成中就有VAE模型的身影
微调&控制
- Lora: 全称 low-Rank Adaptation of Large Language Models,直译为大语言模型的低阶适应器。
- hypernetworks:
- ControlNet: 一个新的神经网络概念,就是通过额外的输入来控制预训练的大模型。ControlNet 比 img2img 要更加精准和有效,可以直接提取画面的构图,人物的姿势和画面的深度信息等等
- openpose
- hed
图片修复高清
- Codeformer: 图片&脸部修复: codeformer.pth
模型:detection_Resnet50_Final.pth parsing_parsenet.pth 两个预训练模型参数权重文件;Release CodeFormer V0.1.0 Release · sczhou/CodeFormer · GitHub
- GFPGAN:腾讯开发的人脸复原算法,用于三次元脸部修复的GAN : GFPGANv1.3.pth
Downloading: "https://github.com/xinntao/fzacexlib/releases/download/v0.1.0/detection_Resnet50_Final.pth" to D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\models\GFPGAN\detection_Resnet50_Final.pth
- ESRGAM:Enhanced Super-Resolution Generative Adversarial Networks,基于SRGAN改进而来智能放大图片的模型, 适用于照片写实类(可能出现细节过于锐利的效果,但有些人喜欢这样的风格),R-ESRGAN 4x+(全能型),R-ESRGAN 4x+ Anime6B(适用于二次元),R-ESRGAN-General-WDN-4xV3(适用于厚涂插画)github.com/xinntao/Rea…
D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\models\ESRGAN
Downloading: "https://github.com/cszn/KAIR/releases/download/v1.0/ESRGAN.pth" to D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\models\ESRGAN\ESRGAN_4x.pth
Downloading: "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth" to D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\models\RealESRGAN\RealESRGAN_x4plus.pth
- SwinIR_4x: Image Restoration Using Swin Transformer SwinIR 预训练模型实现图片的超分, 需要表现光影的厚涂插画表现优于照片和二次元的图片放大,但逊于R-ESRGAN-General-WDN-4xV3 github.com/JingyunLian… SwinIR (realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN)
- LDSR照片写实类图片表现很好,插画和二次元图片不行,而且体积很大,速度很慢(好奇的话,可以尝试)
图片预处理打标
- torch-deepdanbooru: model-resnet_custom_v3.pt
- deepbooru
- deepbanbooru: deepbooru 分析图片的tag&自训练前对数据集的文本分析(现在不需要了,只需准备上面torch_deepdanbooru的权重文件)
模型:Release DeepDanbooru Pretrained Model v3-20211112-sgd-e28 · KichangKim/DeepDanbooru · GitHub GitHub - KichangKim/DeepDanbooru: AI based multi-label girl image classification system, implemented by using TensorFlow.
- BLIP: 形成了统一的理解和生成多模态模型
模型:model_base_caption_capfilt_large.pth To finetune the pre-trained checkpoint using 8 A100 GPUs, first set 'pretrained' in configs/caption_coco.yaml as "storage.googleapis.com/sfr-vision-…". Then run:
其他
- karlo
- opencv
stable diffusion 功能介绍
三大核心组成部分
-
VAE:包括Encoder编码器和Decoder解码器,用于图像从像素空间到潜空间(latent space)的转换,或者叫降维或升维,由于用于降维的VAE Encoder 只在训练模型的阶段使用,推理过程(图像生成)只需要VAE Decoder解码器
-
U-net:噪声预测器,输出预测的噪声残差,用于每次迭代过程的降噪,提供了交叉注意力层,并且通过交叉注意力机制来消耗CLIP提供的条件文本嵌入U-net,输出预测的噪声残差,实现有条件(被文本指挥)的迭代降噪。stable diffusion 训练的重点就是噪声预测器(noise predictor),它可以通过训练得出每次需要减掉的噪声,每次需要减多少噪声是预测出来的,这就是一个叫U-net的模型,从而实现还原清晰图片的目的。
-
CLIP:将Prompt文本转化成能够让U-net使用的嵌入(embedding),达到实现文本作为条件生成图片的过程,可以通过微调的方式,发出带有关键词的embedding,用于调整图片的样式。你能下载到的textual inversion就是通过这种方式实现调整生成图像效果的,优点是文件的体积非常小。
工作流程
- SD在潜空间生成随机的张量,你也可以设置种子(seed)来控制这个初始值,特定的初始值可以起到固定的作用。然后这个在潜在种子生成64 x 64的潜空间图像,Prompt通过CLIP转化77 x 768条件文本嵌入(embedding);
- U-net以这个嵌入为条件,对潜空间图像迭代降噪。U-net输出噪声的残差,通过调度器(scheduler)进行降噪计算并返回本轮的去噪样本,(而这个调度器也叫采样器或者求解器,对应了不同的算法,有各种优缺点);
- 在迭代20次后,最后VAE的解码器把最终的潜空间图像转化输入到像素空间,即我们能看到的像素图片,整个工作流到此结束,你得到了结果图片。
采样方法
Stable Diffusion在每个步骤中都会生成一张新的采样后的图像,整个去噪的过程,即采样,使用的采样手段,即为采样器或称为采样方法
经典ODE求解器
- Euler采样器:欧拉采样方法。
- Heun采样器:欧拉的一个更准确但是较慢的版本。
- LMS采样器:线性多步法,与欧拉采样器速度相仿,但是更准确。
祖先采样器
名称中带有a标识的采样器表示这一类采样器是祖先采样器。这一类采样器在每个采样步骤中都会向图像添加噪声,采样结果具有一定的随机性。
- Euler a
- DPM2 a
- DPM++ 2S a
- DPM++ 2S a Karras
Karras Noise Schedule
带有Karras字样的采样器,最大的特色是使用了Karras论文中建议的噪音计划表。主要的表现在于噪点步长在接近尾声时会更小,有助于图像的质量提升。
DDIM与PLMS(已过时,不再使用)
DDIM(去噪扩散隐式模型)和PLMS(伪线性多步方法)是伴随Stable Diffusion v1提出的采样方法,DDIM也是最早被用于扩散模型的采样器。PLMS是DDIM的一种更快的替代方案。当前这两种采样方法都不再广泛使用。
DPM与DPM++
DPM(扩散概率模型求解器)这一系列的采样器于2022年发布,代表了具有类似体系结构的求解器系列。
由于DPM会自适应调整步长,不能保证在约定的采样步骤内完成任务,整体速度可能会比较慢。对Tag的利用率较高,在使用时建议适当放大采样的步骤数以获得较好的效果。
DPM++是对DPM的改进,DPM2采用二阶方法,其结果更准确,但是相应的也会更慢一些。
UniPC
UniPC(统一预测校正器),一种可以在5-10个步骤中实现高质量图像生成的方法。
K-diffusion
用于指代Katherine Crowson's k-diffusion项目中实现的Karras 2022论文中提及的的相关采样器。当前常用的采样器中,除了DDIM、PLMS与UniPC之外的采样器均来自于k-diffusion。
打标
打标器 | 效果 | 效果(中文翻译) |
---|---|---|
Stable Diffusion webui-训练-图像预处理-BLIP | a man in a kitchen with a fire in the fireplace and a hammer in his hand and a hammer in his other hand | 一个男人在厨房里,壁炉里生着火,手里拿着锤子,另一只手拿着锤子 |
Stable Diffusion webui-训练-图像预处理-deepbooru | 1boy, black_gloves, gloves, indoors, male_focus, shirt, short_sleeves, solo | 一个男孩,黑色手套,手套,室内,男人特写,衬衫,短袖,单人 |
Stable Diffusion webui-Tagger(WD14) | 1boy, cooking, frying pan, male focus, solo, gloves, apron, fire, brown footwear, black gloves, boots, stove, kitchen, holding, facial hair, bandana, blue shirt, shirt | 一个男孩,烹饪,煎锅,男人特写,单人,手套,围裙,火,棕色鞋,黑色手套,靴子,炉子,厨房,握着,胡子,头巾,蓝色衬衫,衬衫 |
kohya webui-Utilities-Captioning-BLIP Captioning | a man is working on a piece of metal | 一个男人正在加工一块金属 |
kohya webui-Utilities-Captioning-GIT Captioning | a drawing of a blacksmith with a hammer and a glove on his hand. | 一幅画,画的是一个手上戴着手套、拿着锤子的铁匠。 |
SDWebUI 版本
SDWebUI 版本需要关注两个版本号:
- 一个是 SDWebUI 自身项目的版本号, 从 v1.1.0 开始 SDWebUI 依赖 pytorch 2.0.0 , 在这之前依赖 pytorch 1.X.X
Releases · AUTOMATIC1111/stable-diffusion-webui · GitHub
v1.0.0-pre
v1.1.0
v1.1.1
v1.2.0
v1.2.1
v1.3.0
v1.3.0-RC
v1.3.1
v1.3.1-RC
v1.3.2
v1.3.2-RC
v1.4.0
v1.4.0-RC
v1.4.1
v1.5.0
v1.5.0-RC
v1.5.1-RC
- 一个是基础模型的版本号, lora 等微调模型是基于某个版本的基础模型训练生成的, 使用时也需要选择对应版本的基础模式. 基础模型版本: 1.4, 1.5, 2.0, SDXL. 其中 1.5 版本的模型生态最为丰富.
版本升级
v1.0.0-pre - v1.5.0
- 升级 SDWebUI 自身项目的版本号, SDWebUI 版本会打一个对应版本号的 tag , 版本 v1.5.0 对应 tag v1.5.0, 使用 git 创建一个本地 branch 对应到 tag v1.5.0
git checkout -b tag/v1.5.0 v1.5.0
- 运行 webui-user.bat
- Cloning Stable Diffusion XL into ${sdweb-src}\repositories\generative-models
Cloning Stable Diffusion XL into D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\repositories\generative-models...
Cloning into 'D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\repositories\generative-models'...
- pytorch 版本检查, 因为 v1.0.0-pre 使用的 pytorch 1.13.1+cu117, v1.5.0 使用 pytorch 2.0.0 , 会提示升级 pytorch
You are running torch 1.13.1+cu117.
The program is tested to work with torch 2.0.0.
To reinstall the desired version, run with commandline flag --reinstall-torch.
Beware that this will cause a lot of large files to be downloaded, as well as
there are reports of issues with training tab on the latest version.
Use --skip-version-check commandline argument to disable this check.
- 手动升级 pytorch 版本, 在 download.pytorch.org/whl/torch_s… 页面下载 2.0.0 版本 torch 的三个库, 分别是 torch, torchaudio, torchvision. 将其安装到已经存在的 venv 环境中.
# 1. 设置 PYTHON 环境变量指向 venv 环境中的 python.exe
(sdwebui_py_3106) E:\libs\torch\2.0.0-cu117-cp310>set PYTHON="D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\Scripts\Python.exe"
# 2. 验证 %PYTHON% 设置正确
(sdwebui_py_3106) E:\libs\torch\2.0.0-cu117-cp310>%PYTHON%
Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
# 3. 使用 %PYTHON% -m pip install 命令分别安装之前下载 torch, torchaudio, torchvision
(sdwebui_py_3106) E:\libs\torch\2.0.0-cu117-cp310>%PYTHON% -m pip install "torch-2.0.0+cu117-cp310-cp310-win_amd64.whl"
(sdwebui_py_3106) E:\libs\torch\2.0.0-cu117-cp310>%PYTHON% -m pip install "torchaudio-2.0.0+cu117-cp310-cp310-win_amd64.whl"
(sdwebui_py_3106) E:\libs\torch\2.0.0-cu117-cp310>%PYTHON% -m pip install "torchvision-0.15.0+cu117-cp310-cp310-win_amd64.whl"
完整日志
(sdwebui_py_3106) D:\workspace\project\stablediffusion\sdwebui\sdwebui-src>webui-user.bat
venv "D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\Scripts\Python.exe"
Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)]
Version: v1.5.0
Commit hash: a3ddf464a2ed24c999f67ddfef7969f8291567be
Cloning Stable Diffusion XL into D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\repositories\generative-models...
Cloning into 'D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\repositories\generative-models'...
remote: Enumerating objects: 424, done.
remote: Counting objects: 100% (221/221), done.
remote: Compressing objects: 100% (135/135), done.
remote: Total 424 (delta 120), reused 133 (delta 77), pack-reused 203
Receiving objects: 100% (424/424), 22.27 MiB | 792.00 KiB/s, done.
Resolving deltas: 100% (188/188), done.
Fetching updates for K-diffusion...
Checking out commit for K-diffusion with hash: c9fe758757e022f05ca5a53fa8fac28889e4f1cf...
Previous HEAD position was 5b3af03 Release 0.0.12
HEAD is now at c9fe758 Release 0.0.15
Installing requirements
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: send2trash~=1.8 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (1.8.2)
Requirement already satisfied: dynamicprompts[attentiongrabber,magicprompt]~=0.27.0 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (0.27.0)
Requirement already satisfied: pyparsing~=3.0 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (3.0.9)
Requirement already satisfied: jinja2~=3.1 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (3.1.2)
Requirement already satisfied: transformers[torch]~=4.19 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (4.25.1)
Requirement already satisfied: MarkupSafe>=2.0 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from jinja2~=3.1->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (2.1.2)
Requirement already satisfied: tqdm>=4.27 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (4.65.0)
Requirement already satisfied: tokenizers!=0.11.3,<0.14,>=0.11.1 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (0.13.3)
Requirement already satisfied: huggingface-hub<1.0,>=0.10.0 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (0.13.4)
Requirement already satisfied: numpy>=1.17 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (1.23.5)
Requirement already satisfied: packaging>=20.0 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (23.1)
Requirement already satisfied: pyyaml>=5.1 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (6.0)
Requirement already satisfied: regex!=2019.12.17 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (2023.3.23)
Requirement already satisfied: filelock in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (3.11.0)
Requirement already satisfied: requests in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (2.25.1)
Requirement already satisfied: torch!=1.12.0,>=1.7 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (1.13.1+cu117)
Requirement already satisfied: typing-extensions>=3.7.4.3 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from huggingface-hub<1.0,>=0.10.0->transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (4.5.0)
Requirement already satisfied: colorama in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from tqdm>=4.27->transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (0.4.6)
Requirement already satisfied: idna<3,>=2.5 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from requests->transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (2.10)
Requirement already satisfied: certifi>=2017.4.17 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from requests->transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (2022.12.7)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from requests->transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (1.26.15)
Requirement already satisfied: chardet<5,>=3.0.2 in d:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\lib\site-packages (from requests->transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (4.0.0)
sd-dynamic-prompts installer: running 'D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\venv\Scripts\python.exe' -m pip install 'send2trash~=1.8' 'dynamicprompts[attentiongrabber,magicprompt]~=0.27.0'
Launching Web UI with arguments: --no-half --api
no module 'xformers'. Processing without...
No SDP backend available, likely because you are running in pytorch versions < 2.0. In fact, you are using PyTorch 1.13.1+cu117. You might want to consider upgrading.
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
==============================================================================
You are running torch 1.13.1+cu117.
The program is tested to work with torch 2.0.0.
To reinstall the desired version, run with commandline flag --reinstall-torch.
Beware that this will cause a lot of large files to be downloaded, as well as
there are reports of issues with training tab on the latest version.
Use --skip-version-check commandline argument to disable this check.
==============================================================================
[AddNet] Updating model hashes...
100%|█████████████████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00, 2121.55it/s]
[AddNet] Updating model hashes...
100%|██████████████████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00, 841.64it/s]
Loading weights [4d38461a2c] from D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\models\Stable-diffusion\XSarchitectural-InteriorDesign-ForXSLora_XSarchitecturalV10InteriorDesignForXSLora_3000.ckpt.ckpt
*Deforum ControlNet support: enabled*
'ControlNet UI setup failed with error: 'module 'extensions.sd-webui-controlnet.scripts.external_code' has no attribute 'get_modules_detail''!
*** Error executing callback ui_tabs_callback for D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\extensions\deforum-for-automatic1111-webui\scripts\deforum.py
Traceback (most recent call last):
File "D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\modules\script_callbacks.py", line 153, in ui_tabs_callback
res += c.callback() or []
File "D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\extensions\deforum-for-automatic1111-webui\scripts\deforum_helpers\ui_right.py", line 85, in on_ui_tabs
component_list = [components[name] for name in get_component_names()]
File "D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\extensions\deforum-for-automatic1111-webui\scripts\deforum_helpers\ui_right.py", line 85, in <listcomp>
component_list = [components[name] for name in get_component_names()]
KeyError: 'cn_1_overwrite_frames'
---
Creating model from config: D:\workspace\project\stablediffusion\sdwebui\sdwebui-src\configs\v1-inference.yaml
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Applying attention optimization: Doggettx... done.
Model loaded in 27.3s (load weights from disk: 4.1s, create model: 1.2s, apply weights to model: 15.5s, load VAE: 0.5s, move model to device: 5.5s, calculate empty prompt: 0.2s).
Running on local URL: http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.
Startup time: 123.5s (launcher: 79.5s, import torch: 5.9s, import gradio: 2.3s, setup paths: 1.9s, other imports: 2.2s, setup codeformer: 0.2s, list SD models: 0.1s, load scripts: 2.5s, create ui: 28.0s, gradio launch: 0.3s, add APIs: 0.5s).