【Optimized Stable Diffusion】ネガティブプロンプトを使ってみる

はじめに

今さらながらStable Diffusionで遊んでみます。

ネガティブプロンプトを使ってみたので記録を残します。

使用させて頂いたのはVRAM 6GBでも問題なく動作する「Optimized Stable Diffusion」です。
github.com
Windows 11を使用しています。(WSL2は使っていません)

PC環境

Windows 11
RTX 3060 Laptop (VRAM 6GB)
CUDA 11.6.2
Git for Windows 2.37.3
Python 3.9.13

環境構築

以下の2行で済みます。

pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116
pip install -r https://raw.githubusercontent.com/dai-ichiro/env4stable-diffusion/main/optimized/requirements_win.txt

詳細は過去記事にありますのでよかったら読んで下さい。

実行

「optimized_txt2img.py」の書き換え

プロンプト、ネガティブプロンプトをテキストファイルに記述できるように「optimizedSD」フォルダ内の「optimized_txt2img.py」を書き換えました。

書き換えたものはこちらです。

ファイル名を「txt2img.py」として「optimizedSD」フォルダ内に保存しました。

まずは普通に動かしてみる

プロンプトを記述したファイル(prompt.txt)

内容(呪文)はこちらのサイトから拝借しました。ありがとうございます。

anime of tsundere moe kawaii beautiful girl
pixiv niconico artstation deviantart newgrounds tumblr
fantasy scene fantasy composition fantasy lighting
PlayStation5 octane render

実行

python optimizedSD/txt2img.py --prompt-file prompt.txt --seed 972950

結果

デフォルトで5枚の画像が作成されます。

赤い髪と赤い眼を除外

赤い髪と赤い眼を除外したい場合にネガティブプロンプトを使用します。

プロンプトを記述したファイル(prompt.txt)

先ほどと変えていません。

anime of tsundere moe kawaii beautiful girl
pixiv niconico artstation deviantart newgrounds tumblr
fantasy scene fantasy composition fantasy lighting
PlayStation5 octane render

ネガティブプロンプトを記述したファイル(negative_prompt.txt)

red hair
red eyes

実行

python optimizedSD/txt2img.py --prompt-file prompt.txt --negative-prompt-file negative_prompt.txt --seed 972950

結果


少女はひとりで十分

ふたりの少女が描かれた画像を除外します。

プロンプトを記述したファイル(prompt.txt)

先ほどと変えていません。

anime of tsundere moe kawaii beautiful girl
pixiv niconico artstation deviantart newgrounds tumblr
fantasy scene fantasy composition fantasy lighting
PlayStation5 octane render

ネガティブプロンプトを記述したファイル(negative_prompt.txt)

2girls
red hair
red eyes

実行

python optimizedSD/txt2img.py --prompt-file prompt.txt --negative-prompt-file negative_prompt.txt --seed 972950

結果

「2girls」を除外するとひとりの少女が少年に変わりました。

少年はいらない

少年を除外します。

プロンプトを記述したファイル(prompt.txt)

先ほどと変えていません。

anime of tsundere moe kawaii beautiful girl
pixiv niconico artstation deviantart newgrounds tumblr
fantasy scene fantasy composition fantasy lighting
PlayStation5 octane render

ネガティブプロンプトを記述したファイル(negative_prompt.txt)

2girls
boy
red hair
red eyes

実行

python optimizedSD/txt2img.py --prompt-file prompt.txt --negative-prompt-file negative_prompt.txt --seed 972950

結果