1. はじめに
今回は、自分自身への備忘録を兼ねて、WindowsPC に Stable Diffusion web UI (AUTOMATIC1111版)をインストールする方法を、お伝えしたいと思います。
2. この記事を読んでできること
- WindowsPC に Stable Diffusion web UI をインストールできるようになる
- Stable Diffusion を使えるようになる
3. 注意事項
- 18歳以上であること
4. 必要なもの
- WindowsPC(この記事では Windows11 を利用)
- グラフィックボード(NVIDIAの「GeForce RTX20」シリーズ以降、VRAM8GB以上)
- HDD または SSD(十分なディスク容量があること)
- インターネット環境(有線LAN推奨)
- キーボード
- マウス
- HDMIディスプレイ
5. Stable Diffusion web UI (.zipファイル)のダウンロード
- GitHubサイトを開き、「sd.webui.zip」ファイルをダウンロードする
- .zipファイルを解凍する
- 参考:この記事作成時のファイルバージョン:sd.webui.zip(v1.0.0-pre)
6. モデルファイル の 格納
-
自力で、StableDiffusion のモデルファイルを入手し、
webui/models/Stable-diffusion
フォルダ配下に格納する
7. VAE ファイル の格納
-
自力で、StableDiffusion のVAEファイルを入手し、
webui/models/VAE
フォルダ配下に格納する
8. Stable Diffusion web UI の初回環境構築
-
sd.webui
フォルダ配下のrun.bat
ファイルを実行する - フォルダ名は
sd.webui
ではなくstable-diffusion-webui
が一般的のようです - フォルダ名は
run.bat
ファイルを実行する前に、sd.webui
からstable-diffusion-webui
へ変更しておくと、他の参考サイトと同じフォルダ名称になりわかりやすいかもしれません
raise RuntimeError("Cannot add middleware after an application has started")
RuntimeError: Cannot add middleware after an application has started
続行するには何かキーを押してください . . .
9. エラー発生時のトラブルシューティング(2023/03/10 時点の解決例)
-
cmd
コマンドプロンプトを開き、以下のコマンドを実行する -
cmd
コマンドの開き方は、エクスプローラーでpython
フォルダまで移動し、エクスプローラーのアドレスバーにcmd
と入力し、ENTERキーを押下するとcmd
コマンドプロンプトを開きます - コマンド実行結果が成功だったら、再度、
sd.webui
フォルダ配下のrun.bat
ファイルを実行してみる
// ディレクトリの移動(python.exeファイルがあるフォルダ内へ移動)
> cd C:\Program Files\sd.webui\system\python
// コマンド実行
> python.exe -m pip install --upgrade fastapi==0.90.1
// Successfully installed fastapi-0.90.1 starlette-0.23.1 が出力されると成功らしい
// コマンドプロンプトを終了する
> exit
- それでもだめなら、過去のトラブルシューティングを試みる
- RuntimeError: Cannot add middleware after an application has startedを参考にトラブルシューティングを試みる
- WebUI Cannot add middleware after an application has started エラー解決方法 を参考にトラブルシューティングを試みる
10. Stable Diffusion web UI をブラウザで開く
- ブラウザを開き、http://127.0.0.1:7860 にアクセスする
11. プロンプト の 設定
- 画面左上の1つ目のテキストボックスに「 cat 」と入力する
12. Stable Diffusion の 実行
- 「Generate!」ボタンをクリックする
- 参考サイト:画像生成AI「Stable Diffusion」で崩れがちな顔をきれいにできる「GFPGAN」を簡単に使える「Stable Diffusion web UI(AUTOMATIC1111版)」の基本的な使い方
13. おわりに
いかがでしたでしょうか?WindowsPC に Stable Diffusion web UI (AUTOMATIC1111版)をインストールし、Stable Diffusion を実行することができたのではないかと思います
今回の記事が、みなさまの学習の参考になれば幸いです
2023/03/10 TAKAHIRO NISHIZONO
14. 追記その1:モデルファイル「.safetensors」拡張子ファイルを入手しよう
- モデルファイルを入手し、
webui\models\Stable-diffusion
フォルダ配下に格納しよう - lofi_V1Fp16.safetensors
- colorful_v13.safetensors
- Basil_mix_fixed.safetensors
- museV1_v1.safetensors
15. 追記その2:VAEファイル「.ckpt」拡張子ファイルを入手しよう
- VAEファイルを入手し、
webui\models\VAE
フォルダ配下に格納しよう - vae-ft-mse-840000-ema-pruned.ckpt
16. 追記その3:ジェネリックモデルファイル「chilled_re-generic_v2.safetensors[589d7600e1]」マージモデルを自作しよう
- 商用利用可能なChilloutMixのジェネリックAIモデルの紹介と作り方を解説 を参考に、モデルファイルを自作しよう
- レシピ参照先:鎖城郎郭@AI錬成画師
- Recipe commentary(English):鎖城郎郭@AI錬成画師
- Q2:発色が悪い、どうして?:鎖城郎郭@AI錬成画師
- Q3:I don't know the percentage/同じ割合で作っても異なる:鎖城郎郭@AI錬成画師
- 私のレシピは基本ベースなので後は好みに自己調整してね、モデル名はご自由に:鎖城郎郭@AI錬成画師
chilled_re-generic_v2 Recipe
ALL Weighted sum merge
museV1_v1:0.4+(Basil_mix_fixed:0.3+(lofi_V1Fp16:0.5+colorful_v13))
// A3:補足
merge1.lofi_V1Fp16:colorful_v13=50%:50%=M:0.5
merge2.Basil_mix_fixed:merge1=70%:30%=M:0.3
merge3.museV1_v1:merge2=60%:40%=M:0.4
M:0.5→M:0.3→M:0.4=perfect!
17. 追記その4:モデルファイルの破損トークンを修復してみよう( chilled_re-generic_v2fix.safetensors[7e78128329] fixファイル生成)
-
Stable Diffusionモデルの破損チェックと修復について を参考に、モデルファイルを自作しよう
-
fix_postion_ids.py をダウンロードし、
system\python
フォルダ配下に保存する
-
cmd
コマンドプロンプトを開き、以下のコマンドを実行する
// ディレクトリの移動(python.exeファイルがあるフォルダ内へ移動)
> cd C:\Program Files\sd.webui\system\python
// ヘルプを確認
> python fix_position_ids.py -h
// 破損個所の確認
> python fix_position_ids.py --model "C:\Program Files\sd.webui\webui\models\Stable-diffusion\chilled_re-generic_v2.safetensors" --verbose
// 破損個所の修復(fixファイルの生成)
> python fix_position_ids.py --model "C:\Program Files\sd.webui\webui\models\Stable-diffusion\chilled_re-generic_v2.safetensors" --out "C:\Program Files\sd.webui\webui\models\Stable-diffusion\chilled_re-generic_v2fix.safetensors"
// コマンドプロンプトを終了する
> exit
- chilled_re-generic_v2:顔は似ているが、服装、肌への光の影がちがっている
- chilled_re-generic_v2fix:顔は似ているが、服装、肌への光の影、髪トップのハイライトがちがっている
- chilloutmix_NiPrunedFp32Fix:じゃっかん丸みのある顔、肌への光の影がはっきりしている印象
18. 追記その5:ジェネリックRecipe「chilled_re-generic.safetensors[89682ba94a]」
- レシピ参照先:鎖城郎郭@AI錬成画師
- Q2:発色が悪い、どうして?:鎖城郎郭@AI錬成画師
- colorful_v2.safetensors
- lofi_V2pre.safetensors
- museV1_v1.safetensors
- Basil_mix_fixed.safetensors
ジェネリックRecipe
全て加重平均(ALL Weighted sum merge)
Basil_mix_fixed:0.3+(museV1_v1:0.3+(colorful_v2:0.5+lofi_V2pre))
- chilled_re-generic:chilled_re-generic_v2と比較すると西洋よりの顔、3回目マージのBasil_mix_fixedの7割影響が強く残っている、肌への光の影はしっかいりとあり、画面全体で活発な印象をうける、chilled_re-generic_v2で3回目マージのmuseV1_v1割合を6割としているのがv2改良ポイントのように感じる
- Basil_mix_fixed:西洋の学習データで作られたモデルが多い中での、東洋エッセンスを多く含むモデルファイル、マージによるジェネリックモデルを生成する際の必要不可欠な隠し味
19. 追記その6:自分だけのオリジナルマージモデルRecipeを見つけてよう
- いろいろ実験して試してみてね
chilled_re-generic_v2-correction Recipe
ALL Weighted sum merge
0.6(museV1_v1) + 0.4(0.7(Basil_mix_fixed) + 0.3(0.5(lofi_V1Fp16) + 0.5(colorful_v13)))
LAST Marge vae-ft-mse-840000-ema-pruned.ckpt
realdos_re-generic Recipe
ALL Weighted sum merge
0.3(Basil_mix_fixed) + 0.7(0.3(museV1_v1) + 0.7(0.5(colorful_v2) + 0.5(lofi_V2pre)))
LAST Marge vae-ft-mse-840000-ema-pruned.ckpt
chilled_re-generic-correction Recipe
ALL Weighted sum merge
0.7(Basil_mix_fixed) + 0.3(0.7(museV1_v1) + 0.3(0.5(colorful_v2) + 0.5(lofi_V2pre)))
LAST Marge vae-ft-mse-840000-ema-pruned.ckpt
musev1_re-generic Recipe
ALL Weighted sum merge
0.9(museV1_v1) + 0.1(Basil_mix_fixed)
LAST Marge vae-ft-mse-840000-ema-pruned.ckpt
chillomusev1_re-generic Recipe
ALL Weighted sum merge
0.8(museV1_v1) + 0.2(Basil_mix_fixed)
LAST Marge vae-ft-mse-840000-ema-pruned.ckpt
Model
0.85(0.8(sunshinemix_NotBakeInVAE) + 0.2(leehanadraw_v10)) + 0.15(Bstaber)
head portrait,realistic, best quality,masterpiece,ultra high res,(photo realistic)1.4,beautiful lighting, (extremely detailed CG unity 8k wallpaper)+, detailed beautiful face,detailed clothes,Casual Clothing,1 girl,upper body,above the waist,slim face,medium breasts, big brown eyes, cute, young, posing, looking at viewers, professional lighting, physically-based rendering,depth of field
Negative prompt: nsfw,paintings, sketches, kis, (worst quality:2)+, (low quality:2)+, (normal quality:2)+, lowres, normal quality, (monochrome)++, (grayscale)++, skin spots, acnes, skin blemishes, age spot, (outdoor)1.6, glans, anime,(worst quality, low quality)1.4, 3d, curvy, fat, gray_scale, (over three finger\\(fingers excluding thumb\\):2)+, (fused anatomy)+, (bad anatomy\\(body\\))+, (bad anatomy\\(hand\\))+, (bad anatomy\\(finger\\))+, (over four fingers\\(finger\\):2)++, (bad anatomy\\(arms\\))+, (over two arms\\(body\\))+, (bad anatomy\\(leg\\))+, (over two legs\\(body\\))+, (interrupted\\(body, arm, leg, finger\\))+, (bad anatomy\\(arm\\))+, (bad detail\\(finger\\))1.2, (bad anatomy\\(fingers\\))1.2, (multiful\\(fingers\\))1.2, (bad anatomy\\(finger\\))1.2, (bad anatomy\\(fingers\\))1.2, (fused\\(fingers\\))1.2, (over four fingers\\(finger\\):2)++, (multiful\\(hands\\))+, (multiful\\(arms\\))+, (multiful\\(legs\\))+, (bad detailed background)+, (unclear architectural outline)+, (non-linear background)+, heterochromia, monochrome, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, lowres, 2girl3girl 4girl5girl, bad anatomy, more than 1penis, bad hands, text, error, missing fingers, cropped, extra digit, fewer digits, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name, Poor Quality, Poor Detail, Weird Detail, Low Quality Effect, extra_nipples, extra face, Multiple Views, extra penis, no penis between breast, , 2koma, 3koma, more than 1girl, (2feet, 3feet, extra legs, extra feet, 4toes, 6toes, 7toes, 8toes)++, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, blurry background, multiple views, awkward_armpit, glow, reference inset, (mutated hands and fingers)1.5, (long body )1.3, long neck,
Steps: 20, Sampler: DPM++ SDE Karras, CFG scale: 7, Seed: 1053927817, Size: 512x512,
22. 追記その8:イラスト風マージモデルファイルを作ろう
-
SukiyakiMix-v1.0 はマージレシピが公開されているイラスト風モデルファイルです、レシピを参考にオリジナルのイラスト風モデルファイルを作成してみましょう
-
アニメでは人間の色味がそのままでは適さない場合が多いので、好みに合わせて VAE ファイルを変えてみて色調を調整してみましょう
SukiyakiMix-v1.0 Recipe
ALL Weighted sum merge
pastel-mix:AbyssOrangeMix2_sfw (AOM2s) = 6:4
LAST Marge orangemix.vae.pt
21. 追記その7:モデルファイルの比較
head portrait,realistic, best quality,masterpiece,ultra high res,(photo realistic)1.4,beautiful lighting, (extremely detailed CG unity 8k wallpaper)+, detailed beautiful face,detailed clothes,Casual Clothing,1 girl,medium breasts, big brown eyes, cute, young, posing, looking at viewers, professional lighting, physically-based rendering,depth of field
Negative prompt: nsfw,paintings, sketches, kis, (worst quality:2)+, (low quality:2)+, (normal quality:2)+, lowres, normal quality, (monochrome)++, (grayscale)++, skin spots, acnes, skin blemishes, age spot, (outdoor)1.6, glans, anime,(worst quality, low quality)1.4, 3d, curvy, fat, gray_scale, (over three finger\\(fingers excluding thumb\\):2)+, (fused anatomy)+, (bad anatomy\\(body\\))+, (bad anatomy\\(hand\\))+, (bad anatomy\\(finger\\))+, (over four fingers\\(finger\\):2)++, (bad anatomy\\(arms\\))+, (over two arms\\(body\\))+, (bad anatomy\\(leg\\))+, (over two legs\\(body\\))+, (interrupted\\(body, arm, leg, finger\\))+, (bad anatomy\\(arm\\))+, (bad detail\\(finger\\))1.2, (bad anatomy\\(fingers\\))1.2, (multiful\\(fingers\\))1.2, (bad anatomy\\(finger\\))1.2, (bad anatomy\\(fingers\\))1.2, (fused\\(fingers\\))1.2, (over four fingers\\(finger\\):2)++, (multiful\\(hands\\))+, (multiful\\(arms\\))+, (multiful\\(legs\\))+, (bad detailed background)+, (unclear architectural outline)+, (non-linear background)+, heterochromia, monochrome, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, lowres, 2girl3girl 4girl5girl, bad anatomy, more than 1penis, bad hands, text, error, missing fingers, cropped, extra digit, fewer digits, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name, Poor Quality, Poor Detail, Weird Detail, Low Quality Effect, extra_nipples, extra face, Multiple Views, extra penis, no penis between breast, , 2koma, 3koma, more than 1girl, (2feet, 3feet, extra legs, extra feet, 4toes, 6toes, 7toes, 8toes)++, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, blurry background, multiple views, awkward_armpit, glow, reference inset, (mutated hands and fingers)1.5, (long body )1.3, long neck,
Steps: 20, Sampler: DPM++ SDE Karras, CFG scale: 7, Seed: 1860404385, Size: 512x512
22. 追記その8:おすすめ embeddings/ ファイル
23. 追記その9:おすすめ LoRA/ ファイル
24. 追記その10:裏技 画像精製のじゃっかん高速化
-
webui-user.bat
ファイルに、--xformers
を追記し保存する
@echo off
set PYTHON=
set GIT=
set VENV_DIR=
set COMMANDLINE_ARGS=--xformers
call webui.bat
25. 追記その11:呪文
▼品質 呪文
masterpiec, best quality, high resolution, ultra detailed,
▼作風 呪文
illustration,
anime,
manga,
realistic,
sketch,
pencil drawing,
watercolor,
oil painting,
claude Monet,
Pablo Picasso,
▼環境 呪文
full body,
portrait,
close up face,
cowboy shot,
wide shot,
from below,
viewfinder,
summer,
winter,
snowfall,
landscape of japan,
medieval europe,
middle ages,
▼主体 呪文
1 girl, smile, detailed beautiful skin, face focus, dress shirt, collarbone, dark_hair, long_hair, hair_flower, hair_ornament,
1 little girl, black short hair, cat ear, red eyes, torogao, embarrassed eyebrows, skin fang, mediam chest, frilled dress, white gloves on both hands,
woman, smile, office lady, tight skirt,
looking at viewer,
▼環境 呪文
windy, soft light,
outdoor, street, night,
▼ネガティブ 呪文
(worst quality:2),(low quality:2),(normal quality:2),((monochrome)),((grayscale)), missing fingers ,skin spots ,acnes,skin blemishes, nsfw
26. 追記その12:LoRA 適用時の Clip skip 値 2
26. 追記その12:ENSD 値 31337
27. 追記その13:おすすめ プロンプト50選
28. 追記その14:便利機能まとめ
29. 追記その15:LoRAファイル作ろう
- niel:(3/20更新)Kohya版LoRA学習環境 簡単スタンドアローンセットアップ(※bmaltais氏の『Kohya's GUI』の導入)
- かたらぎ:kohya版LoRA初心者教本 服を着せ替えできる高性能キャラLoRAをつくろう!】の便利機能まとめ
- RTX3070ti(8GB)でLoRAファイル作成を試しましたが、Train batch sizeは3くらいが限度で、4以上だとグラボのメモリ不足エラーとなりました( ;∀;)
30. 追記その16:高品質なアップスケーラー
31. 追記その17:ControlNetのインストール
32. 追記その18:ControlNet Tile を使ってみる(描画量アップ)
33. 追記その19:Tiled Diffusion (Tiled VAE) の使い方(分割アップスケール)
34. 追記その20:Tile Resampleの解説(描画量アップ+アップスケール)
35. 追記その21:邪魔な部分を簡単除去 - Lama Cleaner
36. 追記その22:画像生成AIで思い通りの画像を作る!「BRAV5」を使いこなすプロンプトのコツ
37. 追記その23:手や顔の崩れを簡単に修正できるADetailerのインストール・使い方を紹介します【Stable Diffusion WebUIの使い方】
-
ITDTM:手や顔の崩れを簡単に修正できるADetailerのインストール・使い方を紹介します【Stable Diffusion WebUIの使い方】
-
run.bat 実行時にADetailerの起動エラーログが出力された場合は、一旦、Stable Diffusionを終了させてから、update.batを実行し、その後に改めてrun.batを起動するとADetailerの起動エラーが解消するかも(自分の環境ではそれで直ったよ)
38. 追記その24:愛音さんテクニック
- X:サンプラーに4x_RealisticRescaler_100000_G
で書き込みはCD_tunerでゴニョゴニョ調整していただければ
38. 追記その24:xxx@AIart(@untn_xxx)さんテクニック
-
GitHub:Photopea Stable Diffusion WebUI Extension はStable Diffusion web UI内で利用できるフォトショップのようなエクステンション機能
39. 追記その25:とーふのかけら(@konapieces)さんテクニック
▼プロンプト
(longeyelashes:0.8),
AsianEyesEra,
▼RoLA
lora:AsianEyesEra:1
- note:AUTOMATIC1111 WebUIをチューニングしよう!WebUIの高速化を解説!
▼生成が早くなる方法
・Negative Guidance minimum sigma:1.1
・Token merging ratio:0.5
・Token merging ratio for img2img:0.5
・Token merging ratio for high-res pass:0.5