一、stable-diffusion介绍
Stable Diffusion是2022年发布的深度学习文本到图像生成模型,它主要用于根据文本的描述产生详细图像,尽管它也可以应用于其他任务,如内补绘制、外补绘制,以及在提示词(英语)指导下产生图生图的翻译。
二、stable-diffusion下载
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
三、创建项目
3.1、创建stable-diffusion虚拟环境
conda create -n sd python=3.10.6
3.2、激活环境
conda activate sd
3.3、进入项目
cd D:\workspace\opensource\openai\stable-diffusion-webui
(sd) D:\workspace\opensource\openai\stable-diffusion-webui>dir
驱动器 D 中的卷没有标签。
卷的序列号是 789E-0657
D:\workspace\opensource\openai\stable-diffusion-webui 的目录
2023/11/14 15:22 <DIR> .
2023/11/14 15:22 <DIR> ..
2023/11/14 15:22 51 .eslintignore
2023/11/14 15:22 3,479 .eslintrc.js
2023/11/14 15:22 56 .git-blame-ignore-revs
2023/11/14 15:22 <DIR> .github
2023/11/14 15:22 534 .gitignore
2023/11/14 15:22 122 .pylintrc
2023/11/14 15:22 33,676 CHANGELOG.md
2023/11/14 15:22 250 CITATION.cff
2023/11/14 15:22 657 CODEOWNERS
2023/11/14 15:22 <DIR> configs
2023/11/14 15:22 <DIR> embeddings
2023/11/14 15:22 178 environment-wsl2.yaml
2023/11/14 15:22 <DIR> extensions
2023/11/14 15:22 <DIR> extensions-builtin
2023/11/14 15:22 <DIR> html
2023/11/14 15:22 <DIR> javascript
2023/11/14 15:22 1,297 launch.py
2023/11/14 15:22 35,240 LICENSE.txt
2023/11/14 15:22 <DIR> localizations
2023/11/14 15:22 <DIR> models
2023/11/14 15:22 <DIR> modules
2023/11/14 15:22 196 package.json
2023/11/14 15:22 798 pyproject.toml
2023/11/14 15:22 11,860 README.md
2023/11/14 15:22 52 requirements-test.txt
2023/11/14 15:22 360 requirements.txt
2023/11/14 15:22 556 requirements_versions.txt
2023/11/14 15:22 420,577 screenshot.png
2023/11/14 15:22 4,899 script.js
2023/11/14 15:22 <DIR> scripts
2023/11/14 15:22 21,496 style.css
2023/11/14 15:22 <DIR> test
2023/11/14 15:22 <DIR> textual_inversion_templates
2023/11/14 15:22 687 webui-macos-env.sh
2023/11/14 15:22 92 webui-user.bat
2023/11/14 15:22 1,380 webui-user.sh
2023/11/14 15:22 2,223 webui.bat
2023/11/14 15:22 5,471 webui.py
2023/11/14 15:22 8,353 webui.sh
3.4、下载模型
3.5、项目模型存储的地址
D:\workspace\opensource\openai\stable-diffusion-webui\models\Stable-diffusion
3.6、修改配置文件launch_utils.py
def prepare_environment():
torch_index_url = os.environ.get('TORCH_INDEX_URL', "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/")
torch_command = os.environ.get('TORCH_COMMAND', f"pip install torch==2.0.1 torchvision==0.15.2 --extra-index-url {torch_index_url}")
requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt")
xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.20')
clip_package = os.environ.get('CLIP_PACKAGE', "https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip")
openclip_package = os.environ.get('OPENCLIP_PACKAGE', "https://github.moeyy.xyz/https://github.com/mlfoundations/open_clip/archive/bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b.zip")
stable_diffusion_repo = os.environ.get('STABLE_DIFFUSION_REPO', "https://github.com/Stability-AI/stablediffusion.git")
stable_diffusion_xl_repo = os.environ.get('STABLE_DIFFUSION_XL_REPO', "https://github.com/Stability-AI/generative-models.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.moeyy.xyz/https://github.com/sczhou/CodeFormer.git')
blip_repo = os.environ.get('BLIP_REPO', 'https://github.com/salesforce/BLIP.git')
stable_diffusion_commit_hash = os.environ.get('STABLE_DIFFUSION_COMMIT_HASH', "cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf")
stable_diffusion_xl_commit_hash = os.environ.get('STABLE_DIFFUSION_XL_COMMIT_HASH', "45c443b316737a4ab6e40413d7794a7f5657c19f")
k_diffusion_commit_hash = os.environ.get('K_DIFFUSION_COMMIT_HASH', "ab527a9a6d347f364e3d185ba6d714e22d80cb3c")
codeformer_commit_hash = os.environ.get('CODEFORMER_COMMIT_HASH', "c5b4593074ba6214284d6acd5f1719b6c5d739af")
blip_commit_hash = os.environ.get('BLIP_COMMIT_HASH', "48211a1594f1321b00f14c9f7a5b4813144b2fb9")
3.7、安装环境
python -m pip install -r requirements.txt -i https://pypi.douban.com/simple/
3.8、启动webui.bat
start webui.bat
Creating venv in directory D:\workspace\opensource\openai\stable-diffusion-webui\venv using python "d:\ProgramData\miniconda3\envs\sd\python.exe"
venv "D:\workspace\opensource\openai\stable-diffusion-webui\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.6.0-2-g4afaaf8a
Commit hash: 4afaaf8a020c1df457bcf7250cb1c7f609699fa7
Installing torch and torchvision
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cu118