はじめに
環境を Google Drive 上にすべて保存し、Anything V3 を使うことを目的にする。
0. Google アカウントの作成
既存のアカウントを使用してもいいが、容量を食うので新たにアカウントを作成することをすすめる。
1. Google Drive への保存 (一度だけ)
Google Drive 左上の [新規] → その他 → アプリを追加 → Colaboratory を追加する。
Google Drive 左上の [新規] → その他 → Google Colaboratory を選択し、下のコードを張り付ける。
# ディレクトリの作成
!mkdir /content/drive/MyDrive/AnythingV3
!mkdir /content/drive/MyDrive/AnythingV3/PyResource
# 必要な諸々
%cd /content/drive/MyDrive/AnythingV3/PyResource
!pip install -t ./ -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers
!pip install -t ./ pytorch_lightning tensorboard==2.9.1 omegaconf einops taming-transformers==0.0.1 clip transformers kornia test-tube
!pip install -t ./ diffusers invisible-watermark
# UI の取得
%cd /content/drive/MyDrive/AnythingV3
!git clone --depth=1 https://github.com/AUTOMATIC1111/stable-diffusion-webui ./stable-diffusion-webui
# Anythingv3.0 のモデルデータを取得
%cd /content/drive/MyDrive/AnythingV3/stable-diffusion-webui
!wget https://huggingface.co/Linaqruf/anything-v3.0/resolve/main/Anything-V3.0-pruned.ckpt -O ./model.ckpt
!wget https://huggingface.co/Linaqruf/anything-v3.0/resolve/main/Anything-V3.0.vae.pt -O ./model.vae.pt
画面左のファイル → ドライブをマウント を選択する。
セルの左の再生ボタンを押してしばらく待つ。長いので耐える。
2. NSFW (エッチ絵判定) の回避 (とばしてもいい)
マイドライブ/AnythingV3/PyResource/diffusers/piplines/stable_diffusion/safety_checker.py をダウンロードして 87 行目から 95 行目をコメントアウトする。以下の部分である。削除してもいい。
for idx, has_nsfw_concept in enumerate(has_nsfw_concepts):
if has_nsfw_concept:
images[idx] = np.zeros(images[idx].shape) # black image
if any(has_nsfw_concepts):
logger.warning(
"Potential NSFW content was detected in one or more images. A black image will be returned instead."
" Try again with a different prompt and/or seed."
)
Google Drive の元のファイルは削除し、修正したファイルをそこへ戻す。
3. UI の起動(毎回)
1. をやったのち 1 時間ほど待ってから実行する。そうでないとデータが Drive に移動しきっていないことがあるため。
Google Drive 左上の [新規] → その他 → Google Colaboratory を選択し、下のコードを張り付ける
import sys
sys.path.append('/content/drive/MyDrive/AnythingV3/PyResource')
%cd /content/drive/MyDrive/AnythingV3/stable-diffusion-webui
!COMMANDLINE_ARGS="--share --gradio-debug" REQS_FILE="requirements.txt" python launch.py
画面左のファイル → ドライブをマウント を選択する。
画面右上のランタイム → ランタイムのタイプを変更 → ハードウェアアクセラレータをGPUに変更する。セルの左の再生ボタンを押してしばらく待つ。
すると下のようなテキストが出てくる。最後の行の Running on public URL の右側の URL をクリックする。
/content/drive/MyDrive/AnythingV3/stable-diffusion-webui
Python 3.8.16 (default, Dec 7 2022, 01:12:13)
[GCC 7.5.0]
Commit hash: 44c46f0ed395967cd3830dd481a2db759fda5b3b
Installing gfpgan
Installing clip
Installing open_clip
Installing requirements for CodeFormer
Installing requirements for Web UI
Launching Web UI with arguments: --share --gradio-debug
No module 'xformers'. Proceeding without it.
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Downloading: 100% 939k/939k [00:00<00:00, 1.86MB/s]
Downloading: 100% 512k/512k [00:00<00:00, 1.21MB/s]
Downloading: 100% 389/389 [00:00<00:00, 376kB/s]
Downloading: 100% 905/905 [00:00<00:00, 901kB/s]
Downloading: 100% 4.41k/4.41k [00:00<00:00, 4.08MB/s]
Downloading: 100% 1.59G/1.59G [00:30<00:00, 57.0MB/s]
Loading weights [2700c435] from /content/drive/MyDrive/AnythingV3/stable-diffusion-webui/model.ckpt
Using VAE found similar to selected model: /content/drive/MyDrive/AnythingV3/stable-diffusion-webui/model.vae.pt
Loading VAE weights from: /content/drive/MyDrive/AnythingV3/stable-diffusion-webui/model.vae.pt
Applying cross attention optimization (Doggettx).
Model loaded.
Loaded a total of 0 textual inversion embeddings.
Embeddings:
Running on local URL: http://127.0.0.1:7860
Running on public URL: https://32834bc0a5b8b6cf.gradio.app
ドライブ内の AnythingV3/stabl-diffusion-webui/outputs の中のフォルダ内に画像が保存される。
参考
anything v3.0をgoogle colabで使う (stable diffusion web ui版)
NovelAI よりも凄い? AnythingV3 を Google Colab で試す!