画像生成AIのひとつであるStable Diffusionをローカル環境で使用できるように構築するStable Diffusion Web UI (AUTOMATIC1111) のインストール方法を紹介します。
実行環境
OS | Windows11 23H2 |
AUTOMATIC1111 | v1.9.4 |
インストール手順
今回は、NVIDIA(推奨)のグラフィックボード+Windowsの環境でインストールする方法を2つ紹介します。基本的にPythonとGitも一緒にパッケージ化されている方法1でいいと思います。
方法1
ファイルのダウンロードと解凍
下のリンクからsd.webui.zipをダウンロード
zipファイルをお好きな場所で解凍(すべて展開)してください。
batファイル実行
![update.bat 起動](https://pcniki.com/wp-content/uploads/2023/08/stable-diffusion-web-ui-automatic1111-install-11-800x511.webp)
まずは、update.batを実行して最新バージョンにアップデートします。
![update.bat 起動後](https://pcniki.com/wp-content/uploads/2023/08/stable-diffusion-web-ui-automatic1111-install-12-800x451.webp)
アップデートが終わったら何かキーを押すとコマンドプロンプトが閉じます。
![run.bat 起動](https://pcniki.com/wp-content/uploads/2023/08/stable-diffusion-web-ui-automatic1111-install-13-800x511.webp)
run.batを実行します。
![run.bat 起動後](https://pcniki.com/wp-content/uploads/2023/08/stable-diffusion-web-ui-automatic1111-install-14-800x451.webp)
初回起動時は、ファイルのダウンロードなどで時間がかかります。
![run.bat 起動後準備完了](https://pcniki.com/wp-content/uploads/2023/08/stable-diffusion-web-ui-automatic1111-install-15-800x451.webp)
正しくインストールされるとRunning on local URL: http://127.0.0.1:7860というメッセージが表示されブラウザが起動します。
![Stable Diffusion スタート画面](https://pcniki.com/wp-content/uploads/2023/06/stable-diffusion-start-screen-800x450.webp)
こちらがStable Diffusion Web UI (AUTOMATIC1111) の生成画面になります。Generateで画像を生成することができますがいろいろな設定項目があるので以下の記事を参考にしてください。
方法2
Git インストール
GitHubからリポジトリをクローンするのに使います。
![gitダウンロード](https://pcniki.com/wp-content/uploads/2023/06/stable-diffusion-web-ui-automatic1111-install-3-800x368.webp)
Click here to downloadから最新版がダウンロードできます。ダウンロードしたら起動してください。
![Git Setup](https://pcniki.com/wp-content/uploads/2023/06/stable-diffusion-web-ui-automatic1111-install-4.webp)
特に設定する項目はないのでひたすらNextでSetupを進めてください。
Python 3.10.6 インストール
Pythonをインストールします。現在バージョンは3.10.6が指定されています。(マイクロバージョンは後方互換性が高いので新しいので大丈夫そうですが)
![Pythonダウンロード](https://pcniki.com/wp-content/uploads/2023/06/stable-diffusion-web-ui-automatic1111-install-1-800x282.webp)
Windows installer (64-bit) ダウンロードして起動
![Python 3.10.6 Setup](https://pcniki.com/wp-content/uploads/2023/06/stable-diffusion-web-ui-automatic1111-install-2.webp)
Add Python 3.10 to PATHにチェックを入れてインストールを進めてください。
ファイルのダウンロード
Stable Diffusion Web UI (AUTOMATIC1111) のファイルをダウンロードします。
![ダウンロード場所](https://pcniki.com/wp-content/uploads/2023/06/stable-diffusion-web-ui-automatic1111-install-5-800x534.webp)
エクスプローラーでダウンロードしたい場所にアクセスしたらアドレスバーにcmdと入力してEnterでコマンドプロンプトを起動します。
下のコードを入力してEnter
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
![Stable diffusion Web UI ダウンロード](https://pcniki.com/wp-content/uploads/2023/06/stable-diffusion-web-ui-automatic1111-install-6-800x534.webp)
指定した場所にStable Diffusion Web UI (AUTOMATIC1111) のファイルがダウンロードされます。
batファイル実行
![webui-user.bat 起動](https://pcniki.com/wp-content/uploads/2023/06/stable-diffusion-web-ui-automatic1111-install-7-800x534.webp)
ダウンロードされたフォルダ内のwebui-user.batを実行します。
![Stable diffusion Web UI インストール](https://pcniki.com/wp-content/uploads/2023/06/stable-diffusion-web-ui-automatic1111-install-8-800x418.webp)
初回起動時は、ファイルのダウンロードなどで時間がかかります。
![Stable diffusion Web UI 起動](https://pcniki.com/wp-content/uploads/2023/06/stable-diffusion-web-ui-automatic1111-install-9-800x418.webp)
正しくインストールされるとRunning on local URL: http://127.0.0.1:7860というメッセージが表示されブラウザが起動します。ブラウザが起動しない場合はコマンドプロンプトは閉じずにhttp://127.0.0.1:7860を開いてください。
コマンドライン引数の追加
webui-user.batを編集してコマンドライン引数を追加することによっていくつかの最適化を行うことができます。
![webui-user.bat 編集](https://pcniki.com/wp-content/uploads/2023/06/stable-diffusion-web-ui-automatic1111-install-10.webp)
COMMANDLINE_ARGS=の後にオプションを記述します。
おすすめのコマンドライン引数
VRAM使用量の減少とパフォーマンスの向上(同一Seedでの生成結果に少し違いが出る)
--xformers
VRAM使用量を減らす(パフォーマンスは若干低下します)
--medvram
--opt-sub-quad-attention
トラブルシューティング
生成された画像が黒や緑になる場合
--precision full --no-half
NansException: A tensor with all NaNs was produced in VAEの場合
--no-half-vae
ほかにもあるので気になる方はチェックしてみてください。