EasyNegativeの概要と使い方
EasyNegativeとは
「ネガティブプロンプト用」のTextual Inversion埋め込み。
SD1.5モデルで「粗悪な画像特徴」を学習したもので、ネガティブプロンプトに使うことで生成から不要要素を抑制。
元のモデルはSD1.5用であり、Trigger word(トークン名)はeasynegativeと設定されているprompthero.com。
Stable Diffusion Web UI (Automatic1111) での使い方
ファイル配置
EasyNegativeの.ptまたは.safetensorsファイルを、Web UI フォルダ内の embeddings ディレクトリに配置
github.com。配置後、UIを再起動する必要はない。
プロンプト指定
プロンプト入力欄(特にネガティブプロンプト欄)で、埋め込みのトークン名(例: EasyNegative)を指定。
たとえば、ネガティブプロンプトに (EasyNegative:1.0) と書けば、重み1.0で適用prompthero.com
複数埋め込みの組み合わせ
他の埋め込みと組み合わせる場合は、カンマ区切りやスペースで複数トークンを指定。例: EasyNegative, badhandv4。
必要に応じて括弧で重み調整
例: Stable Diffusion Web UIのネガティブプロンプト欄に直接 EasyNegative を入力するだけで有効https://scrapbox.io/files/6814d05a7cfe3de494b51253.png
Diffusersライブラリでの使い方
パイプラインの選択
Diffusersでは主に StableDiffusionPipeline(テキスト→画像)や StableDiffusionImg2ImgPipeline、SDXL向けなら AutoPipelineForText2Image などを使用
埋め込みの読み込み
load_textual_inversion メソッドでEasyNegativeを読み込みます。たとえばローカルファイルから読み込む場合は
code:python
from diffusers import StableDiffusionPipeline
pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16).to("cuda")
pipe.load_textual_inversion("path/to/EasyNegative.safetensors", token="EasyNegative")
Hugging Face Hub上のリポジトリから読み込む場合は、リポジトリIDとファイル名(weight_name)を指定
プロンプト生成
埋め込み読込後、プロンプト中およびネガティブプロンプト中でトークン EasyNegative を使う。
code:python
prompt = "A beautiful landscape, high quality, EasyNegative"
negative = "EasyNegative"
image = pipe(prompt, negative_prompt=negative, num_inference_steps=50).images0
こうすると、Positiveプロンプトと同時にネガティブ埋め込みが適用される
コード例:
code:python
from diffusers import StableDiffusionPipeline
import torch
pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16).to("cuda")
# 埋め込みを読み込む(ローカルファイル例)
pipe.load_textual_inversion("EasyNegative.safetensors", token="EasyNegative")
# 生成
prompt = "A fine detailed portrait of a woman, masterpiece, EasyNegative"
img = pipe(prompt, negative_prompt="EasyNegative", num_inference_steps=50).images0
img.save("out.png")
SD1.5 と SDXL の対応・互換性
対応モデル
EasyNegative はSD1.5系で作成された埋め込みであり、Base model: SD1.5 とされている。
公式情報でも「SD1.5 埋め込みは SDXLでは直接効果がない」と指摘されているgithub.com。
SDXLでの使用
SDXLには2つのテキストエンコーダがあるが(1つはSD1.5のCLIPと同型)、Stable Diffusion WebUIではSDXLでSD1.5用埋め込みが自動適用されないことがあるgithub.com。
基本的にはSD1.5系モデルでの使用を推奨prompthero.comgithub.com。
#Daichi_Sugita