4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Stable Diffusion Web UIのGoogle Colaboratoryでの導入手順を改めてまとめる

Posted at

Stable Diffusion Web UIをGoogle Colaboratoryで利用する手順を改めてまとめます。
ただし、このエントリーは私の備忘録的な手順書なため
各用語の細かい説明は省きます。

また今回は
LoRAモデルの上位互換のLoHaモデルを所持し、使用するケースを想定しています。

では、以下手順です。

まず
Google Colaboratoryで

1.ノートブックを作成

2.[編集]→[ノートブックの設定]でGPUを「T4」に設定にする
(コンピューティングユニットの消費が激しい「V100」、「A100」にしないように注意)
001.png

3.管理画面右上の「接続」ボタンを押す
002.png

4.Googleドライブをマウント
003.png

5.下記、コードを実行


①コードセル[1] 旧バージョンのStable Diffusion Web UIを複製(旧バージョンの準備方法は以前のエントリーを参考)

# 旧versionのWebUIを複製
import shutil

folder_1 = '/content/drive/MyDrive/StableDiffusion/stable-diffusion-webui-a9fed7c364061ae6efb37f797b6b522cb3cf7aa2'
folder_2 = '/content/stable-diffusion-webui'
shutil.copytree(folder_1 , folder_2)

%cd /content/stable-diffusion-webui

# LoRAモデルを格納するフォルダを作成
!mkdir -p /content/stable-diffusion-webui/models/Lora

# Hypernetworkを格納するフォルダを作成
!mkdir -p /content/stable-diffusion-webui/models/hypernetworks

②コードセル[2] 旧バージョンのsd-webui-additional-networksを複製(旧バージョンの準備方法は以前のエントリーを参考)

# 旧バージョンのsd-webui-additional-networksを複製
import shutil

folder_1 = '/content/drive/MyDrive/StableDiffusion/sd-webui-additional-networks-2da464780254d3f5beaf15edaea78499896c52e7'
folder_2 = '/content/stable-diffusion-webui/extensions/sd-webui-additional-networks'
shutil.copytree(folder_1 , folder_2)

③コードセル[3] ModelとVAEと拡張機能のインストール、PyTorchのpipインストール

!wget https://huggingface.co/WarriorMama777/OrangeMixs/resolve/main/Models/AbyssOrangeMix3/AOM3A1B_orangemixs.safetensors -O /content/stable-diffusion-webui/models/Stable-diffusion/AOM3A1B_orangemixs.safetensors
!wget https://huggingface.co/hakurei/waifu-diffusion-v1-4/resolve/main/vae/kl-f8-anime2.ckpt -O /content/stable-diffusion-webui/models/VAE/kl-f8-anime2.ckpt

%cd /content/stable-diffusion-webui/extensions/
!git clone https://github.com/liasece/sd-webui-train-tools /content/stable-diffusion-webui/extensions/sd-webui-train-tools

%cd /content/stable-diffusion-webui/extensions/
!git clone /content/stable-diffusion-webui/extensions/sd-webui-additional-networks

%cd /content/stable-diffusion-webui
!pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchtext==0.14.1 torchaudio==0.13.1 torchdata==0.5.1 --extra-index-url https://download.pytorch.org/whl/cu117

④コードセル[4] Stable Diffusion Web UIの起動スクリプトを実行し、Web UIが正常に起動するか確認

!python launch.py --share --xformers --enable-insecure-extension-access

6.拡張機能sd-webui-lycorisを[Available]→[Load from]から[a1111-sd-webui-lycoris]をインストール
再起動して、正常にインストールされていることを確認

7.[Settings]→[Stable Diffusion]からVAEを変更し[Apply settings]を押す
一旦WebUIを停止
006.png

8.持っているキャラクターのモデル(キャラクター名.safetensors)を
\stable-diffusion-webui\models\LyCORISにアップロード

9.4x-UltraSharp.pthファイルを\stable-diffusion-webui\models\ESRGAN
フォルダにアップロード
005.png

10.Stable Diffusion Web UIを起動

11.txt2imgで赤い花札カードのボタンを押し、Loraタブを押し、追加したキャラクターの.safetensorsファイルを選択

12.あとはpromptとparameterを調整しながら画像を出力するだけ

13.作業が終わったら、起動スクリプトのコードセルの停止ボタンを押し、かつ管理画面右上の「切断」ボタンを押すのを忘れずに
(これを忘れるとコンピューティングユニットが消費され続けてしまいます)

以上です。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?