h1t
/

Text-to-Image
Diffusers
lora
h1t commited on
Commit
80cd908
1 Parent(s): 9606b47

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +68 -17
README.md CHANGED
@@ -13,7 +13,7 @@ inference: false
13
  Official Model Repo of the paper: [Trajectory Consistency Distillation](https://arxiv.org/abs/2402.19159).
14
  For more information, please check the [GitHub Repo](https://github.com/jabir-zheng/TCD) and [Project Page](https://mhh0318.github.io/tcd/).
15
 
16
- Also welcome to try the demo host on [🤗 Space(https://huggingface.co/spaces/h1t/TCD)].
17
 
18
  ![](./assets/teaser_fig.png)
19
 
@@ -48,7 +48,7 @@ And then we clone the repo.
48
  git clone https://github.com/jabir-zheng/TCD.git
49
  cd TCD
50
  ```
51
- Here, we demonstrate the applicability of our TCD LoRA to various models, including [SDXL](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0), [SDXL Inpainting](https://huggingface.co/diffusers/stable-diffusion-xl-1.0-inpainting-0.1), a community model named [Animagine XL](https://huggingface.co/cagliostrolab/animagine-xl-3.0), a styled LoRA [Papercut](https://huggingface.co/TheLastBen/Papercut_SDXL), pretrained [Depth Controlnet](https://huggingface.co/diffusers/controlnet-depth-sdxl-1.0), and [IP-Adapter](https://github.com/tencent-ailab/IP-Adapter) to accelerate image generation with high quality in 4-8 steps.
52
 
53
  ### Text-to-Image generation
54
  ```py
@@ -58,7 +58,7 @@ from scheduling_tcd import TCDScheduler
58
 
59
  device = "cuda"
60
  base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
61
- tcd_lora_id = ""
62
 
63
  pipe = StableDiffusionXLPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16, variant="fp16").to(device)
64
  pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
@@ -79,7 +79,7 @@ image = pipe(
79
  generator=torch.Generator(device=device).manual_seed(0),
80
  ).images[0]
81
  ```
82
- ![](./assets/t2i_sdxl.png)
83
 
84
  ### Inpainting
85
  ```py
@@ -90,7 +90,7 @@ from scheduling_tcd import TCDScheduler
90
 
91
  device = "cuda"
92
  base_model_id = "diffusers/stable-diffusion-xl-1.0-inpainting-0.1"
93
- tcd_lora_id = ""
94
 
95
  pipe = AutoPipelineForInpainting.from_pretrained(base_model_id, torch_dtype=torch.float16, variant="fp16").to(device)
96
  pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
@@ -119,7 +119,7 @@ image = pipe(
119
 
120
  grid_image = make_image_grid([init_image, mask_image, image], rows=1, cols=3)
121
  ```
122
- ![](./assets/inpainting_sdxl.png)
123
 
124
  ### Versatile for Community Models
125
  ```py
@@ -129,7 +129,7 @@ from scheduling_tcd import TCDScheduler
129
 
130
  device = "cuda"
131
  base_model_id = "cagliostrolab/animagine-xl-3.0"
132
- tcd_lora_id = ""
133
 
134
  pipe = StableDiffusionXLPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16, variant="fp16").to(device)
135
  pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
@@ -160,7 +160,7 @@ from scheduling_tcd import TCDScheduler
160
 
161
  device = "cuda"
162
  base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
163
- tcd_lora_id = ""
164
  styled_lora_id = "TheLastBen/Papercut_SDXL"
165
 
166
  pipe = StableDiffusionXLPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16, variant="fp16").to(device)
@@ -186,6 +186,7 @@ image = pipe(
186
  ![](./assets/styled_lora.png)
187
 
188
  ### Compatibility with ControlNet
 
189
  ```py
190
  import torch
191
  import numpy as np
@@ -220,8 +221,8 @@ def get_depth_map(image):
220
  return image
221
 
222
  base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
223
- controlnet_id = "/mnt/CV_teamz/pretrained/controlnet-depth-sdxl-1.0"
224
- tcd_lora_id = ""
225
 
226
  controlnet = ControlNetModel.from_pretrained(
227
  controlnet_id,
@@ -260,15 +261,65 @@ image = pipe(
260
 
261
  grid_image = make_image_grid([depth_image, image], rows=1, cols=2)
262
  ```
263
- ![](./assets/controlnet_depth_sdxl.png)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
 
265
  ### Compatibility with IP-Adapter
266
- Please refer to the official [repository](https://github.com/tencent-ailab/IP-Adapter/tree/main) for instructions on installing dependencies for IP-Adapter.
267
  ```py
268
  import torch
269
- from PIL import Image
270
  from diffusers import StableDiffusionXLPipeline
271
- from diffusers.utils import make_image_grid
272
 
273
  from ip_adapter import IPAdapterXL
274
  from scheduling_tcd import TCDScheduler
@@ -277,7 +328,7 @@ device = "cuda"
277
  base_model_path = "stabilityai/stable-diffusion-xl-base-1.0"
278
  image_encoder_path = "sdxl_models/image_encoder"
279
  ip_ckpt = "sdxl_models/ip-adapter_sdxl.bin"
280
- tcd_lora_id = ""
281
 
282
  pipe = StableDiffusionXLPipeline.from_pretrained(
283
  base_model_path,
@@ -291,8 +342,7 @@ pipe.fuse_lora()
291
 
292
  ip_model = IPAdapterXL(pipe, image_encoder_path, ip_ckpt, device)
293
 
294
- ref_image = Image.open(f"assets/images/woman.png")
295
- ref_image.resize((512, 512))
296
 
297
  prompt = "best quality, high quality, wearing sunglasses"
298
 
@@ -311,6 +361,7 @@ grid_image = make_image_grid([ref_image, image], rows=1, cols=2)
311
  ```
312
  ![](./assets/ip_adapter.png)
313
 
 
314
  ## Citation
315
  ```bibtex
316
  @misc{zheng2024trajectory,
 
13
  Official Model Repo of the paper: [Trajectory Consistency Distillation](https://arxiv.org/abs/2402.19159).
14
  For more information, please check the [GitHub Repo](https://github.com/jabir-zheng/TCD) and [Project Page](https://mhh0318.github.io/tcd/).
15
 
16
+ Also welcome to try the demo host on [🤗 Space](https://huggingface.co/spaces/h1t/TCD).
17
 
18
  ![](./assets/teaser_fig.png)
19
 
 
48
  git clone https://github.com/jabir-zheng/TCD.git
49
  cd TCD
50
  ```
51
+ Here, we demonstrate the applicability of our TCD LoRA to various models, including [SDXL](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0), [SDXL Inpainting](https://huggingface.co/diffusers/stable-diffusion-xl-1.0-inpainting-0.1), a community model named [Animagine XL](https://huggingface.co/cagliostrolab/animagine-xl-3.0), a styled LoRA [Papercut](https://huggingface.co/TheLastBen/Papercut_SDXL), pretrained [Depth Controlnet](https://huggingface.co/diffusers/controlnet-depth-sdxl-1.0), [Canny Controlnet](https://huggingface.co/diffusers/controlnet-canny-sdxl-1.0) and [IP-Adapter](https://github.com/tencent-ailab/IP-Adapter) to accelerate image generation with high quality in few steps.
52
 
53
  ### Text-to-Image generation
54
  ```py
 
58
 
59
  device = "cuda"
60
  base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
61
+ tcd_lora_id = "h1t/TCD-SDXL-LoRA"
62
 
63
  pipe = StableDiffusionXLPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16, variant="fp16").to(device)
64
  pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
 
79
  generator=torch.Generator(device=device).manual_seed(0),
80
  ).images[0]
81
  ```
82
+ ![](./assets/t2i_tcd.png)
83
 
84
  ### Inpainting
85
  ```py
 
90
 
91
  device = "cuda"
92
  base_model_id = "diffusers/stable-diffusion-xl-1.0-inpainting-0.1"
93
+ tcd_lora_id = "h1t/TCD-SDXL-LoRA"
94
 
95
  pipe = AutoPipelineForInpainting.from_pretrained(base_model_id, torch_dtype=torch.float16, variant="fp16").to(device)
96
  pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
 
119
 
120
  grid_image = make_image_grid([init_image, mask_image, image], rows=1, cols=3)
121
  ```
122
+ ![](./assets/inpainting_tcd.png)
123
 
124
  ### Versatile for Community Models
125
  ```py
 
129
 
130
  device = "cuda"
131
  base_model_id = "cagliostrolab/animagine-xl-3.0"
132
+ tcd_lora_id = "h1t/TCD-SDXL-LoRA"
133
 
134
  pipe = StableDiffusionXLPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16, variant="fp16").to(device)
135
  pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
 
160
 
161
  device = "cuda"
162
  base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
163
+ tcd_lora_id = "h1t/TCD-SDXL-LoRA"
164
  styled_lora_id = "TheLastBen/Papercut_SDXL"
165
 
166
  pipe = StableDiffusionXLPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16, variant="fp16").to(device)
 
186
  ![](./assets/styled_lora.png)
187
 
188
  ### Compatibility with ControlNet
189
+ #### Depth ControlNet
190
  ```py
191
  import torch
192
  import numpy as np
 
221
  return image
222
 
223
  base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
224
+ controlnet_id = "diffusers/controlnet-depth-sdxl-1.0"
225
+ tcd_lora_id = "h1t/TCD-SDXL-LoRA"
226
 
227
  controlnet = ControlNetModel.from_pretrained(
228
  controlnet_id,
 
261
 
262
  grid_image = make_image_grid([depth_image, image], rows=1, cols=2)
263
  ```
264
+ ![](./assets/controlnet_depth_tcd.png)
265
+
266
+ #### Canny ControlNet
267
+ ```py
268
+ import torch
269
+ from diffusers import ControlNetModel, StableDiffusionXLControlNetPipeline
270
+ from diffusers.utils import load_image, make_image_grid
271
+ from scheduling_tcd import TCDScheduler
272
+
273
+ device = "cuda"
274
+ base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
275
+ controlnet_id = "diffusers/controlnet-canny-sdxl-1.0"
276
+ tcd_lora_id = "h1t/TCD-SDXL-LoRA"
277
+
278
+ controlnet = ControlNetModel.from_pretrained(
279
+ controlnet_id,
280
+ torch_dtype=torch.float16,
281
+ variant="fp16",
282
+ ).to(device)
283
+ pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
284
+ base_model_id,
285
+ controlnet=controlnet,
286
+ torch_dtype=torch.float16,
287
+ variant="fp16",
288
+ ).to(device)
289
+ pipe.enable_model_cpu_offload()
290
+
291
+ pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
292
+
293
+ pipe.load_lora_weights(tcd_lora_id)
294
+ pipe.fuse_lora()
295
+
296
+ prompt = "ultrarealistic shot of a furry blue bird"
297
+
298
+ canny_image = load_image("https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/bird_canny.png")
299
+
300
+ controlnet_conditioning_scale = 0.5 # recommended for good generalization
301
+
302
+ image = pipe(
303
+ prompt,
304
+ image=canny_image,
305
+ num_inference_steps=4,
306
+ guidance_scale=0,
307
+ eta=0.3, # A parameter (referred to as `gamma` in the paper) is used to control the stochasticity in every step. A value of 0.3 often yields good results.
308
+ controlnet_conditioning_scale=controlnet_conditioning_scale,
309
+ generator=torch.Generator(device=device).manual_seed(0),
310
+ ).images[0]
311
+
312
+ grid_image = make_image_grid([canny_image, image], rows=1, cols=2)
313
+ ```
314
+
315
+ ![](./assets/controlnet_canny_tcd.png)
316
 
317
  ### Compatibility with IP-Adapter
318
+ ⚠️ Please refer to the official [repository](https://github.com/tencent-ailab/IP-Adapter/tree/main) for instructions on installing dependencies for IP-Adapter.
319
  ```py
320
  import torch
 
321
  from diffusers import StableDiffusionXLPipeline
322
+ from diffusers.utils import load_image, make_image_grid
323
 
324
  from ip_adapter import IPAdapterXL
325
  from scheduling_tcd import TCDScheduler
 
328
  base_model_path = "stabilityai/stable-diffusion-xl-base-1.0"
329
  image_encoder_path = "sdxl_models/image_encoder"
330
  ip_ckpt = "sdxl_models/ip-adapter_sdxl.bin"
331
+ tcd_lora_id = "h1t/TCD-SDXL-LoRA"
332
 
333
  pipe = StableDiffusionXLPipeline.from_pretrained(
334
  base_model_path,
 
342
 
343
  ip_model = IPAdapterXL(pipe, image_encoder_path, ip_ckpt, device)
344
 
345
+ ref_image = load_image("https://raw.githubusercontent.com/tencent-ailab/IP-Adapter/main/assets/images/woman.png").resize((512, 512))
 
346
 
347
  prompt = "best quality, high quality, wearing sunglasses"
348
 
 
361
  ```
362
  ![](./assets/ip_adapter.png)
363
 
364
+
365
  ## Citation
366
  ```bibtex
367
  @misc{zheng2024trajectory,