見出し画像

Stable Diffusionワイルドカードを使ったみた!

こんにちは、あるいは、こんばんは!
Stable Diffusionでのプロンプト生成で悩み、画像生成につまってしまい、筆が、タイピングが、思考が停止しまいがちです。
プログラミングやらネットの検索ワードやらでよく用いられる「ワイルドカード」を利用して、こんぴゅう太くんに代わりに考えてもらおうと思った次第です。

そんなふうに思った皆さまに、いいものがありました!
Stable Diffusion Automatic1111 Web UI の拡張機能、「dynamic-prompts」です。
以前に拡張機能を追加した際に、うやむやのままLyCORISが使えるようになっていたので、今回はしっかりと実装される様子を検証したいと思います♪

Stable Diffusion Automatic1111 Web UIを起動します。

わたしの環境では以下・・・(しつこい? 読み飛ばしてくださいね)

conda activate py310
cd /Users/user/Dropbox/GitHub/clone/stable-diffusion-webui
python launch.py --skip-python-version-check

…Running on local URL:  http://127.0.0.1:7860

Running on local URL: http://127.0.0.1:7860と表示されましたら、ウェブブラウザでアクセスします。

拡張機能(Extensions)から「dynamic-prompts」をインストールするよ!

Stable Diffusionを立ち上がってから、
①タブが並んでいるところの「Extensions(拡張機能)」を選択
②さらにタブが並んでいますので「Avairable(拡張機能リスト)」を選択
③「Load from:(読込)」をポチッ
④「wildcard」を検索
⑤「Install(インストール)」してみましょう!

①「Extensions(拡張機能)」 ②「Avairable(拡張機能リスト)」
③「Load from:(読込)」 ④「wildcard」検索 ⑤「Install(インストール)」

エラーですね(- -;)

stderr: 'fatal: destination path 'C:\Users\user\Dropbox\GitHub\clone\stable-diffusion-webui\tmp\sd-dynamic-prompts' already exists and is not an empty directory.

じゃあ、GitHubからcloneするよ!

ありがちなエラーで困りものですが、わたしには解決できないと思うのでGitHubからcloneすることにしました。
(普通にダウンロードすることもできますよ)

adieyal 様の sd-dynamic-prompts をダウンロードします。
https://github.com/adieyal/sd-dynamic-prompts

cd /Users/user/Dropbox/GitHub/clone/stable-diffusion-webui/extensions
git clone https://github.com/adieyal/sd-dynamic-prompts.git

検証するつもりでしたが、いつの段階で入っていたのか今回も分からず・・・_(-.-;)

いつの間にかインストール済

とにかく入ったので、使ってみます!

ワイルドカードを使ったみた!

インストールしたらUIを再起動します。
「txt2img」や「img2img」のタブを選択すると、下のほうに「Dynamic Prompts」が増えています。「▼」で展開します。
(タブには「Wildcard Manager」というものも ふえています)
「Dynamic Prompts enabled(有効化)」にチェックします。
(「Combinatorial generation(組み合わせを生成)」は、総当たりの組み合わせを行って、画像を生成するものです)

基本構文を書いてみるよ!

基本的な呪文の書き方
{ num $$重み1 :: 呪文1 | 重み2 :: 呪文2 | 重み3 :: 呪文3 }

numには数値を入力:数値の数だけランダムに選択します
重みには数値を入力:相対的な強さを表現します
呪文にはテキストを入力:いつもの表現を組み合わせてみましょう

使用したモデルは「Cheese Daddy's Landscapes mix」です。
風景画がきれいですね!

プロンプトを参考にして以下を入力しました。

masterpiece, best quality, high quality, extremely detailed CG unity 8k wallpaper,
{Ocean, vastness, depth, blue expanse, rolling waves, white foam, salt spray, marine life, coral reefs, sandbars, sea breezes, vast horizon, sunrises | ultra-detailed, illustration, 1girl, witch hat, purple eyes, blonde hair, wielding a purple staff blasting purple energy, purple beam, purple effects, dragons, chaos, marisa, anime | landscape with texture ,A place with lots of leaves on the ground and autumn colors | flowering landscape, A dry place like an empty desert,dearest,foxy,Mono Lake,hackberry,3D Digital Paintings | Fantasy landscape, towering mountains, lush forests, rolling hills, sparkling rivers, shimmering lakes, enchanted meadows, mysterious caves, hidden waterfalls, rainbow skies, celestial lights| a beautiful landscapes oil paiting, award winning photography, Bokeh, Depth of Field, HDR, bloom, Chromatic Aberration ,Photorealistic,extremely detailed, trending on artstation, trending on CGsociety, Intricate, High Detail, dramatic, art by midjourney AND masterpiece, best quality, high quality, extremely detailed CG unity 8k wallpaper A lush summer landscape, with rolling green hills that stretch towards the horizon, dotted with wildflowers in shades of pink, yellow, and purple, volumetric lighting AND masterpiece, best quality, high quality, extremely detailed CG unity 8k wallpaper A serene autumn landscape, surrounded by trees in hues of golden yellow, fiery red, and burnt orange. The crisp air carries the sweet fragrance of fallen leaves and wood smoke. The ground is covered with a blanket of warm-colored leaves that rustle underfoot. In the distance, a misty mountain range rises up, volumetric lighting AND masterpiece, best quality, high quality, extremely detailed CG unity 8k wallpaper A breathtaking winter landscape, blanketed in a mantle of snow, creating a world of glittering whites and cool blues. Tall evergreens stand tall and proud, their branches weighed down by heavy snow, volumetric lighting AND masterpiece, best quality, high quality, extremely detailed CG unity 8k wallpaper A vibrant spring landscape, bursting with new life and color. Rolling hills are covered with a carpet of green, dotted with delicate wildflowers in shades of pink, purple, and yellow, volumetric lighting},
award winning photography, Bokeh, Depth of Field, HDR, bloom, Chromatic Aberration ,Photorealistic,extremely detailed, trending on artstation, trending on CGsociety, Intricate, High Detail, dramatic, art by midjourney

一番下にある「Script」という機能に近い使い方をしているのですが、一つのPromptで表現できるようになったみたいです。
次はもう少しわかりやすく、モデルさんの髪の毛の色などを変えてみます。

masterpiece, best quality, high quality, extremely detailed CG unity 8k wallpaper, ultra-detailed, illustration, 1girl, solo,  
{ purple | red | green | blue } eyes, { blonde | black | red | green | blue } hair,
award winning photography, Bokeh, Depth of Field, HDR, bloom, Chromatic Aberration ,Photorealistic,extremely detailed, trending on artstation, trending on CGsociety, Intricate, High Detail, dramatic, art by midjourney

ワイルドカードファイルを使ってみる!

入力の手間がどうしても残ってしまうので、あらかじめワードを入力しておくワイルドカードファイルを準備しておきます。
自作の場合には、以下のようにテキストファイルを作成しましょう。

呪文1
呪文2
呪文3
…(つづく)

すでに作成されているものをダウンロードすることもできます。
例えば、CIVITAI から探してみてください。

ダウンロードしたファイルを展開して、フォルダごと以下のディレクトリに入れましょう。

C:/Users/user/Dropbox/GitHub/clone/stable-diffusion-webui/extensions/sd-dynamic-prompts/wildcards

わたしのパス

もし、余裕があればテキストの中身も確認してみてください。

akebia fruit
apple
apple bunny
apple core
apple peel
bitten apple
candy apple
golden apple
green apple
red apple
avocado
banana

food_fruit.txt

使い方ですが、例えば「FILE_NAME.txt」の場合には 以下のようにプロンプトを書きます。

masterpiece, 1 girl, __FILE_NAME__

FILE_NAMEの前後に、"_(アンダースコア)"を2つずつ入力します

ともあれ、まずは実際にやってみましょう!
以下を入力してみましたよ。

masterpiece, 1 girl, __expression__, bring __food_sweets__, __color__ colored __clothing-female__

ランダムで画像を作成してくれます!
いろいろな画像を作成してほしい場合には、「Batch count」を増やすと簡単にできますよ。
(ほかの機能との組み合わせもできると思います)

まとめ

使い方としては、今のものに、「何か変化を加えたい!」という時に とても有用になるのかなぁ・・・と思っています。
img2imgもできますので、チャレンジしてみてください。
表現を言語化するのに悩んで頭がショートしてしまったら、一度、使ってみてはいかがでしょうか。


誤字・脱字が有りましたので修正加えました。
内容は初稿と変更ありません。

この記事が参加している募集

やってみた

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