FreeStyleWiki

Sampling methodとその技術的基盤

このエントリーをはてなブックマークに追加

[お絵描きAI]

Sampling methodとその技術的基盤

  概要

まずはここを見よ

  Diffusion modelとは?

What are Diffusion Models?

  • ノイズだけの画像にある計算をして、理想の画像に近づけることをサンプリングと言うようだ
sampling method 元ネタ リファレンス実装
Euler a a がつくとAncestral samplingを意味する
Euler Karras et al. (2022) https://github.com/crowsonkb/k-diffusion
LMS
Heun Karras et al. (2022) https://github.com/crowsonkb/k-diffusion
DPM2 DPM-Solver++(2S) and (2M) https://github.com/crowsonkb/k-diffusion
DPM2 a a がつくとAncestral samplingを意味する
DDIM denoising diffusion implicit model(=DDIM;Song et al 2020)
PLMS

DPM2とheunは1stepあたりEulerの2倍の回数、拡散モデルを通過するので実行時間が増える。

LMSやPLMSはEulerより高次の計算をするが、過去の拡散モデルの出力を保持するので実行時間は増えない。

Samplerの違いに関して正確な理解がしたいなら常微分方程式の数値解法に関する勉強をすればよい。

StableDiffusionのサンプリング法

  v-diffusion-pytorch

k-diffusionの元となった実装がここにある

The models are denoising diffusion probabilistic models ( https://arxiv.org/abs/2006.11239 )

とあるので、結構前のものを参照している?

インストール手順

$ git clone https://github.com/crowsonkb/v-diffusion-pytorch.git
$ cd v-diffusion-pytorch/
$ python -m venv .venv --prompt v-diffusion-pytorch
$ pip install -e .

推論実行

$ mkdir checkpoints
$ wget https://the-eye.eu/public/AI/models/v-diffusion/cc12m_1_cfg.pth

$ ./cfg_sample.py "the rise of consciousness":5 -n 1 -bs 4 --seed `shuf -i 1-1000000 -n 1`

初期のものなので、できてくる画像は正直気持ち悪い...danbooruで学習されたSFWなモデルがあるのでそっちのほうがいいかもしれない。

$ ./cfg_sample.py --checkpoint checkpoints/danbooru_128.pth --model danbooru_128 \
  "a girl standing":5 -n 1 -bs 4 --seed `shuf -i 1-1000000 -n 1`

コードの修正は必要だが、まだマシなものが出力される。モデルごとに構造が異なる、勉強になる。

v-diffusion-pytorchで用意されているモデル

https://github.com/rttt1093/v-diffusion-pytorch#model-checkpoints