参考
https://blog.kikagaku.co.jp/google-colab-newplan
https://pc.watch.impress.co.jp/docs/column/nishikawa/1485422.html
googlecolabって何?
タダでpythonを動かせる
3種類のプランがある
項目 | 無料版 | Colab Pro | Colab Pro+ |
---|---|---|---|
料金 | 月 0 円 | 月 1,072 円 | 月 5,243 円 |
GPU | 自動割当 | 高性能 GPU | 高性能 GPU |
メモリ | 通常使用 | 大量データ用 | 大量データ用 |
使用時間 | 12 時間 | 24 時間 | 24 時間 |
バックグラウンド実行 | ✕ | ✕ | ○ |
ということで無料でも使える。
速度比較
M1 Pro(GPU) 1.92(it)/383秒(10枚)
Colab (Pro)/標準(T4) 2.99(it)/66秒(10枚)
Colab Pro/プレミアム(A100) 6.24(it)/32秒(10枚)
ということで、 Proが一番はやい
早速動かす
ノートブックを新規作成
ランタイム > ランタイムのタイプを変更 > GPUを選択
再生ボタンの右側に以下のコードを書いて再生ボタンを押す
(体感15秒ほど待つ)
import torch
import time
# Set device to GPU or CPU
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Create random matrices
input_size = 30000
a = torch.randn(input_size, input_size).to(device)
b = torch.randn(input_size, input_size).to(device)
# Test performance
start_time = time.time()
c = torch.matmul(a, b)
end_time = time.time()
print("Time taken: {:.2f} seconds".format(end_time - start_time))
Time taken: 2.60 secondsと表示されればOK
stable diffusion を起動
# stable diffusion-webui取得
!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
# Model: v1-5-pruned-emaonly取得
!curl -Lo /content/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.ckpt https://huggingface.co/LarryAIDraw/v1-5-pruned-emaonly/resolve/main/v1-5-pruned-emaonly.ckpt
# stable diffusion-webui起動
%cd /content/stable-diffusion-webui
!COMMANDLINE_ARGS="--share --xformers --theme dark --no-half-vae --opt-sub-quad-attention --enable-insecure-extension-access" REQS_FILE="requirements.txt" python launch.py
と書いて再生ボタンをクリック
数分待つ
以下が表示されたらOK
unning on local URL: http://12x.0.0.1:xxx0
Running on public URL: https://0xxxx-8fa8-4720.gradio.live
下のURLにアクセスしよう。
で、メモリエラー防止の為 Width と Height を 256 に変更。
プロンプト入力欄に
park with cherry blossoms, outside cafe
と入力して Generate を クリックすればOK
続いて Stable Diffusion
停止ボタンを押して、先程のコードを停止。
1 ログインして下記よりchilloutmixをダウンロード
(会員登録必要)
2 GoogleDrive に /models/Stable-diffusion/ フォルダを作成し、そこに上記ファイルをアップロード
from google.colab import drive
drive.mount('/content/drive')
パネルが出てきたら権限を与えるで許可
この際、
colab の /content/drive/MyDrive/以下がGoogleドライブ側の/になる
googleドライブから ファイルをコピー
!cp /content/drive/MyDrive/models/Stable-diffusion/chilloutmix_NiPrunedFp32Fix.safetensors /content/stable-diffusion-webui/models/Stable-diffusion/
Lora のダウンロード
Lora(Low-Rank Adaptationの略)と呼ばれる、使用Modelに特徴を与える
をダウンロード
japaneseDollLikeness_v10 を ダウンロード
https://huggingface.co/AmornthepKladmee/japaneseDollLikeness_v10/blob/main/japaneseDollLikeness_v10.safetensors
Korean Doll Likeness v1.5 を dl
https://github.com/wibus-wee/stable_diffusion_chilloutmix_ipynb/releases
/models/Lora/ フォルダを作成し、上記2つのファイルをアップロード
データを移動
!cp /content/drive/MyDrive/models/Lora/*.* /content/stable-diffusion-webui/models/Lora
stable diffusion の再起動
%cd /content/stable-diffusion-webui
!python launch.py --xformers --theme dark --no-half-vae --opt-sub-quad-attention --share --enable-insecure-extension-access
生成
プロンプトは
https://ishikawatsukasa.com/chat/web/4183/#index_id2
のサンプル1を参考にし、サイズは256x256にした。
出来上がり!
商用利用したい場合は
muse_v1 を使う
https://civitai.com/models/13564/musev1
ダウンロードして、googleドライブにアップロード。
で、移動させる。
!cp /content/drive/MyDrive/models/Stable-diffusion/*.* /content/stable-diffusion-webui/models/Stable-diffusion/
そしたら再起動。
%cd /content/stable-diffusion-webui
!python launch.py --xformers --theme dark --no-half-vae --opt-sub-quad-attention --share --enable-insecure-extension-access
コツ
https://civitai.com/ でいろんな呪文を見れる
脱がせたい場合は、縦長の写真を作ると脱ぎやすい
widht 256 , height 512など
メモ
えなこもでる
https://civitai.com/models/22034/enako
こんな感じだ。これは先のModel取得の下へ入れれば良い。ほかにもVAE(Variational AutoEncoderの略)やembeddingsのulzzang-6500-v1.1.binなどもあるので、興味のある人は調べて欲しい。ModelやLoraなど多くは、先のcivitaiか、Hugging Faceにあるので検索するのが近道だ。
次は、上記から