Stable Diffusion Web UI + Anaconda環(huán)境 + 本地Windows系統(tǒng)部署
最近的很多AIGC模型層出不窮,Stable Diffusion 模型作為一個開源的熱門生成式模型,或許對未來的各行各業(yè)都能產(chǎn)生深遠的影響,了解這個模型并會使用可能是很多人目前想要學習的,本篇博客還原了本人從0-1的一個安裝+部署過程,希望對屏幕前的各位讀者有用,謝謝!創(chuàng)作不易,喜歡的可以點贊收藏
為什么要用anaconda? 原因其實很簡單,anaconda可以做到環(huán)境隔離,即在創(chuàng)建好的環(huán)境中進行安裝,不會影響其他程序或者模型的使用
Stable Diffusion Web UI 項目來源于github,鏈接:https://github.com/AUTOMATIC1111/stable-diffusion-webui,截至今日有著64.5k的star數(shù)量。
Stable Diffusion Web UI 項目部署在本地,可以正常應用的一個界面:
可以看到,我這prompt 框中加入了一些prompt 信息,A painting of a cute goldendoodle in the sky, wearing a suit, natural light, with bright colors, by Studio Ghibli
(入門)Stable Diffusion怎么寫prompt?
其中的關鍵詞意思:
提出問題:您想要一張照片還是一幅畫?照片的主題是什么?人物?動物或者風景?您想要添加哪些細節(jié)?
1 特殊照明。柔和、環(huán)形、霓虹
2 環(huán)境。室內、室外、水下、太空
3 顏色方案。鮮艷、暗淡、粉彩
4 視角。正面、俯視、側面
5 背景。純色、星云、森林
6 采用特定的藝術風格嗎?3D渲染、工作室、電影海報
7 特定的照片類型?微距、長焦
回答問題整理出prompt:
現(xiàn)在我們假設來回答上面的問題,然后嘗試整理出我們需要的prompt
你想要一張照片還是一幅畫? => 畫 (painting)
照片的主題是什么? 人物。動物,風景。=> 一只金毛犬 (a cute goldendoodle)
你希望添加什么細節(jié)? => 穿著西裝 (wearing a suit)
特殊照明。 柔和的、環(huán)境的、環(huán)形光、霓虹燈=> (natural light)
環(huán)境。 室內、室外、水下、太空中 => 在天空中 (in the sky)
色彩方案。 鮮艷的、深色的、粉色的 => 有明亮的顏色 (bright colors)
在特定的藝術風格? 3D渲染,吉卜力工作室,電影海報 => 工作室出品
我們匯總下我們的prompt如下:
A painting of a cute goldendoodle in the sky, wearing a suit, natural light, with bright colors, by Studio Ghibli
利用元素法典https://docs.qq.com/doc/DWHl3am5Zb05QbGVs進行繪制,僅供參考
接下來是我要推薦的博客,我本人也是根據(jù)這些博客以及之前的一些模型經(jīng)驗進行的安裝:
1、全網(wǎng)最能打的AI部署教程,Anaconda環(huán)境完美本地部署Stable-Diffusion-Webui+novelAI
2、【AI作畫】使用stable-diffusion-webui搭建AI作畫平臺
據(jù)說還有秋葉整合包,博主并沒有特意去找,下一步計劃是找一下資源,學習一下
1、創(chuàng)建anaconda環(huán)境
1)官方倉庫推薦的是python 3.10.6的版本
創(chuàng)建一個命名為sdaigc的python環(huán)境
conda create -n sdaigc python=3.10.6
2)安裝 torch、torchvision、torchaudio,,這里博主機器的cuda 是11.1版本,但按照之前的經(jīng)驗,在ananconda中安裝cuda11.3是可以向下兼容的,
進入pytorch官網(wǎng)https://pytorch.org/get-started/previous-versions/,,使用pip命令下載
# CUDA 11.3
pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113
驗證創(chuàng)建環(huán)境,pytorch是否安裝正確,可以使用
annconada command輸入
activate sdaigc
python
import torch
print(torch.cuda.is_available())
>>True
2、克隆stable-diffusion-webui 至本地,并安裝依賴項
拉取stable-diffsion-webui項目,克隆至本地:
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
這里我克隆的位置在E:\stable diffusion\stable-diffusion-webui并提前下好模型權重,放置在E:\stable diffusion\stable-diffusion-webui\models\Stable-diffusion中,
模型權重可以從https://huggingface.co/CompVis/stable-diffusion-v-1-4-original中下載,3.97g
也可以在https://rentry.org/sdmodels中查找所需
或可以通過博主的百度云鏈接進行下載:鏈接:https://pan.baidu.com/s/1hFOBkPYSb4-D7Bv9D9GxdQ 提取碼:39c6
激活創(chuàng)建好的conda環(huán)境后,進入stable-diffusion-webui文件主目錄,使用以下指令安裝依賴
pip install -r requirements.txt
沒有報錯后,在stable-diffusion-webui文件主目錄使用以下指令,運行stable-diffusion-webui
python lauch.py
然而會出現(xiàn)以下的N多問題
!?。∮捎谖医鉀Q這些問題時,并未對報錯的提示進行截圖整理或者復制,這里主要借用了【AI作畫】使用stable-diffusion-webui搭建AI作畫平臺整理的內容,以下的截圖均使用這篇博客的?。?!
我遇到的問題一:
安裝CLIP時提示Connection was aborted, errno 10053
出錯時的錯誤打印如下:
(novelai) E:\workspace\02_Python\novalai\stable-diffusion-webui>python launch.py
Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)]
Commit hash: b8f2dfed3c0085f1df359b9dc5b3841ddc2196f0
Installing clip
Traceback (most recent call last):
File "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 251, in <module>
prepare_enviroment()
File "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 178, in prepare_enviroment
run_pip(f"install {clip_package}", "clip")
File "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 63, 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 "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 34, in run
raise RuntimeError(message)
RuntimeError: Couldn't install clip.
Command: "D:\anaconda3\envs\novelai\python.exe" -m pip install git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 --prefer-binary
Error code: 1
stdout: Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1
Cloning https://github.com/openai/CLIP.git (to revision d50d76daa670286dd6cacf3bcd80b5e4823fc8e1) to c:\users\yefuf\appdata\local\temp\pip-req-build-f8w7kbzg
stderr: Running command git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git 'C:\Users\yefuf\AppData\Local\Temp\pip-req-build-f8w7kbzg'
fatal: unable to access 'https://github.com/openai/CLIP.git/': OpenSSL SSL_read: Connection was aborted, errno 10053
error: subprocess-exited-with-error
git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git 'C:\Users\yefuf\AppData\Local\Temp\pip-req-build-f8w7kbzg' 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/openai/CLIP.git 'C:\Users\yefuf\AppData\Local\Temp\pip-req-build-f8w7kbzg' 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.
通過訪CLIP項目GitHub主頁,發(fā)現(xiàn)該項目可以通過如下命令進行安裝解決。
pip install ftfy regex tqdm
pip install git+https://github.com/openai/CLIP.git
我遇到的問題二:項目啟動中提示Connection was reset in connection to github.com
出錯時的錯誤打印如下:
(novelai) E:\workspace\02_Python\novalai\stable-diffusion-webui>python launch.py
Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)]
Commit hash: b8f2dfed3c0085f1df359b9dc5b3841ddc2196f0
Cloning Stable Diffusion into repositories\stable-diffusion...
Cloning Taming Transformers into repositories\taming-transformers...
Traceback (most recent call last):
File "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 251, in <module>
prepare_enviroment()
File "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 201, in prepare_enviroment
git_clone(taming_transformers_repo, repo_dir('taming-transformers'), "Taming Transformers", taming_transformers_commit_hash)
File "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 85, in git_clone
run(f'"{git}" clone "{url}" "{dir}"', f"Cloning {name} into {dir}...", f"Couldn't clone {name}")
File "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 34, in run
raise RuntimeError(message)
RuntimeError: Couldn't clone Taming Transformers.
Command: "git" clone "https://github.com/CompVis/taming-transformers.git" "repositories\taming-transformers"
Error code: 128
stdout: <empty>
stderr: Cloning into 'repositories\taming-transformers'...
fatal: unable to access 'https://github.com/CompVis/taming-transformers.git/': OpenSSL SSL_connect: Connection was reset in connection to github.com:443
查看lauch.py中的代碼可以發(fā)現(xiàn),程序在啟動時有對依賴項目進行檢查,如項目不存在,則克隆下來。
def prepare_enviroment():
torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113")
requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt")
commandline_args = os.environ.get('COMMANDLINE_ARGS', "")
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")
deepdanbooru_package = os.environ.get('DEEPDANBOORU_PACKAGE', "git+https://github.com/KichangKim/DeepDanbooru.git@d91a2963bf87c6a770d74894667e9ffa9f6de7ff")
xformers_windows_package = os.environ.get('XFORMERS_WINDOWS_PACKAGE', 'https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/f/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl')
stable_diffusion_repo = os.environ.get('STABLE_DIFFUSION_REPO', "https://github.com/CompVis/stable-diffusion.git")
taming_transformers_repo = os.environ.get('TAMING_REANSFORMERS_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('CODEFORMET_REPO', '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', "69ae4b35e0a0f6ee1af8bb9a5d0016ccb27e36dc")
taming_transformers_commit_hash = os.environ.get('TAMING_TRANSFORMERS_COMMIT_HASH', "24268930bf1dce879235a7fddd0b2355b84d7ea6")
k_diffusion_commit_hash = os.environ.get('K_DIFFUSION_COMMIT_HASH', "f4e99857772fc3a126ba886aadf795a332774878")
codeformer_commit_hash = os.environ.get('CODEFORMER_COMMIT_HASH', "c5b4593074ba6214284d6acd5f1719b6c5d739af")
blip_commit_hash = os.environ.get('BLIP_COMMIT_HASH', "48211a1594f1321b00f14c9f7a5b4813144b2fb9")
因此,還是利用git bash重新執(zhí)行下述git命令,預先將項目克隆下來。
git clone https://github.com/Stability-AI/stablediffusion.git "E:\stable diffusion\stable-diffusion-webui\repositories\stable-diffusion-stability-ai"
git clone https://github.com/CompVis/taming-transformers.git "repositories\taming-transformers"
git clone https://github.com/crowsonkb/k-diffusion.git "repositories\k-diffusion"
git clone https://github.com/sczhou/CodeFormer.git "repositories\CodeFormer"
git clone https://github.com/salesforce/BLIP.git "repositories\BLIP"
文件夾如下所示:
3、再次運行
python lauch.py
會發(fā)現(xiàn),有以下報錯:
(sdaigc) E:\stable diffusion\stable-diffusion-webui>python launch.py
Python 3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:29:51) [MSC v.1929 64 bit (AMD64)]
Commit hash: 22bcc7be428c94e9408f589966c2040187245d81
Installing requirements for Web UI
Launching Web UI with arguments:
No module 'xformers'. Proceeding without it.
==============================================================================
You are running torch 1.11.0+cu113.
The program is tested to work with torch 1.13.1.
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.
==============================================================================
Calculating sha256 for E:\stable diffusion\stable-diffusion-webui\models\Stable-diffusion\sd-v1-4.ckpt: fe4efff1e174c627256e44ec2991ba279b3816e364b49f9be2abc0b3ff3f8556
Loading weights [fe4efff1e1] from E:\stable diffusion\stable-diffusion-webui\models\Stable-diffusion\sd-v1-4.ckpt
Error verifying pickled file from E:\stable diffusion\stable-diffusion-webui\models\Stable-diffusion\sd-v1-4.ckpt:
Traceback (most recent call last):
File "E:\stable diffusion\stable-diffusion-webui\modules\safe.py", line 135, in load_with_extra
check_pt(filename, extra_handler)
File "E:\stable diffusion\stable-diffusion-webui\modules\safe.py", line 93, in check_pt
unpickler.load()
File "E:\stable diffusion\stable-diffusion-webui\modules\safe.py", line 30, in persistent_load
return TypedStorage()
File "E:\Anaconda\envs\sdaigc\lib\site-packages\torch\storage.py", line 270, in __init__
assert type(self) != _TypedStorage, (
AssertionError: Calling __init__ this way is only supported in _TypedStorage's child classes. _TypedStorage can only be directly instantiated when kwargs 'wrap_storage' and 'dtype' are given.
The file may be malicious, so the program is not going to read it.
You can skip this check with --disable-safe-unpickle commandline argument.
loading stable diffusion model: AttributeError
Traceback (most recent call last):
File "E:\stable diffusion\stable-diffusion-webui\webui.py", line 139, in initialize
modules.sd_models.load_model()
File "E:\stable diffusion\stable-diffusion-webui\modules\sd_models.py", line 415, in load_model
state_dict = get_checkpoint_state_dict(checkpoint_info, timer)
File "E:\stable diffusion\stable-diffusion-webui\modules\sd_models.py", line 262, in get_checkpoint_state_dict
res = read_state_dict(checkpoint_info.filename)
File "E:\stable diffusion\stable-diffusion-webui\modules\sd_models.py", line 248, in read_state_dict
sd = get_state_dict_from_checkpoint(pl_sd)
File "E:\stable diffusion\stable-diffusion-webui\modules\sd_models.py", line 197, in get_state_dict_from_checkpoint
pl_sd = pl_sd.pop("state_dict", pl_sd)
AttributeError: 'NoneType' object has no attribute 'pop'
主要是這句話:
The file may be malicious, so the program is not going to read it.
You can skip this check with --disable-safe-unpickle commandline argument.
所以再次運行如下指令:
python launch.py --disable-safe-unpickle
運行成功
(sdaigc) E:\stable diffusion\stable-diffusion-webui>python launch.py --disable-safe-unpickle
Python 3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:29:51) [MSC v.1929 64 bit (AMD64)]
Commit hash: 22bcc7be428c94e9408f589966c2040187245d81
Installing requirements for Web UI
Launching Web UI with arguments: --disable-safe-unpickle
No module 'xformers'. Proceeding without it.
==============================================================================
You are running torch 1.11.0+cu113.
The program is tested to work with torch 1.13.1.
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.
==============================================================================
Loading weights [fe4efff1e1] from E:\stable diffusion\stable-diffusion-webui\models\Stable-diffusion\sd-v1-4.ckpt
Creating model from config: E:\stable diffusion\stable-diffusion-webui\configs\v1-inference.yaml
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Downloading (…)olve/main/vocab.json: 100%|███████████████████████████████████████████| 961k/961k [00:02<00:00, 386kB/s]
Downloading (…)olve/main/merges.txt: 100%|███████████████████████████████████████████| 525k/525k [00:01<00:00, 517kB/s]
Downloading (…)cial_tokens_map.json: 100%|█████████████████████████████████████████████| 389/389 [00:00<00:00, 390kB/s]
Downloading (…)okenizer_config.json: 100%|█████████████████████████████████████████████| 905/905 [00:00<00:00, 890kB/s]
Downloading (…)lve/main/config.json: 100%|████████████████████████████████████████| 4.52k/4.52k [00:00<00:00, 4.59MB/s]
Applying cross attention optimization (Doggettx).
Textual inversion embeddings loaded(0):
Model loaded in 50.5s (load weights from disk: 2.9s, create model: 15.2s, apply weights to model: 25.7s, apply half(): 1.9s, move model to device: 2.5s, load textual inversion embeddings: 2.3s).
Running on local URL: http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.
Startup time: 60.4s (import torch: 2.5s, import gradio: 2.6s, import ldm: 1.0s, other imports: 1.5s, load scripts: 0.9s, load SD checkpoint: 51.0s, create ui: 0.4s, gradio launch: 0.4s).
100%|██████████████████████████████████████████████████████████████████████████████████| 20/20 [00:29<00:00, 1.49s/it]
Total progress: 100%|██████████████████████████████████████████████████████████████████| 20/20 [00:24<00:00, 1.24s/it]
100%|██████████████████████████████████████████████████████████████████████████████████| 20/20 [00:27<00:00, 1.38s/it]
Total progress: 100%|██████████████████████████████████████████████████████████████████| 20/20 [00:26<00:00, 1.35s/it]
100%|██████████████████████████████████████████████████████████████████████████████████| 20/20 [00:22<00:00, 1.14s/it]
Total progress: 100%|██████████████████████████████████████████████████████████████████| 20/20 [00:22<00:00, 1.13s/it]
100%|██████████████████████████████████████████████████████████████████████████████████| 20/20 [00:23<00:00, 1.20s/it]
Total progress: 100%|██████████████████████████████████████████████████████████████████| 20/20 [00:23<00:00, 1.18s/it]
15%|████████████▍ | 3/20 [00:04<00:27, 1.59s/it]
Total progress: 15%|██████████ | 3/20 [00:04<00:24, 1.45s/it]
100%|██████████████████████████████████████████████████████████████████████████████████| 20/20 [00:22<00:00, 1.13s/it]
Total progress: 100%|██████████████████████████████████████████████████████████████████| 20/20 [00:22<00:00, 1.12s/it]
100%|██████████████████████████████████████████████████████████████████████████████████| 20/20 [00:45<00:00, 2.28s/it]
Total progress: 100%|██████████████████████████████████████████████████████████████████| 20/20 [00:45<00:00, 2.28s/it]
Data shape for DDIM sampling is (2, 4, 64, 64), eta 0.0████████████████████████████████| 20/20 [00:45<00:00, 2.20s/it]
Running DDIM Sampling with 50 timesteps
DDIM Sampler: 8%|█████▌ | 4/50 [00:13<02:39, 3.46s/it]
Total progress: 8%|█████▎ | 4/50 [00:12<02:29, 3.24s/it]
Data shape for DDIM sampling is (1, 4, 64, 64), eta 0.0 | 4/50 [00:12<02:05, 2.72s/it]
Running DDIM Sampling with 50 timesteps
DDIM Sampler: 100%|████████████████████████████████████████████████████████████████████| 50/50 [01:08<00:00, 1.36s/it]
Total progress: 100%|██████████████████████████████████████████████████████████████████| 50/50 [01:07<00:00, 1.35s/it]
Total progress: 100%|██████████████████████████████████████████████████████████████████| 50/50 [01:07<00:00, 1.35s/it]
除此之外還有一個**No module ‘xformers’. Proceeding without it.**的提示,這里可以無視它,我也找了以下兩篇博客用以解決該問題,僅供參考
No module ‘xformers‘. Proceeding without it.
安裝Stable Diffusion WebUI 幾種報錯的解決方法
4、關于Stable Diffusion WebUI漢化
1)安裝sd-webui-bilingual-localization插件,在擴展選項卡的“install from”輸入URL:https://github.com/journey-ad/sd-webui-bilingual-localization,點擊完成安裝。
在“installed”看到已經(jīng)完成安裝的sd-webui-bilingual-localization插件,重啟UI。
2)下載漢化包
stable-diffusion-webui-localization-zh_CN漢化包
將壓縮包解壓,找到localizations目錄下的zh_CN.json文件,把它放到<stable diffusion根目錄>/localizations下。
再次運行如下指令:文章來源:http://www.zghlxwxcb.cn/news/detail-445059.html
python launch.py --disable-safe-unpickle --autolaunch
選中zh_CN
漢化版UI界面
參考博客:
stable diffusion漢化教程
Stable Diffusion AI 繪畫工具漢化文章來源地址http://www.zghlxwxcb.cn/news/detail-445059.html
到了這里,關于Stable Diffusion Web UI + Anaconda環(huán)境 + 本地Windows系統(tǒng)部署的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!