Views
No views yet
1pip install diffusers transformers accelerate
2git clone https://github.com/AMD-AIG-AIMA/ReNeg.git1import os
2from pathlib import Path
3import torch
4from diffusers import (
5 StableDiffusionPipeline,
6 DDIMScheduler,
7)
8from safetensors.torch import load_file
9
10model_path = "stable-diffusion-v1-5"
11neg_embeddings_path = "checkpoints/sd1.5_reneg_emb.safetensors"
12pipe = StableDiffusionPipeline.from_pretrained(
13 model_path,
14 safety_checker=None,
15)
16pipe.scheduler = DDIMScheduler.from_pretrained(
17 model_path, subfolder="scheduler"
18)
19device = "cuda"
20pipe.to(device)
21
22neg_embeddings = load_file(neg_embeddings_path)["embedding"].to(device) # Assuming the key is "embedding"
23output = pipe(
24 "A girl in a school uniform playing an electric guitar.",
25 negative_prompt_embeds=neg_embeddings,
26)
27
28image = output.images[0]
29# TextToImageModel is the model you want to evaluate
30image.save("output.png")neg_emb, you can perform inference using only positive prompt.inference.py with args.prompt_type = only_pos.python inference.py --model_path "your_sd1.5_path" --prompt_type "only_pos" --prompt "A girl in a school uniform playing an electric guitar."@misc{li2024reneg,
title={ReNeg: Learning Negative Embedding with Reward Guidance},
author={Xiaomin Li, Yixuan Liu, Takashi Isobe, Xu Jia, Qinpeng Cui, Dong Zhou, Dong Li, You He, Huchuan Lu, Zhongdao Wang, Emad Barsoum},
year={2024},
eprint={2412.19637},
archivePrefix={arXiv},
primaryClass={cs.CV}
}