Image-to-Image
Diffusers
English
JOY-Huang commited on
Commit
f44c3cc
1 Parent(s): 47fa009

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +13 -27
README.md CHANGED
@@ -9,8 +9,8 @@ pipeline_tag: image-to-image
9
  # InstantIR Model Card
10
  <div style="display: flex; gap: 10px; align-items: center; justify-content: center; height: auto;">
11
  <a href='https://arxiv.org/abs/2410.06551'><img src='https://img.shields.io/badge/paper-arXiv-b31b1b.svg' style="height: 24px;"></a>
12
- <a href='https://jy-joy.github.io/InstantIR'><img src='https://img.shields.io/badge/project-Website-informational' style="height: 24px;"></a>
13
- <a href='https://github.com/JY-Joy/InstantIR'><img src='https://img.shields.io/badge/code-Github-gray' style="height: 24px;"></a>
14
  </div>
15
 
16
  > **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!
@@ -46,55 +46,41 @@ hf_hub_download(repo_id="InstantX/InstantIR", filename="models/previewer_lora_we
46
  import torch
47
  from PIL import Image
48
 
49
- from diffusers import DDPMScheduler, StableDiffusionXLPipeline
50
  from schedulers.lcm_single_step_scheduler import LCMSingleStepScheduler
51
 
52
  from transformers import AutoImageProcessor, AutoModel
53
 
54
- from module.ip_adapter.utils import init_adapter_in_unet
55
- from module.ip_adapter.resampler import Resampler
56
  from pipelines.sdxl_instantir import InstantIRPipeline
57
 
58
- # prepare 'dinov2'
59
- image_encoder = AutoModel.from_pretrained('facebook/dinov2-large')
60
- image_processor = AutoImageProcessor.from_pretrained('facebook/dinov2-large')
61
-
62
  # prepare models under ./checkpoints
63
  dcp_adapter = f'./models/adapter.pt'
64
  previewer_lora_path = f'./models'
65
  instantir_path = f'./models/aggregator.pt'
66
 
67
- # load SDXL
68
- sdxl = StableDiffusionXLPipeline.from_pretrained('stabilityai/stable-diffusion-xl-base-1.0', torch_dtype=torch.float16)
69
-
70
- # InstantIR pipeline
71
- pipe = InstantIRPipeline(
72
- sdxl.vae, sdxl.text_encoder, sdxl.text_encoder_2, sdxl.tokenizer, sdxl.tokenizer_2,
73
- sdxl.unet, sdxl.scheduler, feature_extractor=image_processor, image_encoder=image_encoder,
74
- )
75
 
76
  # load adapter
77
- image_proj_model = Resampler(
78
- embedding_dim=image_encoder.config.hidden_size,
79
- output_dim=sdxl.unet.config.cross_attention_dim,
80
- )
81
- init_adapter_in_unet(
82
- pipe.unet,
83
- image_proj_model,
84
  dcp_adapter,
 
85
  )
86
 
87
  # load previewer lora
88
  pipe.prepare_previewers(previewer_lora_path)
89
  pipe.scheduler = DDPMScheduler.from_pretrained('stabilityai/stable-diffusion-xl-base-1.0', subfolder="scheduler")
90
  lcm_scheduler = LCMSingleStepScheduler.from_config(pipe.scheduler.config)
91
- pipe.unet.to(dtype=torch.float16)
92
- pipe.to('cuda')
93
 
94
  # load aggregator weights
95
  pretrained_state_dict = torch.load(instantir_path)
96
  pipe.aggregator.load_state_dict(pretrained_state_dict)
97
- pipe.aggregator.to(dtype=torch.float16, device=pipe.unet.device)
 
 
 
98
  ```
99
 
100
  Then, you can restore your broken images with:
 
9
  # InstantIR Model Card
10
  <div style="display: flex; gap: 10px; align-items: center; justify-content: center; height: auto;">
11
  <a href='https://arxiv.org/abs/2410.06551'><img src='https://img.shields.io/badge/paper-arXiv-b31b1b.svg' style="height: 24px;"></a>
12
+ <a href='https://jy-joy.github.io/InstantIR'><img src='https://img.shields.io/badge/project-Website-green' style="height: 24px;"></a>
13
+ <a href='https://github.com/JY-Joy/InstantIR'><img src='https://img.shields.io/badge/code-Github-informational' style="height: 24px;"></a>
14
  </div>
15
 
16
  > **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!
 
46
  import torch
47
  from PIL import Image
48
 
49
+ from diffusers import DDPMScheduler
50
  from schedulers.lcm_single_step_scheduler import LCMSingleStepScheduler
51
 
52
  from transformers import AutoImageProcessor, AutoModel
53
 
54
+ from module.ip_adapter.utils import load_adapter_to_pipe
 
55
  from pipelines.sdxl_instantir import InstantIRPipeline
56
 
 
 
 
 
57
  # prepare models under ./checkpoints
58
  dcp_adapter = f'./models/adapter.pt'
59
  previewer_lora_path = f'./models'
60
  instantir_path = f'./models/aggregator.pt'
61
 
62
+ # load pretrained models
63
+ pipe = InstantIRPipeline.from_pretrained('stabilityai/stable-diffusion-xl-base-1.0', torch_dtype=torch.float16)
 
 
 
 
 
 
64
 
65
  # load adapter
66
+ load_adapter_to_pipe(
67
+ pipe,
 
 
 
 
 
68
  dcp_adapter,
69
+ image_encoder_or_path = 'facebook/dinov2-large',
70
  )
71
 
72
  # load previewer lora
73
  pipe.prepare_previewers(previewer_lora_path)
74
  pipe.scheduler = DDPMScheduler.from_pretrained('stabilityai/stable-diffusion-xl-base-1.0', subfolder="scheduler")
75
  lcm_scheduler = LCMSingleStepScheduler.from_config(pipe.scheduler.config)
 
 
76
 
77
  # load aggregator weights
78
  pretrained_state_dict = torch.load(instantir_path)
79
  pipe.aggregator.load_state_dict(pretrained_state_dict)
80
+
81
+ # send to GPU and fp16
82
+ pipe.to(dtype=torch.float16)
83
+ pipe.to('cuda')
84
  ```
85
 
86
  Then, you can restore your broken images with: