Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,73 @@
|
|
1 |
-
---
|
2 |
-
license:
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license:
|
3 |
+
- apache-2.0
|
4 |
+
language:
|
5 |
+
- en
|
6 |
+
tags:
|
7 |
+
- Diffusion Models
|
8 |
+
- Stable Diffusion
|
9 |
+
- Perturbed-Attention Guidance
|
10 |
+
- PAG
|
11 |
+
---
|
12 |
+
# Perturbed-Attention Guidance for SD 1.5 (i2i)
|
13 |
+
|
14 |
+
The original Perturbed-Attention Guidance for unconditional models and SD1.5 by [Hyoungwon Cho](https://huggingface.co/hyoungwoncho) is availiable at [hyoungwoncho/sd_perturbed_attention_guidance](https://huggingface.co/hyoungwoncho/sd_perturbed_attention_guidance)
|
15 |
+
|
16 |
+
[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)
|
17 |
+
|
18 |
+
This repository is just a simple implementation of the Perturbed-Attention Guidance (PAG) on Stable Diffusion 1.5 (SD 1.5) for the 🧨 diffusers library to "image-to-image".
|
19 |
+
|
20 |
+
|
21 |
+
## Quickstart
|
22 |
+
|
23 |
+
Loading Custom Pipeline:
|
24 |
+
|
25 |
+
```py
|
26 |
+
from diffusers import StableDiffusionImg2ImgPipeline
|
27 |
+
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
28 |
+
"runwayml/stable-diffusion-v1-5",
|
29 |
+
custom_pipeline="jyoung105/sd15_perturbed_attention_guidance_i2i",
|
30 |
+
torch_dtype=torch.float16
|
31 |
+
)
|
32 |
+
device="cuda"
|
33 |
+
pipe = pipe.to(device)
|
34 |
+
```
|
35 |
+
|
36 |
+
Unconditional sampling with PAG:
|
37 |
+
![image/jpeg](example_1.jpg)
|
38 |
+
|
39 |
+
```py
|
40 |
+
output = pipe(
|
41 |
+
"",
|
42 |
+
image=init_image,
|
43 |
+
strength=0.6,
|
44 |
+
num_inference_steps=50,
|
45 |
+
guidance_scale=0.0,
|
46 |
+
pag_scale=5.0,
|
47 |
+
pag_applied_layers_index=['m0']
|
48 |
+
).images
|
49 |
+
```
|
50 |
+
|
51 |
+
Sampling with PAG and CFG:
|
52 |
+
![image/jpeg](example_2.jpg)
|
53 |
+
```py
|
54 |
+
output = pipe(
|
55 |
+
"A man with hoodie on is looking at sky, photo",
|
56 |
+
image=init_image,
|
57 |
+
strength=0.6,
|
58 |
+
num_inference_steps=50,
|
59 |
+
guidance_scale=0.0,
|
60 |
+
pag_scale=5.0,
|
61 |
+
pag_applied_layers_index=['m0']
|
62 |
+
).images
|
63 |
+
```
|
64 |
+
|
65 |
+
## Parameters
|
66 |
+
|
67 |
+
`guidance_scale` : guidance scale of CFG (ex: `7.5`)
|
68 |
+
|
69 |
+
`pag_scale` : guidance scale of PAG (ex: `4.0`)
|
70 |
+
|
71 |
+
`pag_applied_layers`: layer to apply perturbation (ex: ['mid'])
|
72 |
+
|
73 |
+
`pag_applied_layers_index` : index of the layers to apply perturbation (ex: ['m0', 'm1'])
|