wanghaofan
commited on
Commit
•
1305afc
1
Parent(s):
e527716
Update README.md
Browse files
README.md
CHANGED
@@ -17,10 +17,10 @@ pipeline_tag: text-to-image
|
|
17 |
|
18 |
## Introduction
|
19 |
|
20 |
-
InstantID is a new state-of-the-art tuning-free method to achieve ID-Preserving generation with only single image.
|
21 |
|
22 |
<div align="center">
|
23 |
-
<img src='examples/
|
24 |
</div>
|
25 |
|
26 |
|
@@ -31,11 +31,86 @@ You also can download the model in python script:
|
|
31 |
|
32 |
```python
|
33 |
from huggingface_hub import hf_hub_download
|
34 |
-
hf_hub_download(repo_id="InstantX/InstantID", local_dir="./checkpoints")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
```
|
36 |
|
37 |
For more details, please follow the instructions in our [GitHub repository](https://github.com/InstantID/InstantID).
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
## Disclaimer
|
41 |
|
|
|
17 |
|
18 |
## Introduction
|
19 |
|
20 |
+
InstantID is a new state-of-the-art tuning-free method to achieve ID-Preserving generation with only single image, supporting various downstream tasks.
|
21 |
|
22 |
<div align="center">
|
23 |
+
<img src='examples/applications.png'>
|
24 |
</div>
|
25 |
|
26 |
|
|
|
31 |
|
32 |
```python
|
33 |
from huggingface_hub import hf_hub_download
|
34 |
+
hf_hub_download(repo_id="InstantX/InstantID", filename="ControlNetModel/config.json", local_dir="./checkpoints")
|
35 |
+
hf_hub_download(repo_id="InstantX/InstantID", filename="ControlNetModel/diffusion_pytorch_model.safetensors", local_dir="./checkpoints")
|
36 |
+
hf_hub_download(repo_id="InstantX/InstantID", filename="ip-adapter.bin", local_dir="./checkpoints")
|
37 |
+
```
|
38 |
+
|
39 |
+
For face encoder, you need to manutally download via this [URL](https://github.com/deepinsight/insightface/issues/1896#issuecomment-1023867304) to `models/antelopev2`.
|
40 |
+
|
41 |
+
```python
|
42 |
+
# !pip install opencv-python transformers accelerate insightface
|
43 |
+
import diffusers
|
44 |
+
from diffusers.utils import load_image
|
45 |
+
from diffusers.models import ControlNetModel
|
46 |
+
|
47 |
+
import cv2
|
48 |
+
import torch
|
49 |
+
import numpy as np
|
50 |
+
from PIL import Image
|
51 |
+
|
52 |
+
from insightface.app import FaceAnalysis
|
53 |
+
from pipeline_stable_diffusion_xl_instantid import StableDiffusionXLInstantIDPipeline, draw_kps
|
54 |
+
|
55 |
+
# prepare 'antelopev2' under ./models
|
56 |
+
app = FaceAnalysis(name='antelopev2', root='./', providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
|
57 |
+
app.prepare(ctx_id=0, det_size=(640, 640))
|
58 |
+
|
59 |
+
# prepare models under ./checkpoints
|
60 |
+
face_adapter = f'./checkpoints/ip-adapter.bin'
|
61 |
+
controlnet_path = f'./checkpoints/ControlNetModel'
|
62 |
+
|
63 |
+
# load IdentityNet
|
64 |
+
controlnet = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=torch.float16)
|
65 |
+
|
66 |
+
pipe = StableDiffusionXLInstantIDPipeline.from_pretrained(
|
67 |
+
... "stabilityai/stable-diffusion-xl-base-1.0", controlnet=controlnet, torch_dtype=torch.float16
|
68 |
+
... )
|
69 |
+
pipe.cuda()
|
70 |
+
|
71 |
+
# load adapter
|
72 |
+
pipe.load_ip_adapter_instantid(face_adapter)
|
73 |
+
```
|
74 |
+
|
75 |
+
Then, you can customized your own face images
|
76 |
+
|
77 |
+
```python
|
78 |
+
# load an image
|
79 |
+
image = load_image("your-example.jpg")
|
80 |
+
|
81 |
+
# prepare face emb
|
82 |
+
face_info = app.get(cv2.cvtColor(np.array(face_image), cv2.COLOR_RGB2BGR))[-1]
|
83 |
+
face_emb = face_info['embedding']
|
84 |
+
face_kps = draw_kps(face_image, face_info['kps'])
|
85 |
+
|
86 |
+
pipe.set_ip_adapter_scale(0.8)
|
87 |
+
|
88 |
+
prompt = "analog film photo of a man. faded film, desaturated, 35mm photo, grainy, vignette, vintage, Kodachrome, Lomography, stained, highly detailed, found footage, masterpiece, best quality"
|
89 |
+
negative_prompt = "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured (lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch,deformed, mutated, cross-eyed, ugly, disfigured"
|
90 |
+
|
91 |
+
# generate image
|
92 |
+
image = pipe(
|
93 |
+
... prompt, image_embeds=face_emb, image=face_kps, controlnet_conditioning_scale=0.8
|
94 |
+
... ).images[0]
|
95 |
```
|
96 |
|
97 |
For more details, please follow the instructions in our [GitHub repository](https://github.com/InstantID/InstantID).
|
98 |
|
99 |
+
## Usage Tips
|
100 |
+
1. If you're not satisfied with the similarity, try to increase the weight of "IdentityNet Strength" and "Adapter Strength".
|
101 |
+
2. If you feel that the saturation is too high, first decrease the Adapter strength. If it is still too high, then decrease the IdentityNet strength.
|
102 |
+
3. If you find that text control is not as expected, decrease Adapter strength.
|
103 |
+
4. If you find that realistic style is not good enough, go for our Github repo and use a more realistic base model.
|
104 |
+
|
105 |
+
## Demos
|
106 |
+
|
107 |
+
<div align="center">
|
108 |
+
<img src='examples/0.png'>
|
109 |
+
</div>
|
110 |
+
|
111 |
+
<div align="center">
|
112 |
+
<img src='examples/1.png'>
|
113 |
+
</div>
|
114 |
|
115 |
## Disclaimer
|
116 |
|