
Stable Diffusion 活動おぼえがき(初日)
始めに
急にStable Diffusionで遊びたくなったので、やったことの覚え書きをしていきます
作業環境は以下の通り
作業環境
AMD Ryzen 5 2600
NVIDIA GeForce GTX 1660 SUPER (VRAM 4GB)
メモリ24GB
はじめに
インストール方法がわからないので、まずはClaude Codeを入れて、インストールしてもらう。ここ以降の作業メモも、Claude CodeやChatGPTに教わったものが多いので、古い情報や誤った情報があるかもしれない
後から知ったのだが、Stable Diffusion Web UI の Forge版 がインストールされたらしい
モデル。よくわからずに、`anything-v5.safetensors` を入れる
とりあえず出力してみる
a girl, smile, cat ear, white frill dress, knee socks Steps: 20, Sampler: Euler a, Schedule type: Automatic, CFG scale: 8, Seed: 145002429, Size: 512x768, Model hash: 7f96a1a9ca, Model: anything-v5, Version: f2.0.1v1.10.1-previous-669-gdfdcbab6

品質が向上するプロンプトとネガティブプロンプトを入れる
最近のモデルだと所説あるらしいですが、ひとまず導入
(best quality:1.2), masterpiece, (nup, neutral:1.2) a girl, smile, cat ear, white frill dress, knee socks Negative prompt: (worst quality, low quality, extra digits:1.4), (EasyNegative), negative_hand-neg, bad anatomy, text, watermark, signature, speech bubble Steps: 20, Sampler: Euler a, Schedule type: Automatic, CFG scale: 8, Seed: 145002429, Size: 512x768, Model hash: 7f96a1a9ca, Model: anything-v5, Version: f2.0.1v1.10.1-previous-669-gdfdcbab6

Euler a + Automatic より、DPM++2M + Karras の方が良いらしい
根拠は忘れました
(best quality:1.2), masterpiece, (nup, neutral:1.2) a girl, smile, cat ear, white frill dress, knee socks Negative prompt: (worst quality, low quality, extra digits:1.4), (EasyNegative), negative_hand-neg, bad anatomy, text, watermark, signature, speech bubble Steps: 20, Sampler: DPM++ 2M, Schedule type: Karras, CFG scale: 8, Seed: 145002429, Size: 512x768, Model hash: 7f96a1a9ca, Model: anything-v5, Version: f2.0.1v1.10.1-previous-669-gdfdcbab6

Hires.fixを導入
Sampling stepsは下手に上げても20-30で収束するので、それよりは、Hires.fix を使って、出力画像をアップスケールした方が、質のよい画像がでるとのこと。試してみる
(best quality:1.2), masterpiece, (nup, neutral:1.2) a girl, smile, cat ear, white frill dress, knee socks Negative prompt: (worst quality, low quality, extra digits:1.4), (EasyNegative), negative_hand-neg, bad anatomy, text, watermark, signature, speech bubble Steps: 20, Sampler: DPM++ 2M, Schedule type: Karras, CFG scale: 8, Seed: 145002429, Size: 512x768, Model hash: 7f96a1a9ca, Model: anything-v5, Denoising strength: 0.7, Hires Module 1: Use same choices, Hires CFG Scale: 8, Hires upscale: 2, Hires upscaler: Latent, Version: f2.0.1v1.10.1-previous-669-gdfdcbab6

モデルをhimawarimix_v11に変更
差についてはよくわかっていないけど、サンプルの絵がかわいかったのでこれを選択
(best quality:1.2), masterpiece, (nup, neutral:1.2) a girl, smile, cat ear, white frill dress, knee socks Negative prompt: (worst quality, low quality, extra digits:1.4), (EasyNegative), negative_hand-neg, bad anatomy, text, watermark, signature, speech bubble Steps: 20, Sampler: DPM++ 2M, Schedule type: Karras, CFG scale: 8, Seed: 145002429, Size: 512x768, Model hash: e12177c4b0, Model: himawarimix_v11, Denoising strength: 0.7, Hires Module 1: Use same choices, Hires CFG Scale: 8, Hires upscale: 2, Hires upscaler: Latent, Version: f2.0.1v1.10.1-previous-669-gdfdcbab6

X/Y/Z plotを使っていろいろな姿勢を作る
X/Y/Z plot は、seedやプロンプトの一部文言をワイルドカード化して、複数画像をバッチ出力してくれる機能。いろいろな構図や、seedを試したいときにめちゃくちゃ便利。あと、解像度とか、sampling steps も変更できるので、処理と結果のバランスが良いところを探すのにも便利そう
面倒くさいので、いろいろなポーズをChatGPTに提案してもらう
Stable DiffusionのX/Y/Xプロンプト用にさまざまな姿勢が欲しいので、10個くらい提案してください。寝ている、座っている、立っている、動いているなど、できる限り多様なポーズになるようにしてください。ポーズは2-3単語程度で、ポーズごとにダブルクォートで区切って、カンマ区切りにしてください
"lying on back","sitting on chair","standing upright","walking forward","running pose","jumping midair","kneeling down","crouching low","leaning against wall","stretching arms"
ScriptをX/Y/X plotにして、X typeを Prompt S/Rに。X valuesにCSV形式で変更したいプロンプトを追加。先頭の nop は、プロンプトからそれを見つけて変更する変数名
Include Sub ImageをONにしないと、小さい画像のグリッドしか出力されないので注意

プロンプトは以下の通り。(nop: 1.5) にして、ポーズを強調させる
(best quality:1.2), masterpiece, (nup, neutral:1.2)
a girl, smile, cat ear, white frill dress, knee socks
(nop:1.5)

このあたりから、同一プロンプト、同一seedでも、細かい部分を共通にさせることは難しいのだなということを知る
この辺りは、LoRAやControlNet OpenPoseで解決できるらしい。宿題

SDXLモデルの導入
いろいろ遊んでいるうちに、複雑なプロンプトやポーズを取らせるとすぐに破綻することに気づく
そもそも自分が使っていたのは、古いモデルということを理解
stable diffusionのモデルには世代があって、1.5 -> XL -> 3系と進化が進んだらしい
ただし、SD3については、コミュニティと開発間で軋轢が発生していて、現在主流のモデルはXL派生らしい
なので、HimawariMixのXL-v13を導入。先ほどの手が破綻したプロンプトを試す
(best quality:1.2), masterpiece, (nup, neutral:1.2)
a girl, smile, cat ear, white frill dress, knee socks
(stretching arms:1.5)
Negative prompt: (worst quality, low quality, extra digits:1.4), (EasyNegative), negative_hand-neg, bad anatomy, text, watermark, signature, speech bubble
Steps: 20, Sampler: DPM++ 2M, Schedule type: Karras, CFG scale: 8, Seed: 145002429, Size: 512x768, Model hash: d9d661baad, Model: himawarimix_xlV13, Denoising strength: 0.7, Hires Module 1: Use same choices, Hires CFG Scale: 8, Hires upscale: 2, Hires steps: 20, Hires upscaler: Latent, Version: f2.0.1v1.10.1-previous-669-gdfdcbab6

手や足が途中で切れている件。サンプルだとわかりにくいんですが、そもそもSDXLは 3:4だと width:896, height:1152 が推奨らしく、現在の512x768だと、何度生成しても毎回画角がズームした感じなる(ハマった)
正方形だと 1024x1024 とのこと
(best quality:1.2), masterpiece, (nup, neutral:1.2)
a girl, smile, cat ear, white frill dress, knee socks
(stretching arms:1.5)
Negative prompt: (worst quality, low quality, extra digits:1.4), (EasyNegative), negative_hand-neg, bad anatomy, text, watermark, signature, speech bubble
Steps: 20, Sampler: DPM++ 2M, Schedule type: Karras, CFG scale: 8, Seed: 145002429, Size: 896x1152, Model hash: d9d661baad, Model: himawarimix_xlV13, Denoising strength: 0.7, Hires Module 1: Use same choices, Hires CFG Scale: 8, Hires upscale: 2, Hires steps: 20, Hires upscaler: Latent, Version: f2.0.1v1.10.1-previous-669-gdfdcbab6

と思い、896x1152 にしたが、手ははみ出たままで、盛大に破綻した
なので、1024x1024にして、ネガティブプロンプトに extra arm, extra leg を追加
またここで、ついに生成時間が10分を超過する
時間削減のために、Hirs.fixのUpscaleを1.5に変更
本当はこういう風にいろいろまとめて変更するのは、比較しづらくなるのでよろしくない
(best quality:1.2), masterpiece, (nup, neutral:1.2)
a girl, smile, cat ear, white frill dress, knee socks
(stretching arms:1.5)
Negative prompt: (worst quality, low quality, extra digits:1.4), (EasyNegative), negative_hand-neg, bad anatomy, text, watermark, signature, speech bubble, extra arm, extra leg
Steps: 20, Sampler: DPM++ 2M, Schedule type: Karras, CFG scale: 8, Seed: 145002429, Size: 1024x1024, Model hash: d9d661baad, Model: himawarimix_xlV13, Denoising strength: 0.7, Hires Module 1: Use same choices, Hires CFG Scale: 8, Hires upscale: 1.5, Hires steps: 20, Hires upscaler: Latent, Version: f2.0.1v1.10.1-previous-669-gdfdcbab6

6分22秒に短縮
前よりは引きになったが、やっぱりはみ出ている。これ以上は、full body とか入れないと難しい気がする
処理速度の調整: Sampling steps の違いメモ
この辺でSampling stepsの違いでどのくらい品質に差があるのか気になりだす。時間もかかる処理なので、減らせればそれに越したことはない
プロンプトは今までと同じ。Upscaleは1.5で、Sampling stepsを 10,20,30,40,50 で比較してみる

Upscalerありなら、20以降は変化がなかった。
処理速度の調整: UpscalerのHires stepsの違いメモ
次は、Upscaleは1.5で、Sampling steps20で、Hires stepsを10、20、30で比較してみる

こちらも自分では、ほとんど差が分からない感じになった。
処理速度の調整: UpscalerのUpscaleの違いメモ
さらに、Sampling steps20で、Hires steps10で、Upscaleなし、1.1、1.25、1.5、1.75で比較してみる

実のところUpscaleなしでも、見かけ上の品質の変化はなかった
ちなみに処理時間は、
なし : 1分43秒
1.1 : 2分46秒
1.25 : 3分12秒
1.5 : 4分17秒
1.75 : 5分
破綻がないかX/Y/Z plotで再度確認
(best quality:1.2), masterpiece, (nup, neutral:1.2)
a girl, smile, cat ear, white frill dress, knee socks
(nop:1.5)
Negative prompt: (worst quality, low quality, extra digits:1.4), (EasyNegative), negative_hand-neg, bad anatomy, text, watermark, signature, speech bubble, extra arm, extra leg
Steps: 20, Sampler: DPM++ 2M, Schedule type: Karras, CFG scale: 8, Seed: 145002429, Size: 1024x1024, Model hash: d9d661baad, Model: himawarimix_xlV13, Version: f2.0.1v1.10.1-previous-669-gdfdcbab6
"lying on back","sitting on chair","standing upright","walking forward","running pose","jumping midair","kneeling down","crouching low","leaning against wall","stretching arms"

11枚で生成時間は19分28秒。許容範囲。
やっぱり Upscale だいじ
ここまでやっておいてなんですが、画像によっては、Upscale 1.5 するとだいぶ違うことに気が付く

ここまでのまとめ
HimawariMixのXL-v13 の場合
1024x1024 が公式が学習したサイズなのでそれに準ずる方が良い
縦長や横長にすると、それに合わせた構図になるので、その場合は、1152x896 にする
Sampling steps 20 以上にしても、見た目上の変化はない
Upscaleは1.5くらいはやった方が良い
ここまでの感想
現状のビデオカードだと時間がかかる……!!
アラートこそ出ていないが、VRAMもコア数も足りていない気がする。今後のことを考えて、新しいビデオカードが欲しい
これからやりたいこと
同一キャラをどれだけ維持できるか?
表情差分、姿勢差分、アイテム差分など。差分がどれだけ作れるか
おまけ。
hassaku-xl-illustriousも落としたので、同一プロンプトでどんな違いがあるか確認
(best quality:1.2), masterpiece, (nup, neutral:1.2)
a girl, smile, cat ear, white frill dress, knee socks
(nop:1.5)
Negative prompt: (worst quality, low quality, extra digits:1.4), (EasyNegative), negative_hand-neg, bad anatomy, text, watermark, signature, speech bubble, extra arm, extra leg
Steps: 20, Sampler: DPM++ 2M, Schedule type: Karras, CFG scale: 8, Seed: 145002429, Size: 1024x1024, Model hash: 9ece21c352, Model: hassakuXLIllustrious_v22, Denoising strength: 0.7, Hires Module 1: Use same choices, Hires CFG Scale: 8, Hires upscale: 1.5, Hires steps: 10, Hires upscaler: Latent, Version: f2.0.1v1.10.1-previous-669-gdfdcbab6
