README.md 7.23 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
# 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(方法一)

mashun1's avatar
mashun1 committed
33
    docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-ubuntu20.04-dtk24.04.1-py3.10
mashun1's avatar
mashun1 committed
34
35
36
37
    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

mashun1's avatar
mashun1 committed
38
39
40
41
    wget https://cancon.hpccube.com:65024/directlink/4/migraphx/DAS1.1/migraphx-4.3.0+das1.1.git0a2480f.abi0.dtk2404-cp310-cp310-linux_x86_64.run

    bash migraphx-4.3.0+das1.1.git0a2480f.abi0.dtk2404-cp310-cp310-linux_x86_64.run

mashun1's avatar
mashun1 committed
42
43
44
45
46
47
48
49
50
### 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

mashun1's avatar
mashun1 committed
51
52
53
54
    wget https://cancon.hpccube.com:65024/directlink/4/migraphx/DAS1.1/migraphx-4.3.0+das1.1.git0a2480f.abi0.dtk2404-cp310-cp310-linux_x86_64.run

    bash migraphx-4.3.0+das1.1.git0a2480f.abi0.dtk2404-cp310-cp310-linux_x86_64.run

mashun1's avatar
mashun1 committed
55

mashun1's avatar
mashun1 committed
56
57
### Anaconda (方法三)
1、关于本项目DCU显卡所需的特殊深度学习库可从光合开发者社区下载安装:
chenzk's avatar
chenzk committed
58
https://developer.sourcefind.cn/tool/
mashun1's avatar
mashun1 committed
59

mashun1's avatar
mashun1 committed
60
61
62
63
64
65
    DTK驱动:dtk24.04.1
    python:python3.10
    torch:2.1.0
    torchvision:0.16.0
    onnxruntime:1.15.0
    migraphx: migraphx-4.3.0
mashun1's avatar
mashun1 committed
66
67
68
69
70
71
72
73

Tips:以上dtk驱动、python、torch等DCU相关工具版本需要严格一一对应

2、其它非特殊库参照requirements.txt安装

    pip install -r requirements.txt


mashun1's avatar
mashun1 committed
74
75
注意:如果遇到运行错误`Numpy`相关,需要`pip install numpy==1.26.0`

mashun1's avatar
mashun1 committed
76
77
78
79
## 数据集



mashun1's avatar
update  
mashun1 committed
80
81
82
83
## 训练



mashun1's avatar
mashun1 committed
84
85
86
87
88
## 推理

### 模型下载

|url|名称|是否必要|
mashun1's avatar
update  
mashun1 committed
89
|:---:|:---:|:---:|
chenzk's avatar
chenzk committed
90
91
92
93
94
95
96
97
98
99
|[huggingface](https://huggingface.co/InstantX/InstantID) \| [SCNet] |InstantID|是|
|[huggingface](https://huggingface.co/wangqixun/YamerMIX_v8/tree/main) \| [SCNet] |YamerMIX_v8|是|
|[google driver](https://drive.google.com/file/d/18wEUfMNohBJ4K3Ly5wpTejPfDzp-8fI8/view) \| [SCNet] |antelopev2|是|
|[huggingface](https://huggingface.co/latent-consistency/lcm-lora-sdxl/tree/main) \| [SCNet] |pytorch_lora_weights|是|
|[huggingface](https://huggingface.co/FMNing/sd-control-facenet/tree/main) \| [SCNet] |facenet|否|
|[huggingface](https://hf-mirror.com/diffusers/controlnet-canny-sdxl-1.0/tree/main) \| [SCNet] |controlnet-canny-sdxl-1.0|否|
|[huggingface](https://hf-mirror.com/diffusers/controlnet-depth-sdxl-1.0-small/tree/main) \| [SCNet] |controlnet-depth-sdxl-1.0-small|否|
|[huggingface](https://hf-mirror.com/Intel/dpt-hybrid-midas/tree/main) \| [SCNet] |dpt-hybrid-midas|否|
|[huggingface](https://huggingface.co/lllyasviel/ControlNet/tree/main/annotator/ckpts) \| [SCNet] |annotator|否|
|[huggingface](https://huggingface.co/thibaud/controlnet-openpose-sdxl-1.0/tree/main) \| [SCNet] |controlnet-openpose-sdxl-1.0|否|
mashun1's avatar
mashun1 committed
100

mashun1's avatar
mashun1 committed
101
102
注意:如果huggingface无法访问,可访问( https://hf-mirror.com/ ),
`是否必须``否`涉及的模型仅在`app-multicontrolnet.py`需要。
mashun1's avatar
mashun1 committed
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179


    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
180
#### app
mashun1's avatar
mashun1 committed
181
182
183

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

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

mashun1's avatar
mashun1 committed
186
187
188
189
#### app-multicontrolnet

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

mashun1's avatar
mashun1 committed
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
![Alt text](readme_imgs/image-4.png)

### 精度



## 应用场景

### 算法类别

`AIGC`

### 热点行业

`零售,广媒,设计`

## 源码仓库及问题反馈

chenzk's avatar
chenzk committed
208
* https://developer.sourcefind.cn/codes/modelzoo/instantid_pytorch
mashun1's avatar
mashun1 committed
209
210
211
212

## 参考资料

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