はじめに
「EasyNegative」については以下の記事を参照させて頂きました。koneko3.com
今回はDiffuserに「EasyNegative」を導入してみます。
EasyNegativeを使う
必要なのはたったの2行でした。(こちらを参照)pipe.load_textual_inversion("EasyNegative-test", weight_name="EasyNegative.safetensors", token="EasyNegative") negative_prompt = "EasyNegative"
全体のスクリプトをのせておきます。
import os import torch from diffusers import DiffusionPipeline, AutoencoderKL, EulerAncestralDiscreteScheduler def main(): model_id = "model/Counterfeit-V2.0" vae_folder = "vae/anime2_vae" prompt = "masterpiece, best quality, 1girls, brown hair, brown eyes, long skirt, wide shot, coffee shop" negative_prompt = "EasyNegative" vae = AutoencoderKL.from_pretrained(vae_folder, torch_dtype=torch.float16).to('cuda') pipe = DiffusionPipeline.from_pretrained( model_id, safety_checker=None, vae=vae, torch_dtype=torch.float16) pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config) pipe.load_textual_inversion("EasyNegative-test", weight_name="EasyNegative.safetensors", token="EasyNegative") pipe.to("cuda") n_samples = 10 base_seed = 200 os.makedirs('results', exist_ok=True) for i in range(n_samples): seed = base_seed + i generator = torch.manual_seed(seed) image = pipe( prompt = prompt, negative_prompt = negative_prompt, generator = generator, num_images_per_prompt = 1, width = 512, height = 768).images[0] image.save(os.path.join('results', f'seed{seed}.png')) if __name__ == "__main__": main()