はじめに
皆さん、Clip Skipの値を気に留めたことはありますか?
画像生成AIには、Clip Skipという項目を目にしたことがある方が多いと思いますが、正直何のことかよくわかっていない方も多いと思います。
そこで、今回はClip Skipに関する内容を、紐解いていってみようと思います。
Clip Skipとは
※2023.05.03 引用元の内容に誤りがあった為、引用元を変更しています。
と、ズラッと英語が並んでいてぱっと見、何のことかわからないと思いますので、要点だけを纏めて説明します。
Clip Skipの要約
上記の説明を纏めて、要点を図解しています。
※2023.05.03 引用元の内容に誤りがあった為、図を修正しています。
この図では、引用元の文章に習い、CLIP Textが「human」+Clip Skip:2であった場合、どのような挙動をするか図解しています。
実際、ニューラルネットワークでは、「human」という文字列をそのまま受け取ることはできません。
CLIP Textで言語化された文字列を用いて、数値化(Text-EncodingによるToken化)し、ニューラルネットワークへ引き渡しています。
この数値化された情報をどのレイヤでストップさせ、ニューラルネットワークへ引き渡すかを定めるのが「Clip Skip」です。
上図から想像付くと思いますが、参照レイヤの深度が浅い段階でスキップされると、引き渡す情報量も少なくなり、結果的に不正確な情報ノイズとして生成される画像に影響を及ぼすこととなります。
Clip Skipの影響度
実際にClip Skip値を設定し、画像を生成してみましょう。
画像生成プロンプトと各設定値は以下で固定。
上図を見てもらうと分かる通り、大幅な変化が見て取れます。
構図自体の変遷としては、Clip Skip:5を超えたあたりから、大部分の構図が一定になるものの、画像の鮮明度としては非常に悪いものになっています。
これは、参照レイヤの深度が浅く、引き渡す情報量が少なくなり、正しい言語変換が出来ずに、不正確な情報がノイズとなり、それが引き渡された影響と判断できるでしょう。
Clip SkipとCFG Scaleの関係
生成画像に大きく関わってくる要素として、CFG Scaleと呼ばれるものがあります。
これは、恐らく皆さんもご存じと思われるので、説明については割愛させて頂きます。
では、Clip SkipとCFG Scaleで相互作用はあるのかを紐解いていきましょう。
上図を見てもらうと分かる通り、構図の大きな変化はなく、Clip Skip値に沿った画像内で軽微な変化のみ見て取れます。
従って、Clip SkipとCFG Scaleに相互作用はなく、全くの別物と思っても良いと思います。
Clip Skipの使い道
ここまで見ると、勘の良い人なら、ある程度Clip Skipの使い道が見えてくるのではないでしょうか。
ここでは、筆者がClip Skipを実際に使用してる手法をお伝えしようと思います。
Text 2 Image+Seed値固定+Clip Skip変更
t2iで好きな構図を出す
Seed値を確定させる
Clip Skipを変化させ生成する
構図に対する影響度は「高」
ニッチな用途だが、あと少しの変化が欲しいというときに利用しています。
Image 2 Image+Seed値固定+Clip Skip変更
t2iで好きな構図を出す
Seed値を確定させる
i2iにてClip Skipを変化させ生成する
構図に対する影響度は「低」
i2i+Clip Skip変更は、思ったよりも大きな構図変化が見られません。
それは、i2iの特性上、画像データの情報が優位的に働いているためです。
構図に変化を加えたくないが、細部の変化が欲しいというときに利用しています。
Clip Skipに関するライフハック
AUTOMATIC1111 WebUIだと、Clip Skipの設定箇所が設定タブでしか変更できません。
その為、設定項目をCheckpointなどがあるUIヘッダ部分へ移動してしまいましょう。
設定は、[設定]タブ -> [ユーザーインターフェース]項目 -> [クイック設定]から行えます。
上図では、
の設定をUIヘッダ部へ表示するようにしています。
クイック設定欄に以下を入力して、[設定を適用]してみましょう。
sd_model_checkpoint,sd_vae,CLIP_stop_at_last_layers
設定適用後、UIを再度読み込めば…
このように表示することができました。
おまけで、VAEもよく使う項目なので、追加しています。
おわりに
今回はClip Skipに関するお話をしました!
ちょっと堅苦しい内容になりましたけど、Clip Skipに関して詳しく取り上げてる記事が少ないので、少し踏み込んで解説しました。
皆さんもClip Skip使ってみてはいかがですか?