Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
pipeline_tag: unconditional-image-generation
|
| 5 |
+
tags:
|
| 6 |
+
- Diffusion Models
|
| 7 |
+
- Stable Diffusion
|
| 8 |
+
- Perturbed-Attention Guidance
|
| 9 |
+
- PAG
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Perturbed-Attention Guidance
|
| 13 |
+
|
| 14 |
+
[Project](https://ku-cvlab.github.io/Perturbed-Attention-Guidance/) / [arXiv](https://arxiv.org/abs/2403.17377) / [GitHub](https://github.com/KU-CVLAB/Perturbed-Attention-Guidance)
|
| 15 |
+
|
| 16 |
+
This repository is based on [Diffusers](https://huggingface.co/docs/diffusers/index). The pipeline is a modification of StableDiffusionPipeline to support inpainting with Perturbed-Attention Guidance (PAG).
|
| 17 |
+
|
| 18 |
+
## Quickstart
|
| 19 |
+
|
| 20 |
+
Loading Custom Piepline:
|
| 21 |
+
|
| 22 |
+
```
|
| 23 |
+
from diffusers import StableDiffusionPipeline
|
| 24 |
+
|
| 25 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 26 |
+
"runwayml/stable-diffusion-inpainting",
|
| 27 |
+
custom_pipeline="hyoungwoncho/sd_perturbed_attention_guidance_inpaint",
|
| 28 |
+
torch_dtype=torch.float16,
|
| 29 |
+
safety_checker=None
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
device="cuda"
|
| 33 |
+
pipe = pipe.to(device)
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
Inpainting with PAG:
|
| 37 |
+
|
| 38 |
+
```
|
| 39 |
+
output = pipe(
|
| 40 |
+
prompts,
|
| 41 |
+
image=init_image,
|
| 42 |
+
mask_image=mask_image,
|
| 43 |
+
num_inference_steps=50,
|
| 44 |
+
guidance_scale=0.0,
|
| 45 |
+
pag_scale=5.0,
|
| 46 |
+
pag_applied_layers_index=['m0']
|
| 47 |
+
).images[0]
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
## Parameters
|
| 51 |
+
|
| 52 |
+
guidance_scale : gudiance scale of CFG (ex: 7.5)
|
| 53 |
+
|
| 54 |
+
pag_scale : gudiance scale of PAG (ex: 5.0)
|
| 55 |
+
|
| 56 |
+
pag_applied_layers_index : index of the layer to apply perturbation (ex: ['m0'])
|