見出し画像

グレート・ピレニーズをTVで見ていたらふとFooocusを使ってみようと思った(調査編)

Fooocus」は「Stable Diffusion」のWeb UIです。
WindowsやMac、Linux、Google Colab上で動作します。

今回、Google Colab(Pro)で動かしました。
上記のGitHubからColab用コードを入手できます。

!pip install pygit2==1.12.2
%cd /content
!git clone https://github.com/lllyasviel/Fooocus.git
%cd /content/Fooocus
!python entry_with_update.py --share

Great Pyrenees is runningのログ

生成した画像は「outputs」ディレクトリに格納されます。

/content/Fooocus/outputs/YYYY-MM-DD/

画面下の「Advaneced」をチェックすると右側に設定パネルが表示されます。
例えばStyleタブの「Fooocus V2」にチェックしてプロンプト
Great Pyrenees is running
を実行します。

Great Pyrenees is running & Fooocus V2

実際には複数のワードが追加されたプロンプトが投げられます。
このプロンプトは上記ディレクトリに書き込まれる「log.html」で確認できます。
log.html」を表示する際、事前に/content/Fooocus/outputs/YYYY-MM-DD に生成された画像も同じフォルダにダウンロードしておきます。

生成した画像もダンロードしてlog.htmlを表示

実際のプロンプトは言葉が足されています。

Great Pyrenees is running, radiant light, very detailed, stunning, intricate, cinematic, extremely complimentary colors, pristine, beautiful, romantic, perfect, vibrant, complex, color, highly saturated, theatrical, sublime, sharp focus, fine detail, professional, spiritual surreal background, best, unique, amazing, breathtaking, creative, positive, joyful, thought, pure, attractive

JSONのプロンプトで再現

Styleを変更してみます。

Great Pyrenees is running &  Fooocus Cinematic

log.htmlを見ます。

上記生成を反映直後のlog.html

今回使用した「Fooocus Cinematic」のプロンプトの記述がありません。
以下のフォルダにある「sdxl_styles_fooocus.json」を参照しているようです。

/content/Fooocus/sdxl_styles/

sdxl_styles_fooocus.json」に書かれているプロンプト(以下)を使ってFooocusで生成して試してみます。

    {
        "name": "Fooocus Cinematic",
        "prompt": "cinematic still {prompt} . emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
        "negative_prompt": "anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured"
    }

この際、のチェックはすべて外します。

参照ファイルのプロンプトを利用して生成
上記後のlog.html。Stylesがブランクになっています

JSONを書き換えて白を黒に

フォトリアルなケースではわかりにくいのでもう1パターン試しました。
SAI Origami」の例です。

Great Pyrenees is running &  SAI Origami

Styleのチェックを全部外し、「/content/Fooocus/sdxl_styles/sdxl_styles_sai.json」に書かれている「SAI Origami」のプロンプトを使って生成します。

origami style {Great Pyrenees is running} . paper art, pleated paper, folded, origami art, pleats, cut and fold, centered composition

今度は、sdxl_styles_sai.jsonの「SAI Origami」の内容を一部書き換え、「/content/Fooocus/sdxl_styles/」にアップロードします。
ゴチック部分が追記した箇所です。

{ "name": "sai-origami", "prompt": "origami style {prompt} . black colored paper art, black colored pleated paper, folded, origami art, pleats, cut and fold, left composition",
"negative_prompt": "noisy, sloppy, messy, grainy, highly detailed, ultra textured, photo" },

Google Colabの実行を中断し、以下コマンドでFooocusを再起動。
書き換えたjsonを再読み込みしてもらいます。

!python entry_with_update.py --share

SAI Origami」をチェックして実行しました。

Great Pyrenees is running &  SAI Origami改

ただ、jsonに記載されているプロンプトを「こうすればこう変わるはず」と思い、変えてみても変化が起きないこともしばしばありました。
プロンプト内に優先順位があるのか、他に生成内容を決めているプロンプトが組み込まれているのかもしれません。

Civitaiからモデルをダウンロード

学習モデルは以下ディレクトリに入っています。

/content/Fooocus/models/checkpoints/

冒頭で使ったコードでは、デフォルトで下記のモデルを格納します。

/content/Fooocus/models/checkpoints/juggernautXL_v8Rundiffusion.safetensors

別のモデルを組み込むことも可能でした。
例えば、Civitaiから(何となく目に留まった)「Artium」をダウンロードしてみます。
!aria2cコマンドの部分を変えています。

!pip install pygit2==1.12.2
%cd /content
!git clone https://github.com/lllyasviel/Fooocus.git
!apt -y install -qq aria2
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://civitai.com/api/download/models/277071 -d /content/Fooocus/models/checkpoints -o Artium-v2.0.safetensors
%cd /content/Fooocus
!python entry_with_update.py --share

Modelタブから「Artium」を選択できるようになります。

「Artium」を選択

なお、ベースモデルの対象が「SDXL」に限るようです。
試しに「SD1.5」のモデルを1つダウンロードしましたが、動作しませんでした。
Styleのチェックをすべて外し、「Artium」に掲載されているプロンプトを参考に生成しました。

Styleを全部外して「Artium」で生成

ローカル→Googleドライブ→Colab

!aria2cコマンドを実行中、認証エラーが出てダウンロードを失敗することがあります。
原因はわからないのですが、その場合はローカルのディスクにダウンロードしてから /content/Fooocus/models/checkpoints にアップロードします。

Exception: [AbstractCommand.cc:351] errorCode=24 URI=https://civitai.com/api/download/models/xxxxxx
  -> [HttpSkipResponseCommand.cc:215] errorCode=24 Authorization failed.

ローカルのディスクからColabのディレクトリに直接アップするのはうまくいかなかったので、Googleドライブを経由しました。
今回の場合、Civitaiから「RealCartoon-XL」のモデル(6.46GB)をローカルにダウンロード。
Googleドライブにアップしてから、Colabのディレクトリにコピーしました。 

# Googleドライブをマウント
from google.colab import drive
drive.mount('/content/drive')

# Googleドライブからコピー
!cp /content/drive/MyDrive/model/* /content/Fooocus/models/checkpoints/

先ほどと同様にFooocusのStyleのチェックをすべて外し、「RealCartoon-XL」のモデルを選択して、生成を実行しました。

Styleを全部外して「RealCartoon-XL」で生成

次は「LoRA」を試そうと思っています。

参考


この記事が気に入ったらサポートをしてみませんか?