add IP-Adapter-FaceID-SDXL demo
Browse files
README.md
CHANGED
@@ -124,6 +124,70 @@ images = ip_model.generate(
|
|
124 |
|
125 |
```
|
126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
### IP-Adapter-FaceID-Plus
|
128 |
|
129 |
Firstly, you should use [insightface](https://github.com/deepinsight/insightface) to extract face ID embedding and face image:
|
|
|
124 |
|
125 |
```
|
126 |
|
127 |
+
### IP-Adapter-FaceID-SDXL
|
128 |
+
|
129 |
+
Firstly, you should use [insightface](https://github.com/deepinsight/insightface) to extract face ID embedding:
|
130 |
+
|
131 |
+
```python
|
132 |
+
|
133 |
+
import cv2
|
134 |
+
from insightface.app import FaceAnalysis
|
135 |
+
import torch
|
136 |
+
|
137 |
+
app = FaceAnalysis(name="buffalo_l", providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
|
138 |
+
app.prepare(ctx_id=0, det_size=(640, 640))
|
139 |
+
|
140 |
+
image = cv2.imread("person.jpg")
|
141 |
+
faces = app.get(image)
|
142 |
+
|
143 |
+
faceid_embeds = torch.from_numpy(faces[0].normed_embedding).unsqueeze(0)
|
144 |
+
```
|
145 |
+
|
146 |
+
Then, you can generate images conditioned on the face embeddings:
|
147 |
+
|
148 |
+
```python
|
149 |
+
|
150 |
+
import torch
|
151 |
+
from diffusers import StableDiffusionXLPipeline, DDIMScheduler
|
152 |
+
from PIL import Image
|
153 |
+
|
154 |
+
from ip_adapter.ip_adapter_faceid import IPAdapterFaceIDXL
|
155 |
+
|
156 |
+
base_model_path = "/dockerdata/models/RealVisXL_V3.0/"
|
157 |
+
ip_ckpt = "ip-adapter-faceid_sdxl.bin"
|
158 |
+
device = "cuda"
|
159 |
+
|
160 |
+
noise_scheduler = DDIMScheduler(
|
161 |
+
num_train_timesteps=1000,
|
162 |
+
beta_start=0.00085,
|
163 |
+
beta_end=0.012,
|
164 |
+
beta_schedule="scaled_linear",
|
165 |
+
clip_sample=False,
|
166 |
+
set_alpha_to_one=False,
|
167 |
+
steps_offset=1,
|
168 |
+
)
|
169 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(
|
170 |
+
base_model_path,
|
171 |
+
torch_dtype=torch.float16,
|
172 |
+
scheduler=noise_scheduler,
|
173 |
+
add_watermarker=False,
|
174 |
+
)
|
175 |
+
|
176 |
+
# load ip-adapter
|
177 |
+
ip_model = IPAdapterFaceIDXL(pipe, ip_ckpt, device)
|
178 |
+
|
179 |
+
# generate image
|
180 |
+
prompt = "A closeup shot of a beautiful Asian teenage girl in a white dress wearing small silver earrings in the garden, under the soft morning light"
|
181 |
+
negative_prompt = "monochrome, lowres, bad anatomy, worst quality, low quality, blurry"
|
182 |
+
|
183 |
+
images = ip_model.generate(
|
184 |
+
prompt=prompt, negative_prompt=negative_prompt, faceid_embeds=faceid_embeds, num_samples=2,
|
185 |
+
width=1024, height=1024,
|
186 |
+
num_inference_steps=30, guidance_scale=7.5, seed=2023
|
187 |
+
)
|
188 |
+
|
189 |
+
```
|
190 |
+
|
191 |
### IP-Adapter-FaceID-Plus
|
192 |
|
193 |
Firstly, you should use [insightface](https://github.com/deepinsight/insightface) to extract face ID embedding and face image:
|