私の CSDN へようこそ: https://spike.blog.csdn.net/
この記事のアドレス: https://spike.blog.csdn.net/article/details/131528224
Stable Diffusion WebUIは、深層学習に基づいた画像生成ツールで、ユーザーが入力したテキストや画像をもとに高品質な画像を新たに生成します。
- 顔の生成、スタイルの転送、画像の修復、画像の超解像度など、さまざまな画像生成タスクをサポートします。
- 画像生成の中核アルゴリズムとして安定拡散モデル (Stable Diffusion Model) を使用するこのモデルは、高効率、安定性、制御性という利点を備えています。
- ユーザーがソフトウェアやプラグインをインストールせずにブラウザ経由でアクセスして使用できる、使いやすい Web インターフェイスを提供します。
- カスタムパラメータとモデルをサポートし、ユーザーは自分のニーズと好みに応じて画像生成の効果とスタイルを調整できます。
Stable Diffusion WebUI は、あらゆる種類のユーザーに適した画像生成ツールです。プロのデザイナー、アーティスト、写真家、あるいは一般の愛好家や学習者であっても、ここで創造性と想像力を発揮して、必要な画像を生成できます。
WebUI 環境を実行します。
source venv/bin/activate
python launch.py --port 9301 --listen --xformers
nohup python -u launch.py --port 9301 --listen --xformers > nohup.sd.out &
ウェブ版:
- GitHub:https://github.com/AUTOMATIC1111/stable-diffusion-webui
- インストールドキュメント: https://stable-diffusion-book.vercel.app/install/WebUi/launch/
1. 環境構築
プロジェクトをダウンロードします (約 23118 個のプロジェクト ファイル、ダウンロード速度が遅い):
git clone [email protected]:AUTOMATIC1111/stable-diffusion-webui.git
環境を自動的に構成します (より多くの Python 環境をインストールする必要があり、ダウンロード速度が遅くなります)。
cd stable-diffusion-webui
bash webui.sh # 自动安装环境
ログは次のとおりです。
################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye)
################################################################
################################################################
Running on chenlong user
################################################################
################################################################
Repo already cloned, using it as install directory
################################################################
################################################################
Create and activate python venv
################################################################
デフォルトで構成された Python 環境は次の場所にあります。stable-diffusion-webui/venv/bin/activate
つまり、仮想環境を使用しますvirtualenv
。
conda deactivate # 取消 conda
source venv/bin/activate # 激活
PyTorch GPU エラーが発生した場合は、PyTorch を再インストールしてください。
問題が発生したため、仮想環境でいくつかのパッケージを手動でインストールし、Python パッケージのバージョンの競合を解決するように注意してください。
pip install einops==0.3.0 kornia==0.6 omegaconf==2.1.1 pytorch-lightning==1.4.2 torchmetrics==0.6.0 transformers==4.26.1 torch==2.0.1 torchvision==0.15.2 google-auth==2.22.0rc1 urllib3==1.26.16
pip install facexlib==0.3.0 tb-nightly==2.14.0a20230702 sdkit==1.0.112 opencv-python==4.6.0.66 -i https://mirrors.aliyun.com/pypi/simple
# 需要安装
# pip install git+https://ghproxy.com/https://github.com/mlfoundations/open_clip.git --prefer-binary
pip install open-clip-torch==2.0.2 deepspeed==0.9.5
pip install opencv-python-headless==4.8.0.74 opencv-python==4.8.0.74
デフォルトで構成されたプロジェクト環境は次の場所にあります。stable-diffusion-webui/repositories
依存プロジェクトを手動でダウンロードします。
cd repositories/
git clone https://ghproxy.com/https://github.com/Stability-AI/stablediffusion.git stable-diffusion-stability-ai
git clone https://ghproxy.com/https://github.com/crowsonkb/k-diffusion.git/ k-diffusion
git clone https://ghproxy.com/https://github.com/sczhou/CodeFormer.git
git clone https://ghproxy.com/https://github.com/salesforce/BLIP.git
git clone https://ghproxy.com/https://github.com/CompVis/taming-transformers
最後の 5 つのフォルダー:
BLIP/
CodeFormer/
k-diffusion/
stable-diffusion-stability-ai/
taming-transformers/
WebUI 環境を実行します。
conda deactivate
source venv/bin/activate
python launch.py --port 9301 --xformers
正常に開始されました:
Bug1: 遭遇バグ「AttributeError: module 'open_clip' has noattribute 'transformer'」
ソースからインストールするにはopen_clip
、次のことができます。
pip install git+https://github.com/mlfoundations/open_clip.git --prefer-binary
**バグ 2: 遇到バグ「FileNotFoundError: チェックポイントが見つかりません。安定拡散のチェックポイントを探す場合」 **
安定拡散モデルがダウンロードされていません。つまり、次のとおりです。
FileNotFoundError: No checkpoints found. When searching for checkpoints, looked at:
- file /nfs/chenlong/stable_diffusion/stable-diffusion-webui/model.ckpt
- directory /nfs/chenlong/stable_diffusion/stable-diffusion-webui/models/Stable-diffusion
Can't run without a checkpoint. Find and place a .ckpt or .safetensors file into any of those locations.
手動ダウンロード、約 4G
cd models/Stable-diffusion
wget https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors
Bug3: 遇到Bug 「モジュール「xformers」がありません。それなしで続行します。」
Xformers はインストールされています。これはバグではありません。起動コマンド パラメーターがないため、パラメーターlaunch.py
を追加するだけです。--xformers
python launch.py --port 9301 --listen --xformers
バグ 4: バグ「TCMalloc が見つからない」が発生しました。
インストールパッケージがありませんgoogle-perftools
。インストールしてください。
sudo apt install --no-install-recommends google-perftools
バグ5: 遭遇しましたRuntimeError: Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check
理由は、PyTorch のインストールが異常であるためですが、Python では をimport torch
呼び出すと、 という例外も発生します
ImportError: cannot import name '_get_cpp_backtrace' from 'torch._C'
。
PyTorch を再インストールするだけです。つまり、最初に PyTorch を確認してアンインストールしてから、以下をインストールします。
pip list | grep torch
pip uninstall torch torchvision
pip install torch==2.0.1 torchvision==0.15.2
コマンドをテストして、PyTorch が正しく動作していることを確認します。
import torch
print(torch.__version__) # 2.0.1+cu117
import torchvision
print(torchvision.__version__) # 0.15.2+cu117
次のコマンドを使用して確認することもできます。
python -c "import torchvision; print(torchvision.__version__)"
python -c "import torch; print(torch.__version__)"
バグ6: 遭遇しましたAttributeError: partially initialized module 'cv2' has no attribute '_registerMatType'
参考:AttributeError: 部分的に初期化されたモジュール 'cv2' には属性 '_registerMatType' がありません (おそらく循環インポートが原因です)
pip install opencv-python-headless==4.8.0.74 opencv-python==4.8.0.74
2. テストエンジニアリング
最初の入力は順方向プロンプトで、2 番目の入力は逆方向プロンプトです。
転送プロンプト:
A girl,walking in the forest,the sun fell on her body,(masterpiece:1,2),best quality,masterpiece,highres,original,extremely detailed wallpaper,perfect lighting,(extremely detailed CG:1.2),drawing,paintbrush,
逆プロンプト:
NSFW,(worst quality:2),(low quality:2),(normal quality:2),lowres,normal quality,((monochrome)),((grayscale)),skin spots,acnes,skin blemishes,age spot,(ugly:1.331),(duplicate:1.331),(morbid:1.21),(mutilated:1.21),(tranny:1.331),mutated hands,(poorly drawn hands:1.5),blurry,(bad anatomy:1.21),(bad proportions:1.331),extra limbs,(disfigured:1.331),(missing arms:1.331),(extra legs:1.331),(fused fingers:1.61051),(too many dingers:1.61051),(unclear eyes:1.331),lowers,bad hands,missing fingers,extra digit,bad hands,missing fingers,(((extra arms and legs)))
面の復元 (面の修復) にはモデルをダウンロードする必要があります。
Downloading: "https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_Resnet50_Final.pth" to stable-diffusion-webui/repositories/CodeFormer/weights/facelib/detection_Resnet50_Final.pth
# 下载失败,手动下载
cd repositories/CodeFormer/weights/facelib/
wget https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_Resnet50_Final.pth
構成情報は次のとおりです: サンプリング方法、復元面、CFG スケール
クローズアッププロンプト
look at viewer,close up,upper body
参考: