スポンサーリンク
I was able to use embedding in diffusers, so I tried it out!
This article is a reminder of the introduction
contents
スポンサーリンク
abstract
How to introduce embedding with diffusers
1.requirement
Google Colab
Diffusers:0.15.0
transformers:4.26.0
2.code
We have previously created a code to generate images with diffusers
technoxs-stacker.hatenablog.com
This time, add the following embedding loading process to the above code
# --- load embedding file --- emb_path=path/to/embedding file#Specify the path to the downloaded safetensor file pipe.load_textual_inversion(pretrained_model_name_or_path=emb_path, token=token_word, local_files_only=True) #token_word specifies the word used to activate embedding # ---------------------------------------
The following is the completed code
model_name = modelname save_name = filename.png save_dir = path/to/save/directory os.makedirs(save_dir, exist_ok=True) save_path = os.path.join(save_dir, save_name) seed = 3000000 device = "cuda" pipe = StableDiffusionPipeline.from_pretrained(model_name, torch_dtype=torch.float32) pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config) pipe = pipe.to("cuda") if pipe.safety_checker is not None: pipe.safety_checker = lambda images, **kwargs: (images, False) # --- load embedding file --- emb_path=path/to/embedding file#Specify the path to the unloaded safetensor file pipe.load_textual_inversion(pretrained_model_name_or_path=emb_path, token=token_word, local_files_only=True) #token_word specifies the word used to activate embedding # --------------------------------------- positive=possitive prompt negative=negative prompt generator = torch.Generator(device).manual_seed(seed) image = pipe(positive, negative_prompt=negative, generator=generator).images[0] image.save(save_path)
スポンサーリンク