ControlNetを使うと、Stable Diffusionで、ポーズや構図を指定して作成可能ということで早速使ってみます。
sd-webui-controlnetをインストールする
通常通り、「Stable Diffusion Web UI」を起動します。
起動したら、拡張のタブを表示し、Intall from URLを選択します。

URL欄に、「https://github.com/Mikubill/sd-webui-controlnet」を入力して、インストールします。
インストールが完了すると、以下が表示されます。

Installedタブに遷移すると、「sd-webui-controlnet」が表示されているのを確認して、「Apply and restart UI」を実行します。

再起動したら、URLが変わるので、ColaboratoryのタブにURLが表示されているので、そちらを開きます。
「txt2img」のタブに以下のように「ControlNet」が表示されていればOKです。

ControlNetのモデルデータをダウンロードする
以下のURLから、「control_openpose-fp16.safetensors」をローカルにDLします。

Colaboratoryのウィンドウを開き、ファイル情報を開き、「extensions」「sd-webui-controlnet」「model」とたどります。

ここに、DLしたファイルをアップロードします。


画像を生成してみる
「txt2img」タブの最下部に、「ControlNet」があるのでクリックして表示します。

「Enable」にチェックを入れ、Preprocessorの行の更新ボタンを押してモデルを更新します。
Preprocessorは、openposeを選択して、Modelは、control_openpose-fp16にします。
ポーズの画像を上部にアップロードします。
この状態で通常通り、画像の生成を行います。

なぜかポーズが反映されていません。
Colaboratoryのウィンドウを見ると、以下のエラーがでていました。
Loading model: control_openpose-fp16 [9ca67cc5]
Error running process: /content/stable-diffusion-webui/extensions/sd-webui-controlnet/scripts/controlnet.py
ググると以下のページがでてきました。
何を対処したのか不明です。
ノートブックを新規作成から作り直してみました。
openposeのモデルは、一旦、Web UIを停止して、Colaboratoryから実行しました。
!wget https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_openpose-fp16.safetensors -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_openpose-fp16.safetensors
上記実行後に、Web UIを起動しました。
!python launch.py --share --xformers --enable-insecure-extension-access
再度、modelを指定して画像を作成してみたら動作しました。
modelを自分でDLして、アップロードしたから動かなかったのでしょうか。
動作するようになりましたが、以下のエラーが出るようになりました。
Solution: Please download YAML file, or ask your model provider to provide [/content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_openpose-fp16.yaml] for you to download.
Hint: You can take a look at [/content/stable-diffusion-webui/extensions/sd-webui-controlnet/models] to find many existing YAML files.
以下のように、生成された画像とポーズが表示されるようになりました。


まとめ
Google Colaboratoryで以下をDLする。
!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
%cd /content/stable-diffusion-webui
civitaiのヘルパーをインストールする。
%cd /content/stable-diffusion-webui/extensions/
!git clone https://github.com/butaixianran/Stable-Diffusion-Webui-Civitai-Helper /content/stable-diffusion-webui/extensions/Stable-Diffusion-Webui-Civitai-Helper
%cd /content/stable-diffusion-webui
Stable Diffusion Web UIを起動する。
!python launch.py --share --xformers --enable-insecure-extension-access
stable-diffusion-webuiが起動したら、ControlNetを拡張タブからDLしUIを再起動する。
https://github.com/Mikubill/sd-webui-controlnet
一旦、webuiを落として、以下の2つをDLする。
!wget https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_openpose-fp16.safetensors -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_openpose-fp16.safetensors
!wget https://huggingface.co/webui/ControlNet-modules-safetensors/blob/main/control_scribble-fp16.safetensors -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_scribble-fp16.safetensors
再度、webuiを起動する。
!python launch.py --share --xformers --enable-insecure-extension-access
上記でエラーになったため、以下にオプションを変えています。
!python launch.py --share --enable-insecure-extension-access --disable-safe-unpickle
ControlNetの設定で、Multi ControlNet: Max models amount (requires restart)を2にする。

Apply Settingsを押して、Reload UIをします。
