|
--- |
|
language: |
|
- en |
|
pipeline_tag: image-to-image |
|
tags: |
|
- Diffusion Models |
|
- Stable Diffusion |
|
- Perturbed-Attention Guidance |
|
- PAG |
|
--- |
|
|
|
# Super-Resolution with Perturbed-Attention Guidance |
|
|
|
[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) |
|
|
|
This repository is based on [Diffusers](https://huggingface.co/docs/diffusers/index). |
|
|
|
The pipeline is a modification of StableDiffusionPipeline to support super-resolution with Perturbed-Attention Guidance (PAG). Please refer to "Image-to-upscaler-to-super-resolution" section of an [official document](https://huggingface.co/docs/diffusers/using-diffusers/img2img) for details. |
|
|
|
## Quickstart |
|
|
|
Loading Custom Piepline: |
|
|
|
``` |
|
from diffusers import StableDiffusionPipeline |
|
|
|
pipe = StableDiffusionPipeline.from_pretrained( |
|
"stabilityai/stable-diffusion-x4-upscaler", |
|
custom_pipeline="hyoungwoncho/sd_perturbed_attention_guidance_sr", |
|
torch_dtype=torch.float16, |
|
safety_checker=None |
|
) |
|
|
|
device="cuda" |
|
pipe = pipe.to(device) |
|
``` |
|
|
|
Super-Resolution with PAG: |
|
|
|
``` |
|
output = pipe( |
|
prompts, |
|
image=lr_image, |
|
num_inference_steps=50, |
|
guidance_scale=0.0, |
|
pag_scale=2.0, |
|
pag_applied_layers_index=['u2'] |
|
).images[0] |
|
``` |
|
|
|
## Parameters |
|
|
|
guidance_scale : gudiance scale of CFG (ex: 7.5) |
|
|
|
pag_scale : gudiance scale of PAG (ex: 2.0) |
|
|
|
pag_applied_layers_index : index of the layer to apply perturbation (ex: ['u2']) |