Update README.md
Browse files
README.md
CHANGED
@@ -86,6 +86,54 @@ prompt="a photo of a cat"
|
|
86 |
image=pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0, timesteps=[399]).images[0]
|
87 |
```
|
88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
For more information, please refer to the [code repository](https://github.com/tianweiy/DMD2)
|
90 |
|
91 |
|
|
|
86 |
image=pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0, timesteps=[399]).images[0]
|
87 |
```
|
88 |
|
89 |
+
#### 4-step T2I Adapter
|
90 |
+
|
91 |
+
```python
|
92 |
+
from diffusers import StableDiffusionXLAdapterPipeline, T2IAdapter, AutoencoderKL, UNet2DConditionModel, LCMScheduler
|
93 |
+
from diffusers.utils import load_image, make_image_grid
|
94 |
+
from controlnet_aux.canny import CannyDetector
|
95 |
+
from huggingface_hub import hf_hub_download
|
96 |
+
import torch
|
97 |
+
|
98 |
+
# load adapter
|
99 |
+
adapter = T2IAdapter.from_pretrained("TencentARC/t2i-adapter-canny-sdxl-1.0", torch_dtype=torch.float16, varient="fp16").to("cuda")
|
100 |
+
|
101 |
+
vae=AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
102 |
+
|
103 |
+
base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
|
104 |
+
repo_name = "tianweiy/DMD2"
|
105 |
+
ckpt_name = "dmd2_sdxl_4step_unet_fp16.bin"
|
106 |
+
# Load model.
|
107 |
+
unet = UNet2DConditionModel.from_config(base_model_id, subfolder="unet").to("cuda", torch.float16)
|
108 |
+
unet.load_state_dict(torch.load(hf_hub_download(repo_name, ckpt_name), map_location="cuda"))
|
109 |
+
|
110 |
+
pipe = StableDiffusionXLAdapterPipeline.from_pretrained(
|
111 |
+
base_model_id, unet=unet, vae=vae, adapter=adapter, torch_dtype=torch.float16, variant="fp16",
|
112 |
+
).to("cuda")
|
113 |
+
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
|
114 |
+
pipe.enable_xformers_memory_efficient_attention()
|
115 |
+
|
116 |
+
canny_detector = CannyDetector()
|
117 |
+
|
118 |
+
url = "https://huggingface.co/Adapter/t2iadapter/resolve/main/figs_SDXLV1.0/org_canny.jpg"
|
119 |
+
image = load_image(url)
|
120 |
+
|
121 |
+
# Detect the canny map in low resolution to avoid high-frequency details
|
122 |
+
image = canny_detector(image, detect_resolution=384, image_resolution=1024)#.resize((1024, 1024))
|
123 |
+
|
124 |
+
prompt = "Mystical fairy in real, magic, 4k picture, high quality"
|
125 |
+
|
126 |
+
gen_images = pipe(
|
127 |
+
prompt=prompt,
|
128 |
+
image=image,
|
129 |
+
num_inference_steps=4,
|
130 |
+
guidance_scale=0,
|
131 |
+
adapter_conditioning_scale=0.8,
|
132 |
+
adapter_conditioning_factor=0.5
|
133 |
+
).images[0]
|
134 |
+
gen_images.save('out_canny.png')
|
135 |
+
```
|
136 |
+
|
137 |
For more information, please refer to the [code repository](https://github.com/tianweiy/DMD2)
|
138 |
|
139 |
|