腾讯最新换脸/脸部一致性模型IPAdapater FaceID在ComfyUI的安装和使用

267次阅读
没有评论
腾讯最新换脸/脸部一致性模型IPAdapater FaceID在ComfyUI的安装和使用

之前发表了IPAdapater FaceID的一些文章和视频,很多朋友很感兴趣,但是在安装和使用上却出现了一些问题。今天我就把安装过程描述一下,并针对常见的问题做一些总结,希望能帮助到各位。

IPAdapater FaceID和IPAdapater FaceID Plus的介绍文章可以参考我的前两篇文章。

改变自己 改变人生:让换脸和角色一致性更简单-最新IPAdapter FaceID模型介绍31 赞同 · 3 评论文章

改变自己 改变人生:换脸一致性模型再升级–IPAdapter FaceID Plus版推出13 赞同 · 3 评论文章

目前我看到只有C++omfyUI支持的节点,WEBUI我最近没有用,应该也会很快推出的。

1.ComfyUI_IPAdapter_plus节点的安装

目前ComfyUI_IPAdapter_plus节点支持IPAdapater FaceID和IPAdapater FaceID Plus最新模型,也是SD社区最快支持这两个模型的项目,大家可以通过这个项目抢先体验。爱用一键安装包的朋友可以等最新的安装包更新,也可以在安装包里面自己安装节点。

https://github.com/cubiq/ComfyUI_IPAdapter_plus​github.com/cubiq/ComfyUI_IPAdapter_plus

ComfyUI_IPAdapter_plus-main

2.1M

·

百度网盘

1)模型下载

相关模型可以在huggingface上下载:

h94/IP-Adapter-FaceID · Hugging Face​huggingface.co/h94/IP-Adapter-FaceID

一定要注意模型和lora要匹配。在comfyui节点配置时切记。

也可以百度盘下载:链接:https://pan.baidu.com/s/181VmYi4X1hFMGYqnXP5TbA?pwd=zw0t

提取码:zw0t

FaceID 需要 insightface,你需要在ComfyUI环境中安装它们。我在后面单独一个章节讨论这个问题。主要参考这个issue获取帮助。

当满足依赖后,你需要:

SD 版本 IPadapter Img encoder Lora
v1.5 FaceID (not used¹) FaceID Lora
v1.5 FaceID Plus ViT-H FaceID Plus Lora

注意:基础版的FaceID模型不使用CLIP vision编码器。应将ipadapter模型放入ComfyUI/models/ipadapter目录下(如果不存在则创建该目录)。也可以在extra_model_paths.yaml文件中添加一个ipadapter条目,使用任何自定义的位置。下面是例子:注意我机器上有好几个版本的comfyUI公用一套模型库。

loras模型需要放在 ComfyUI/models/loras/ 目录下。

Plus版本需要ViT-H图像编码器,就是大家经常说的clip-vision。(clip-vision)我也在后面单独再说明一次。

目前还没有SDXL模型。

2)节点安装

已经安装过的用户,可以通过manager直接安装,国内被墙的客户还可以以下三种方式重新安装

  1. 直接在custome-node\ComfyUI_IPAdapter_plus文件夹下使用git pull 命令更新
  2. 把custome-node下的ComfyUI_IPAdapter_plus删除,注意以前下载的模型文件的备份或者转移。
  3. 在github网站下载整个网站的包,或者使用我共享的文件,下载后改名为ComfyUI_IPAdapter_plus-main.zip解压到customer-node下,文件夹名字可以改为ComfyUI_IPAdapter_plus,也可以不改,都不会影响节点的加载。但是注意不能两个同时存在,会有冲突。

3)更新comfyUI和依赖包

这一步最好执行一下,避免后续安装过程的错误。

4)insightface的安装

如果你已经安装过Reactor或者其它使用过insightface的节点,那么安装就比较简单,但如果你是第一次安装,恭喜你,又要经历一个愉快(痛苦)的安装过程,尤其是不懂开发,命令行使用的用户。

运行update目录下的更新bat脚本,确保安装最新版comfy,不要仅仅依赖管理器,即使它说已经全部更新了,也可能不是真的

  • 确保安装了最新版的ipadapter扩展
  • 如果有的话,从ipadapter扩展和reactor的__pycache__目录中删除缓存文件,以防万一
  • 升级pip:python_embeded\python.exe -m pip install -U pip
  • 安装insightface:python_embeded\python.exe -m pip install insightface

在Windows上编译insightface需要安装Visual Studio或VS C++构建工具中的“使用C++进行桌面开发”。

如果使用CUDA,确保安装了CUDA,CUDNN这两个关键的包,安装方法可以百度。

另外,可以从这里下载预编译版本。根据Python版本选择文件,cp310适用于Python 3.10,cp311适用于Python 3.11。要知道你的Python版本,使用:python_embeded\python.exe -V

https://github.com/Gourieff/Assets/blob/main/Insightface/insightface-0.7.3-cp310-cp310-win_amd64.whl

https://github.com/Gourieff/Assets/blob/main/Insightface/insightface-0.7.3-cp311-cp311-win_amd64.whl

insightface-0.7.3-cp310-cp310-win_amd64.whl

841.7K

·

百度网盘

insightface-0.7.3-cp311-cp311-win_amd64.whl

871.8K

·

百度网盘

然后可以使用python_embeded\python.exe -m pip install insightface-0.7.3-cp310-cp310-win_amd64.whl 或针对Python 3.11使用cp311来安装。

如果之前已经安装了insightface,可以使用python_embeded\python.exe -m pip uninstall insightface移除后再重复上述过程。腾讯实验室选择了insightface作为提供商,而insightface确实很难安装。不记得onnx是否会自动安装以防万一,你可以试着手动安装onnxruntimeonnxruntime-gpu(如果需要的话)。

另外要注意的是,还有个buffalo的模型包需要下载

https://github.com/deepinsight/insightface/releases/download/v0.7/buffalo_l.zip

把下载的压缩包解压到ComfyUI\models\insightface\models\buffalo_l。如果你没有这个模型文件,也不能正常工作。

5)buffalo_l.zip的下载和安装

正常情况下buffalo应该是自动下载的,但有些用户反映自动下载失败,各位可以

https://github.com/deepinsight/insightface/releases/download/v0.7/buffalo_l.zip

解压文件到 ComfyUI\models\insightface\models\buffalo_l路径下,正常应该有这五个模型文件。

6)onnx和onnxruntime,onnxruntime-gpu的安装

安装命令如下:

python_embeded\python.exe -m pip install onnx onnxruntime onnxruntime-gpu

一定要安装好CUDA,cuDNN。RT则根据实际情况来自行判断。

window11系统CUDA、cuDNN 安装以及环境变量配置_cuda环境变量怎么设置_QuietNightThought的博客-CSDN博客

检查这五个动态链接库文件

  • cublas64_11.dll –> CUDA 11.x
  • cudart64_110.dll –> CUDA 11.x
  • cudnn64_8.dll –> cuDNN 8.x
  • nvinfer_plugin.dll –> NVIDIA TensorRT
  • nvinfer.dll –> NVIDIA TensorRT

可以看到我的环境TensorRT的两个动态连接库找不到

(sd160) C:\DEV\sd160\stable-diffusion-webui>where cublas64_11.dll
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin\cublas64_11.dll

(sd160) C:\DEV\sd160\stable-diffusion-webui>where cudart64_110.dll
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin\cudart64_110.dll

(sd160) C:\DEV\sd160\stable-diffusion-webui>where cudnn64_8.dll
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin\cudnn64_8.dll

(sd160) C:\DEV\sd160\stable-diffusion-webui>where nvinfer_plugin.dll
信息: 用提供的模式无法找到文件。

(sd160) C:\DEV\sd160\stable-diffusion-webui>where nvinfer.dll
信息: 用提供的模式无法找到文件。

重新下载tensorRT,这是一个打包的文件集,没有安装程序,把对应的文件拷贝到对应路径下就可以

核心重点:将TensorRT-8.6.1.6\include中.h头文件 copy 到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\include 将TensorRT-8.6.1.6\lib 中所有lib文件 copy 到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\lib\x64 将TensorRT-8.6.1.6\lib 中所有dll文件copy 到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin

再次执行命令

(sd160) C:\DEV\sd160\stable-diffusion-webui>where nvinfer_plugin.dll
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin\nvinfer_plugin.dll

(sd160) C:\DEV\sd160\stable-diffusion-webui>where nvinfer.dll
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin\nvinfer.dll

因为有了动态连接库文件,理论上不需要重启,就可以用了。

有些时候还需要设置一个set CUDA_MODULE_LOADING=LAZY的环境变量

还有人说高版本的onnx会引起问题。会建议安装稳定的版本,比如

uninstall onnx 1.15.0 onnxruntime 1.16.3 onnxruntime-gpu 1.16.3 and instal version 1.14 for all

2.模型在ComfyUI的使用

安装节点后在节点路径下有三个示例流程,需要注意的是作者12月28日刚刚更新,27日的客户必须要重新更新才能使用最新的plus节点。

1)基础流程和节点

A节点,IPAdapterModelLoader节点,加载ip-adapter-faceid_sd15.bin模型,需要选择你在ComfyUI\models\ipadapter文件夹下模型文件

B节点,CLIPVisionLoader节点,加载ComfyUI\models\clip_vision的IMG encoder,这个模型只有两个1.5版本的VIT-H,XL版本的VIT-G,但是需要注意的是有一部分XL模型是基于1.5 encoder训练的,所以大部分时候都是选择小模型。

模型选错时会报如下错:

Error occurred when executing IPAdapterApply: mat1 and mat2 shapes cannot be multiplied (257×1664 and 1280×768) File “E:\DEV\ComfyUI_windows_portable\ComfyUI\execution.py”, line 153, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all)

C节点,InsightFaceLoader节点,主要是加载InsightFace模型的,三个模型目前效果差异感觉不大,当然如果你CPU不好就选CUDA

D节点,LoraLoaderModelOnly节点,加载对应Lora模型。

E节点,专门应用FaceID的IPAdapter应用节点。

第一例子使用后,后面两个流程其实也都可以跑起来了。

我自己做了一个基础模型和reactor节点比较的流程。打分的节点我自己写的,用的face++的脸部比较API(收费接口一分钱一次)。

后面又做了改进,可以把分值打在图片下方,方便对比。

3.常见问题

1) InsightFace is not installed! 错误

Window环境最常见的一个问题就是

IPAdapter: InsightFace is not installed! Install the missing dependencies if you wish to use FaceID models.

File “D:\ComfyUI_windows_portable\ComfyUI\execution.py”, line 153, in recursive_execute
output_data, output_ui = get_output_data(obj, input_data_all)
File “D:\ComfyUI_windows_portable\ComfyUI\execution.py”, line 83, in get_output_data
return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
File “D:\ComfyUI_windows_portable\ComfyUI\execution.py”, line 76, in map_node_over_list
results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
File “D:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI_IPAdapter_plus\IPAdapterPlus.py”, line 459, in load_insight_face
raise Exception(‘IPAdapter: InsightFace is not installed! Install the missing dependencies if you wish to use FaceID models.’)

主要是insightface安装不成功,也有一种情况,在windows环境里面和现有的reactor冲突。我发现了一种解决方法,实测有效,但是项目作者本人并不推荐,因为修改了部分代码。

把ComfyUI_IPAdapter_plus\IPAdapterPlus.py 代码中,注释527-530行的from insightface.app import FaceAnalysis的四行代码,把from insightface.app import FaceAnalysis加到py文件的顶部。

腾讯最新换脸/脸部一致性模型IPAdapater FaceID在ComfyUI的安装和使用

2)clip vision模型选错

关于clip vision也就是IMG encoder的选择,大家看下面这个表格,记住只有一个ip-adapter-SDXL需要选择bigG模型, 或者带VIT-G后缀,其实也就两个IPA模型。

选错模型会报下面的错误,上面也提到过。

RuntimeError: mat1 and mat2 shapes cannot be multiplied (257×1664 and 1280×768)

3)onnxruntime无法加载

主要错误信息

LoadLibrary failed with error 126 ……onnxruntime_providers_tensorrt.dll

参考上面onnx的安装步骤。

4)与reactor节点共享问题

有用户反映,无法与reactor节点共同使用。我目前可以两个节点同时使用,建议尽量通过虚拟环境和conda,或者使用embedpython的 python -m pip方式安装各种包,减少包冲突的可能性。

5)module ‘torchvision.transforms’ has no attribute ‘ElasticTransform’

Error occurred when executing IPAdapterApply:
module ‘torchvision.transforms’ has no attribute ‘ElasticTransform’
File “D:\ComfyUI manxueban\ComfyUI\execution.py”, line 153, in recursive_execute
output_data, output_ui = get_output_data(obj, input_data_all)
File “D:\ComfyUI manxueban\ComfyUI\execution.py”, line 83, in get_output_data
return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
File “D:\ComfyUI manxueban\ComfyUI\execution.py”, line 76, in map_node_over_list
results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
File “D:\ComfyUI manxueban\ComfyUI\custom_nodes\ComfyUI_IPAdapter_plus\IPAdapterPlus.py”, line 620, in apply_ipadapter
neg_image = image_add_noise(image, noise) if noise > 0 else None
File “D:\ComfyUI manxueban\ComfyUI\custom_nodes\ComfyUI_IPAdapter_plus\IPAdapterPlus.py”, line 174, in image_add_noise
TT.ElasticTransform(alpha=75.0, sigma=noise*3.5), # shuffle the image

更新comfyUI和python包,在windows portable里面update文件夹下有一个脚本,可以执行一下。

4总结

ComfyUI_IPAdapter_plus体现了社区开源项目的特点,作者如果积极,更新很快,但是问题也多,需要使用者自己去学习和解决。不过甘蔗不能两头甜,愿意尝鲜的使用者也需要多付出一些代价。

大家使用中如果遇到问题,可以在评论区留言,我有空就帮大家看一下。要是特别着急需要解节点问题和使用问题的同学,可以尝试加我微信或者使用知乎的付费咨询,请别人喝一杯咖啡钱都不愿意出的朋友慎重考虑付费咨询,毕竟大家的时间都宝贵。微信号shuai851619。

另外最近我已经设计完成了一整套ComfyUI的学习课程,现在只开一对一辅导课,保证你学的都是干货,能应用到实际工作中,对ComfyUI的理解犹如张无忌“乾坤大挪移”练到第七层,有意的小伙伴可以来找我。

正文完
可以使用微信扫码关注公众号(ID:xzluomor)
post-qrcode
 
评论(没有评论)