File size: 4,729 Bytes
48f7d41 c4a9e2a ddc2ff1 f44c3cc 3f9a631 35af95f 48f7d41 47fa009 48f7d41 bf2fe16 48f7d41 f44c3cc 48f7d41 f44c3cc 48f7d41 360cb75 48f7d41 f44c3cc f793f9c 48f7d41 f44c3cc 360cb75 f44c3cc 48f7d41 360cb75 48f7d41 360cb75 48f7d41 f44c3cc c1056fa 48f7d41 6998fa2 48f7d41 6998fa2 48f7d41 fdbafd0 48f7d41 1a8e796 48f7d41 1a8e796 48f7d41 04f6fe0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
---
license: apache-2.0
language:
- en
library_name: diffusers
pipeline_tag: image-to-image
---
# InstantIR Model Card
<div style="display: flex; gap: 10px; align-items: center; justify-content: center; height: auto;">
<a href='https://arxiv.org/abs/2410.06551'><img src='https://img.shields.io/badge/paper-arXiv-b31b1b.svg' style="height: 24px;"></a>
<a href='https://jy-joy.github.io/InstantIR'><img src='https://img.shields.io/badge/project-Website-green' style="height: 24px;"></a>
<a href='https://github.com/instantX-research/InstantIR'><img src='https://img.shields.io/badge/code-Github-informational' style="height: 24px;"></a>
</div>
> **InstantIR** is a novel single-image restoration model designed to resurrect your damaged images, delivering extrem-quality yet realistic details. You can further boost **InstantIR** performance with additional text prompts, even achieve customized editing!
<div align="center">
<img src='assets/teaser_figure.png'>
</div>
## Usage
### 1. Clone the github repo
```sh
git clone https://github.com/JY-Joy/InstantIR.git
cd InstantIR
```
### 2. Download model weights
You can directly download InstantIR weights in this repository, or
you can download them using python script:
```python
from huggingface_hub import hf_hub_download
hf_hub_download(repo_id="InstantX/InstantIR", filename="models/adapter.pt", local_dir=".")
hf_hub_download(repo_id="InstantX/InstantIR", filename="models/aggregator.pt", local_dir=".")
hf_hub_download(repo_id="InstantX/InstantIR", filename="models/previewer_lora_weights.bin", local_dir=".")
```
### 3. Load InstantIR with 🧨 diffusers
```python
# !pip install diffusers opencv-python transformers accelerate
import torch
from PIL import Image
from diffusers import DDPMScheduler
from schedulers.lcm_single_step_scheduler import LCMSingleStepScheduler
from module.ip_adapter.utils import load_adapter_to_pipe
from pipelines.sdxl_instantir import InstantIRPipeline
# prepare models under ./models
instantir_path = f'./models'
# load pretrained models
pipe = InstantIRPipeline.from_pretrained('stabilityai/stable-diffusion-xl-base-1.0', torch_dtype=torch.float16)
# load adapter
load_adapter_to_pipe(
pipe,
f"{instantir_path}/adapter.pt",
image_encoder_or_path = 'facebook/dinov2-large',
)
# load previewer lora
pipe.prepare_previewers(instantir_path)
pipe.scheduler = DDPMScheduler.from_pretrained('stabilityai/stable-diffusion-xl-base-1.0', subfolder="scheduler")
lcm_scheduler = LCMSingleStepScheduler.from_config(pipe.scheduler.config)
# load aggregator weights
pretrained_state_dict = torch.load(f"{instantir_path}/aggregator.pt")
pipe.aggregator.load_state_dict(pretrained_state_dict)
# send to GPU and fp16
pipe.to(device='cuda', dtype=torch.float16)
pipe.aggregator.to(device='cuda', dtype=torch.float16)
```
Then, you can restore your broken images with:
```python
# load a broken image
low_quality_image = Image.open('path/to/your-image').convert("RGB")
# InstantIR restoration
image = pipe(
image=low_quality_image,
previewer_scheduler=lcm_scheduler,
).images[0]
```
For more details including text-guided enhancement/editing, please refer to our [GitHub repository](https://github.com/JY-Joy/InstantIR).
<!-- ## Usage Tips
1. If you're not satisfied with the similarity, try to increase the weight of "IdentityNet Strength" and "Adapter Strength".
2. If you feel that the saturation is too high, first decrease the Adapter strength. If it is still too high, then decrease the IdentityNet strength.
3. If you find that text control is not as expected, decrease Adapter strength.
4. If you find that realistic style is not good enough, go for our Github repo and use a more realistic base model. -->
## Examples
<div align="center">
<img src='assets/qualitative_real.png'>
</div>
<div align="center">
<img src='assets/outdomain_preview.png'>
</div>
## Disclaimer
This project is released under Apache License and aims to positively impact the field of AI-driven image generation. Users are granted the freedom to create images using this tool, but they are obligated to comply with local laws and utilize it responsibly. The developers will not assume any responsibility for potential misuse by users.
## Acknowledgment
Our work is sponsored by [HuggingFace](https://huggingface.co) and [fal.ai](https://fal.ai).
## Citation
If InstantIR helps your research or project, please cite us via
```bibtex
@article{huang2024instantir,
title={InstantIR: Blind Image Restoration with Instant Generative Reference},
author={Huang, Jen-Yuan and Wang, Haofan and Wang, Qixun and Bai, Xu and Ai, Hao and Xing, Peng and Huang, Jen-Tse},
journal={arXiv preprint arXiv:2410.06551},
year={2024}
}
``` |