Stable Diffusion 初心者ガイド
はじめに
Stable Diffusionとは?
Wikipediaによると、Stable Diffusion
は拡散モデル(DM)の一形態です。2015年に導入された拡散モデルは、トレーニング画像にガウスノイズを連続的に適用することを除去する目的で訓練され、一連のデノイジングオートエンコーダーとして考えることができます。Stable Diffusionは「潜在拡散モデル」(LDM)として知られる変種を使用しています。
Stable Diffusionのインストール方法は?
Stable Diffusion
を使用する方法は2つあります。
- ローカルコンピュータに
Stable Diffusion
をインストール - Colabやその他のオンラインサービスで
Stable Diffusion
を使用
この記事では、ローカルコンピュータへのStable Diffusion
のインストールに焦点を当てます。
Apple Silicon
Macユーザー向け
Stable Diffusion
を使用するための主な方法が2つあります。
方法1:ターミナルでの通常の方法
必要条件:
M1
、M1 Pro
、M1 Max
、M1 ULTRA
、M2
チップ搭載のMac16GB RAM
以上- macOS
12.3
以上
ステップ1
MacにPython
をインストールする必要があります
python3 -V
でバージョンを確認
1 | python3 -V |
1 | which python3 |
1 | pip3 --version |
Python
をインストールする必要がある場合、最も簡単な方法はHomebrew
を使用することです。詳細はhttps://brew.shをご覧ください。
Homebrew
を使用して最新バージョンのPythonをインストール:
1 | brew update |
ステップ2
リポジトリをクローンし、依存関係をインストールします。
git
をインストールしていない場合は、次のようにインストールできます:
1 | brew update |
1 | git clone -b apple-silicon-mps-support https://github.com/bfirsh/stable-diffusion.git |
ステップ3
依存関係をインストールするための仮想環境をインストール:
1 | python3 -m pip install virtualenv |
仮想環境を有効化:
1 | source venv/bin/activate |
仮想環境を無効化:
1 | deactive |
注意:すべてのステップはstable-diffusion-v1のパス内で実行する必要があります
ステップ4
必要なパッケージを再度インストール
1 | brew install Cmake rust protobuf |
ステップ5
リストの依存関係をインストール:
1 | pip install -r requirements.txt |
ステップ6
重みをダウンロード
Hugging Faceリポジトリにアクセスし、ライセンスを読んで理解した後、「Access repository」をクリックします。
そのページでsd-v1-4.ckpt(約4GB)をダウンロードし、上記で作成したディレクトリのmodels/ldm/stable-diffusion-v1/model.ckptとして保存します。
ステップ7
開始
1 | python scripts/txt2img.py \ |
注意:ステップ6とステップ7はReplicateからの引用です
方法2:GUI
-
Diffusionbee
というGUIソフトウェア<—ここをクリックして開始必要条件:
M1
、M1 Pro
、M1 Max
、M1 ULTRA
、M2
チップ搭載のMac16GB RAM
以上- macOS
12.3
以上
Linux
ユーザー向け(DebianまたはUbuntu)
方法
ステップ1
Python、git、virtualenv
をインストール
1 | sudo apt install python3 git virtualenv |
ステップ2
リポジトリをクローンし、依存関係をインストール。
1 | git clone https://github.com/CompVis/stable-diffusion.git |
ライセンスを読んで同意する
ステップ3
仮想環境に移動
仮想環境を有効化
1 | source venv/bin/activate |
仮想環境を無効化
1 | deactive |
ステップ4
重みをダウンロード
Hugging Faceリポジトリにアクセスし、ライセンスを読んで理解した後、「Access repository」をクリックします。
1 | curl https://www.googleapis.com/storage/v1/b/aai-blog-files/o/sd-v1-4.ckpt?alt=media > sd-v1-4.ckpt |
ステップ5
実行
1 | python scripts/txt2img.py --prompt "YOUR-PROMPT-HERE" --plms --ckpt sd-v1-4.ckpt --skip_grid --n_samples 1 |
参考文献
Run. Replicate. (n.d.). Retrieved October 11, 2022, from https://replicate.com/blog/run-stable-diffusion-on-m1-mac
Divamgupta. (n.d.). Divamgupta/diffusionbee-stable-diffusion-ui: Diffusion Bee is the easiest way to run stable diffusion locally on your M1 mac. comes with a one-click installer. no dependencies or technical knowledge needed. GitHub. Retrieved October 11, 2022, from https://github.com/divamgupta/diffusionbee-stable-diffusion-ui