ziffir commited on
Commit
1b675f3
1 Parent(s): 5f6754f

Upload 12 files

Browse files
README.md ADDED
@@ -0,0 +1,271 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - text-to-image
4
+ - stable-diffusion
5
+
6
+ language:
7
+ - en
8
+ library_name: diffusers
9
+ ---
10
+
11
+ # IP-Adapter-FaceID Model Card
12
+
13
+
14
+ <div align="center">
15
+
16
+ [**Project Page**](https://ip-adapter.github.io) **|** [**Paper (ArXiv)**](https://arxiv.org/abs/2308.06721) **|** [**Code**](https://github.com/tencent-ailab/IP-Adapter)
17
+ </div>
18
+
19
+ ---
20
+
21
+
22
+
23
+ ## Introduction
24
+
25
+ An experimental version of IP-Adapter-FaceID: we use face ID embedding from a face recognition model instead of CLIP image embedding, additionally, we use LoRA to improve ID consistency. IP-Adapter-FaceID can generate various style images conditioned on a face with only text prompts.
26
+
27
+ ![results](./ip-adapter-faceid.jpg)
28
+
29
+
30
+ **Update 2023/12/27**:
31
+
32
+ IP-Adapter-FaceID-Plus: face ID embedding (for face ID) + CLIP image embedding (for face structure)
33
+
34
+ <div align="center">
35
+
36
+ ![results](./faceid-plus.jpg)
37
+ </div>
38
+
39
+ **Update 2023/12/28**:
40
+
41
+ IP-Adapter-FaceID-PlusV2: face ID embedding (for face ID) + controllable CLIP image embedding (for face structure)
42
+
43
+ You can adjust the weight of the face structure to get different generation!
44
+
45
+ <div align="center">
46
+
47
+ ![results](./faceid_plusv2.jpg)
48
+ </div>
49
+
50
+ **Update 2024/01/04**:
51
+
52
+ IP-Adapter-FaceID-SDXL: An experimental SDXL version of IP-Adapter-FaceID
53
+
54
+ <div align="center">
55
+
56
+ ![results](./sdxl_faceid.jpg)
57
+ </div>
58
+
59
+ ## Usage
60
+
61
+ ### IP-Adapter-FaceID
62
+
63
+ Firstly, you should use [insightface](https://github.com/deepinsight/insightface) to extract face ID embedding:
64
+
65
+ ```python
66
+
67
+ import cv2
68
+ from insightface.app import FaceAnalysis
69
+ import torch
70
+
71
+ app = FaceAnalysis(name="buffalo_l", providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
72
+ app.prepare(ctx_id=0, det_size=(640, 640))
73
+
74
+ image = cv2.imread("person.jpg")
75
+ faces = app.get(image)
76
+
77
+ faceid_embeds = torch.from_numpy(faces[0].normed_embedding).unsqueeze(0)
78
+ ```
79
+
80
+ Then, you can generate images conditioned on the face embeddings:
81
+
82
+ ```python
83
+
84
+ import torch
85
+ from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL
86
+ from PIL import Image
87
+
88
+ from ip_adapter.ip_adapter_faceid import IPAdapterFaceID
89
+
90
+ base_model_path = "SG161222/Realistic_Vision_V4.0_noVAE"
91
+ vae_model_path = "stabilityai/sd-vae-ft-mse"
92
+ ip_ckpt = "ip-adapter-faceid_sd15.bin"
93
+ device = "cuda"
94
+
95
+ noise_scheduler = DDIMScheduler(
96
+ num_train_timesteps=1000,
97
+ beta_start=0.00085,
98
+ beta_end=0.012,
99
+ beta_schedule="scaled_linear",
100
+ clip_sample=False,
101
+ set_alpha_to_one=False,
102
+ steps_offset=1,
103
+ )
104
+ vae = AutoencoderKL.from_pretrained(vae_model_path).to(dtype=torch.float16)
105
+ pipe = StableDiffusionPipeline.from_pretrained(
106
+ base_model_path,
107
+ torch_dtype=torch.float16,
108
+ scheduler=noise_scheduler,
109
+ vae=vae,
110
+ feature_extractor=None,
111
+ safety_checker=None
112
+ )
113
+
114
+ # load ip-adapter
115
+ ip_model = IPAdapterFaceID(pipe, ip_ckpt, device)
116
+
117
+ # generate image
118
+ prompt = "photo of a woman in red dress in a garden"
119
+ negative_prompt = "monochrome, lowres, bad anatomy, worst quality, low quality, blurry"
120
+
121
+ images = ip_model.generate(
122
+ prompt=prompt, negative_prompt=negative_prompt, faceid_embeds=faceid_embeds, num_samples=4, width=512, height=768, num_inference_steps=30, seed=2023
123
+ )
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 = "SG161222/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:
194
+
195
+ ```python
196
+
197
+ import cv2
198
+ from insightface.app import FaceAnalysis
199
+ from insightface.utils import face_align
200
+ import torch
201
+
202
+ app = FaceAnalysis(name="buffalo_l", providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
203
+ app.prepare(ctx_id=0, det_size=(640, 640))
204
+
205
+ image = cv2.imread("person.jpg")
206
+ faces = app.get(image)
207
+
208
+ faceid_embeds = torch.from_numpy(faces[0].normed_embedding).unsqueeze(0)
209
+ face_image = face_align.norm_crop(image, landmark=faces[0].kps, image_size=224) # you can also segment the face
210
+ ```
211
+
212
+ Then, you can generate images conditioned on the face embeddings:
213
+
214
+ ```python
215
+
216
+ import torch
217
+ from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL
218
+ from PIL import Image
219
+
220
+ from ip_adapter.ip_adapter_faceid import IPAdapterFaceIDPlus
221
+
222
+ v2 = False
223
+ base_model_path = "SG161222/Realistic_Vision_V4.0_noVAE"
224
+ vae_model_path = "stabilityai/sd-vae-ft-mse"
225
+ image_encoder_path = "laion/CLIP-ViT-H-14-laion2B-s32B-b79K"
226
+ ip_ckpt = "ip-adapter-faceid-plus_sd15.bin" if not v2 else "ip-adapter-faceid-plusv2_sd15.bin"
227
+ device = "cuda"
228
+
229
+ noise_scheduler = DDIMScheduler(
230
+ num_train_timesteps=1000,
231
+ beta_start=0.00085,
232
+ beta_end=0.012,
233
+ beta_schedule="scaled_linear",
234
+ clip_sample=False,
235
+ set_alpha_to_one=False,
236
+ steps_offset=1,
237
+ )
238
+ vae = AutoencoderKL.from_pretrained(vae_model_path).to(dtype=torch.float16)
239
+ pipe = StableDiffusionPipeline.from_pretrained(
240
+ base_model_path,
241
+ torch_dtype=torch.float16,
242
+ scheduler=noise_scheduler,
243
+ vae=vae,
244
+ feature_extractor=None,
245
+ safety_checker=None
246
+ )
247
+
248
+ # load ip-adapter
249
+ ip_model = IPAdapterFaceIDPlus(pipe, image_encoder_path, ip_ckpt, device)
250
+
251
+ # generate image
252
+ prompt = "photo of a woman in red dress in a garden"
253
+ negative_prompt = "monochrome, lowres, bad anatomy, worst quality, low quality, blurry"
254
+
255
+ images = ip_model.generate(
256
+ prompt=prompt, negative_prompt=negative_prompt, face_image=face_image, faceid_embeds=faceid_embeds, shortcut=v2, s_scale=1.0,
257
+ num_samples=4, width=512, height=768, num_inference_steps=30, seed=2023
258
+ )
259
+
260
+ ```
261
+
262
+
263
+ ## Limitations and Bias
264
+ - The model does not achieve perfect photorealism and ID consistency.
265
+ - The generalization of the model is limited due to limitations of the training data, base model and face recognition model.
266
+
267
+
268
+
269
+ ## Non-commercial use
270
+ **This model is released exclusively for research purposes and is not intended for commercial use.**
271
+
faceid-plus.jpg ADDED

Git LFS Details

  • SHA256: b366d77e8f0ba2ca905b57a90a20ac9a9ceff421aca8fce6de5d3cb019a4a34f
  • Pointer size: 131 Bytes
  • Size of remote file: 918 kB
faceid_plusv2.jpg ADDED

Git LFS Details

  • SHA256: 5d369c3e49defca663dc50b28b1bb621834d319500b28de6a8de6a6eb319a2de
  • Pointer size: 132 Bytes
  • Size of remote file: 3.44 MB
gitattributes (1).txt ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ ip-adapter-faceid.jpg filter=lfs diff=lfs merge=lfs -text
37
+ faceid_plusv2.jpg filter=lfs diff=lfs merge=lfs -text
38
+ sdxl_faceid.jpg filter=lfs diff=lfs merge=lfs -text
ip-adapter-faceid-plus_sd15.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:252fb53e0d018489d9e7f9b9e2001a52ff700e491894011ada7cfb471e0fadf2
3
+ size 156558503
ip-adapter-faceid-plus_sd15_lora.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3f00341d11e5e7b5aadf63cbdead09ef82eb28669156161cf1bfc2105d4ff1cd
3
+ size 51059544
ip-adapter-faceid-plusv2_sd15.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:26d0d86a1d60d6cc811d3b8862178b461e1eeb651e6fe2b72ba17aa95411e313
3
+ size 156558509
ip-adapter-faceid-plusv2_sd15_lora.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8abff87a15a049f3e0186c2e82c1c8e77783baf2cfb63f34c412656052eb57b0
3
+ size 51059544
ip-adapter-faceid.jpg ADDED

Git LFS Details

  • SHA256: cd4aa6c124459cfe5a9307f298fcf7580fd6caca5ee82baa3b68ca3beb346847
  • Pointer size: 132 Bytes
  • Size of remote file: 4.7 MB
ip-adapter-faceid_sd15.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:201344e22e6f55849cf07ca7a6e53d8c3b001327c66cb9710d69fd5da48a8da7
3
+ size 96740574
ip-adapter-faceid_sd15_lora.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:70699f0dbfadd47de1f81d263cf4c86bd4b7271d841304af9b340b3a7f38e86a
3
+ size 51059544
sdxl_faceid.jpg ADDED

Git LFS Details

  • SHA256: 598c4982ab85aa9b38fbb8cff218ad096ffc6bf6bf01cb192f86be9751c81eef
  • Pointer size: 132 Bytes
  • Size of remote file: 2.78 MB