README.md 5.82 KB
Newer Older
mashun1's avatar
mashun1 committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# InstantID

## 论文

**InstantID:Zero-shot Identity-Preserving Generation in Seconds**

* https://arxiv.org/pdf/2401.07519.pdf

## 模型结构

该模型主要结构为Stable Diffusion,并使用`IdentityNet`(提取面部特征),`IPA``Porjection + FaceEmbedding + Cross Attention`,获取面部prompt)以及`Text Encoder + Text Embedding + Cross Attention`(获取文字prompt)的输出作为`Unet`的控制条件。

![Alt text](readme_imgs/image-1.png)

## 算法原理

该算法在`ControlNet`思想的基础上,通过增加`IdentityNet``IPA`等获取面部特征及Prompt,并将此作为`Unet`的控制条件,具体如下

1、IdentityNet

仅使用五个面部关键点(两个用于眼睛,一个用于鼻子,两个用于嘴巴)作为条件输入;取消了文本提示,并将ID嵌入作为ControlNet中交叉注意力层的条件。

![Alt text](readme_imgs/image-2.png)

2、IPA

引入了一种轻量级的自适应模块,其中包含独立的交叉注意力,以支持图像作为提示。

## 环境配置

### Docker(方法一)

    docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.13.1-centos7.6-dtk-23.04.1-py39-latest
    docker run --shm-size 10g --network=host --name=instantid --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v 项目地址(绝对路径):/home/ -it <your IMAGE ID> bash

    pip install -r requirements.txt

### Dockerfile(方法二)

    # 需要在对应的目录下
    docker build -t <IMAGE_NAME>:<TAG> .
    # <your IMAGE ID>用以上拉取的docker的镜像ID替换
    docker run --shm-size 10g --network=host --name=instantid --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v 项目地址(绝对路径):/home/ -it <your IMAGE ID> bash

    pip install -r requirements.txt


## 数据集



## 推理

### 模型下载

|url|名称|是否必要|
|:---|:-----|:----|
|https://huggingface.co/InstantX/InstantID||是|
|https://huggingface.co/wangqixun/YamerMIX_v8/tree/main||是|
|https://drive.google.com/file/d/18wEUfMNohBJ4K3Ly5wpTejPfDzp-8fI8/view|antelopev2|是|
|https://huggingface.co/latent-consistency/lcm-lora-sdxl/tree/main|pytorch_lora_weights|是|
|https://huggingface.co/FMNing/sd-control-facenet/tree/main|facenet|否|
|https://hf-mirror.com/diffusers/controlnet-canny-sdxl-1.0/tree/main||否|
|https://hf-mirror.com/diffusers/controlnet-depth-sdxl-1.0-small/tree/main||否|
|https://hf-mirror.com/Intel/dpt-hybrid-midas/tree/main||否|
|https://huggingface.co/lllyasviel/ControlNet/tree/main/annotator/ckpts||否|
|https://huggingface.co/thibaud/controlnet-openpose-sdxl-1.0/tree/main||否|


mashun1's avatar
mashun1 committed
70
71
注意:如果huggingface无法访问,可访问( https://hf-mirror.com/ ),
`是否必须``否`涉及的模型仅在`app-multicontrolnet.py`需要。
mashun1's avatar
mashun1 committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148


    models/
    └── antelopev2
        ├── 1k3d68.onnx
        ├── 2d106det.onnx
        ├── genderage.onnx
        ├── glintr100.onnx
        └── scrfd_10g_bnkps.onnx
    
    checkpoints/
    ├── ControlNetModel
    │   ├── config.json
    │   └── diffusion_pytorch_model.safetensors
    ├── diffusers
    │   ├── controlnet-canny-sdxl-1.0
    │   │   ├── config.json
    │   │   └── diffusion_pytorch_model.bin
    │   └── controlnet-depth-sdxl-1.0-small
    │       ├── config.json
    │       └── diffusion_pytorch_model.bin
    ├── Intel
    │   └── dpt-hybrid-midas
    │       ├── config.json
    │       ├── preprocessor_config.json
    │       └── pytorch_model.bin
    ├── ip-adapter.bin
    ├── lllyasviel
    │   └── ControlNet
    │       └── annotator
    │           └── ckpts
    │               ├── body_pose_model.pth
    │               ├── facenet.pth
    │               └── hand_pose_model.pth
    ├── pytorch_lora_weights.safetensors
    ├── thibaud
    │   └── controlnet-openpose-sdxl-1.0
    │       ├── config.json
    │       └── diffusion_pytorch_model.bin
    └── wangqixun
        └── YamerMIX_v8
            ├── model_index.json
            ├── scheduler
            │   └── scheduler_config.json
            ├── text_encoder
            │   ├── config.json
            │   └── model.safetensors
            ├── text_encoder_2
            │   ├── config.json
            │   └── model.safetensors
            ├── tokenizer
            │   ├── merges.txt
            │   ├── special_tokens_map.json
            │   ├── tokenizer_config.json
            │   └── vocab.json
            ├── tokenizer_2
            │   ├── merges.txt
            │   ├── special_tokens_map.json
            │   ├── tokenizer_config.json
            │   └── vocab.json
            ├── unet
            │   ├── config.json
            │   └── diffusion_pytorch_model.safetensors
            └── vae
                ├── config.json
                └── diffusion_pytorch_model.safetensors


### 命令

    python gradio_demo/app.py

    # 多controlnet
    python gradio_demo/app-multicontrolnet.py 

## result

mashun1's avatar
mashun1 committed
149
150
151
152
#### app.py

左边为输入图像,右边为输出图像

mashun1's avatar
mashun1 committed
153
154
![Alt text](readme_imgs/image-3.png)

mashun1's avatar
mashun1 committed
155
156
157
158
#### app-multicontrolnet

左边为输入图像,右边为输出图像

mashun1's avatar
mashun1 committed
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
![Alt text](readme_imgs/image-4.png)

### 精度



## 应用场景

### 算法类别

`AIGC`

### 热点行业

`零售,广媒,设计`

## 源码仓库及问题反馈

* https://developer.hpccube.com/codes/modelzoo/instantid_pytorch

## 参考资料

* https://github.com/InstantID/InstantID