Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,87 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- text-to-image
|
| 5 |
+
- image-generation
|
| 6 |
+
- baai-nova
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
<div align="center">
|
| 10 |
+
<h1>ReNeg: Learning Negative Embedding with Reward Guidance</h1>
|
| 11 |
+
</div>
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
<div align="center">
|
| 15 |
+
|
| 16 |
+
[](https://arxiv.org/abs/2412.19637)
|
| 17 |
+
[](https://github.com/AMD-AIG-AIMA/ReNeg)
|
| 18 |
+
|
| 19 |
+
</div>
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
We present **ReNeg**, a **Re**ward-guided approach that directly learns **Neg**ative embeddings through gradient descent. The global negative embeddings learned using **ReNeg** exhibit strong generalization capabilities and can be seamlessly adaptable to text-to-image and even text-to-video models. Strikingly simple yet highly effective, **ReNeg** amplifies the visual appeal of outputs from base Stable Diffusion models.
|
| 24 |
+
|
| 25 |
+
## Examples
|
| 26 |
+
|
| 27 |
+
Using the [🤗's Diffusers library](https://github.com/huggingface/diffusers) to run ReNeg in a simple and efficient manner.
|
| 28 |
+
|
| 29 |
+
```bash
|
| 30 |
+
pip install diffusers transformers accelerate
|
| 31 |
+
git clone https://github.com/AMD-AIG-AIMA/ReNeg.git
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
Running ReNeg:
|
| 35 |
+
|
| 36 |
+
```python
|
| 37 |
+
import os
|
| 38 |
+
from pathlib import Path
|
| 39 |
+
import torch
|
| 40 |
+
from diffusers import (
|
| 41 |
+
StableDiffusionPipeline,
|
| 42 |
+
DDIMScheduler,
|
| 43 |
+
)
|
| 44 |
+
from safetensors.torch import load_file
|
| 45 |
+
|
| 46 |
+
model_path = "stable-diffusion-v1-5"
|
| 47 |
+
neg_embeddings_path = "checkpoints/sd1.5_reneg_emb.safetensors"
|
| 48 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 49 |
+
model_path,
|
| 50 |
+
safety_checker=None,
|
| 51 |
+
)
|
| 52 |
+
pipe.scheduler = DDIMScheduler.from_pretrained(
|
| 53 |
+
model_path, subfolder="scheduler"
|
| 54 |
+
)
|
| 55 |
+
device = "cuda"
|
| 56 |
+
pipe.to(device)
|
| 57 |
+
|
| 58 |
+
neg_embeddings = load_file(neg_embeddings_path)["embedding"].to(device) # Assuming the key is "embedding"
|
| 59 |
+
output = pipe(
|
| 60 |
+
"A girl in a school uniform playing an electric guitar.",
|
| 61 |
+
negative_prompt_embeds=neg_embeddings,
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
image = output.images[0]
|
| 65 |
+
# TextToImageModel is the model you want to evaluate
|
| 66 |
+
image.save("output.png")
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
To compare with the inference results using `neg_emb`, you can perform inference using only positive prompt.
|
| 70 |
+
+ To perform **inference using only the pos_prompt**, you need to run `inference.py` with `args.prompt_type = only_pos`.
|
| 71 |
+
```bash
|
| 72 |
+
python inference.py --model_path "your_sd1.5_path" --prompt_type "only_pos" --prompt "A girl in a school uniform playing an electric guitar."
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
## Citation
|
| 77 |
+
|
| 78 |
+
```
|
| 79 |
+
@misc{li2024reneg,
|
| 80 |
+
title={ReNeg: Learning Negative Embedding with Reward Guidance},
|
| 81 |
+
author={Xiaomin Li, Yixuan Liu, Takashi Isobe, Xu Jia, Qinpeng Cui, Dong Zhou, Dong Li, You He, Huchuan Lu, Zhongdao Wang, Emad Barsoum},
|
| 82 |
+
year={2024},
|
| 83 |
+
eprint={2412.19637},
|
| 84 |
+
archivePrefix={arXiv},
|
| 85 |
+
primaryClass={cs.CV}
|
| 86 |
+
}
|
| 87 |
+
```
|