2023年02月28日
Stable diffusion Web UIで画像を出すまで(Ubuntu)
概要
Stable diffusion Web UIはターミナル上でインストール、起動のためのコマンドを実行でき、起動したらWebブラウザでprompt(text)を打ち込んだり画像をアップロード、できた画像をダウンロードする仕組みです。
環境Ubuntu
| NVIDIA-SMI 470.161.03 Driver Version: 470.161.03 CUDA Version: 11.4 pytorch 1.13.0+cu117
nvidia-smiコマンドの値よりNvidia driver, CUDAはpytorch 1.13.0+cu117に合わせたものです。
ダウンロード
python3など必要なソフトウェアのインストール
sudo apt install wget git python3 python3-venv
stable-diffusion-webui のインストール
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui webuicd webui
実行
ダウンロードしたディレクトリwebui以下の./webui.sh
を実行します。成功すると初回は必要なライブラリ等のインストールが始まります。2回目以降は成功すると
################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye)
################################################################
################################################################
Running on ユーザー名 user
################################################################
################################################################
Repo already cloned, using it as install directory
################################################################
################################################################
Create and activate python venv
################################################################
################################################################
Launching launch.py...
################################################################
Python 3.8.10 (default, Nov 14 2022, 12:59:47)
[GCC 9.4.0]
Commit hash: 0cc0ee1bcb4c24a8c9715f66cede06601bfc00c8
Installing requirements for Web UI
Launching Web UI with arguments:
No module 'xformers'. Proceeding without it.
Loading weights [6ce0161689] from /home/ユーザー名/work/StableDiffusion/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors
Creating model from config: /home/ユーザー名 /work/StableDiffusion/stable-diffusion-webui/configs/v1-inference.yamlLatent
Diffusion: Running in eps-prediction modeDiffusionWrapper has 859.52 M params.
Applying cross attention optimization (Doggettx).
Textual inversion embeddings loaded(0): Model loaded in 4.0s (load weights from disk: 0.2s, create model: 0.3s, apply weights to model: 2.1s, apply half(): 0.3s, load VAE: 0.8s, move model to device: 0.2s).
Running on local URL: http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.
といったメッセージが 出てきます。
Youtubeを見ながらとかJupyter notebookを起動しながらだとGPUの利用に失敗し
'Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check'"
RuntimeError: "LayerNormKernelImpl" not implemented for 'Half'
などといったエラーが出てきてしまったので素直にPC再起動したほうが良さそうです。
http://127.0.0.1:7860
と表示されているのでこれをWebブラウザのアドレスバーにコピー&ペースト、エンターを押してアクセスすると
というページ(WebUI)が見えます。
text2img
text(prompt)を左上のテキストボックスに入れてGenerateを押すと画像ができます。標準でないモデルを使いたいときはHugging face等から.ckpt形式やsafetensor形式のファイル(数GBあります)をダウンロードしてmodels/Stable-diffusionやmodels/VAEなど対応するディレクトリの下において、WebUIの左上のStable Diffusion checkpointの下のVから選択します。
例えば人物が特化のportraitplus
https://huggingface.co/wavymulder/portraitplusであれば
https://huggingface.co/wavymulder/portraitplus/tree/mainにckptが置いてあります。
パラメーターの説明はあとで