Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using face-ID got error 'onnx.onnx_cpp2py_export' is not a package #156

Closed
ultimatech-cn opened this issue Dec 23, 2023 · 23 comments
Closed

Comments

@ultimatech-cn
Copy link

ultimatech-cn commented Dec 23, 2023

When I trying new face-id sample got following error

ERROR:root:Traceback (most recent call last):
File "E:\DEV\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI_IPAdapter_plus\IPAdapterPlus.py", line 457, in load_insight_face
from insightface.app import FaceAnalysis
File "E:\DEV\ComfyUI_windows_portable\python_embeded\lib\site-packages\insightface_init_.py", line 16, in
from . import model_zoo
File "E:\DEV\ComfyUI_windows_portable\python_embeded\lib\site-packages\insightface\model_zoo_init_.py", line 1, in
from .model_zoo import get_model
File "E:\DEV\ComfyUI_windows_portable\python_embeded\lib\site-packages\insightface\model_zoo\model_zoo.py", line 11, in
from .arcface_onnx import *
File "E:\DEV\ComfyUI_windows_portable\python_embeded\lib\site-packages\insightface\model_zoo\arcface_onnx.py", line 10, in
import onnx
File "E:\DEV\ComfyUI_windows_portable\python_embeded\lib\site-packages\onnx_init_.py", line 116, in
from onnx import (
File "E:\DEV\ComfyUI_windows_portable\python_embeded\lib\site-packages\onnx\checker.py", line 29, in
import onnx.defs
File "E:\DEV\ComfyUI_windows_portable\python_embeded\lib\site-packages\onnx\defs_init_.py", line 22, in
import onnx.onnx_cpp2py_export.defs as C # noqa: N812
ModuleNotFoundError: No module named 'onnx.onnx_cpp2py_export.defs'; 'onnx.onnx_cpp2py_export' is not a package

Check the package insighface and onnx by pip show

...>....\python_embeded\python.exe -m pip show insightface
WARNING: Ignoring invalid distribution -rotobuf (e:\dev\comfyui_windows_portable\python_embeded\lib\site-packages)
Name: insightface
Version: 0.7.3
Summary: InsightFace Python Library
Home-page: https://github.com/deepinsight/insightface
Author: InsightFace Contributors
.......

I try to import module in python as below, there is no error.

E:\DEV\ComfyUI_windows_portable>python_embeded\python.exe
Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec 6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import onnx.onnx_cpp2py_export.defs as C
from insightface.app import FaceAnalysis

Any workaround for this?

@Edmaximus
Copy link

I'm facing the same issue with the Load InsightFace node in ComfyUI Portable(Python 3.10. I've already tried all the troubleshooting steps below to no success:
Uninstalled, installed and verified onnx and onnxruntime.
Tested manually importing onnx and onnxruntime by themselves, which worked without issues.
Explicitly imported onnxruntime before insightface in the load_insight_face function
Downgrading onnx a few versions to check if they work.
Made sure there's no conflict between this python environment and my other ones.
Checked the onnx package directory and found the .pyd file corresponding to the onnx_cpp2py_export module.
Fixed a dependency conflicts between protobuf and mediapipe.

I have Reactor on this same comfyui install and it's using Insightface perfectly fine. Any assistance with this would be appreciated.

@ultimatech-cn
Copy link
Author

ultimatech-cn commented Dec 25, 2023

I find a strange workaround for that, but I think it is related to python module importing on Windows.

  1. stop comfyUI.
  2. changing something in "..\ComfyUI_windows_portable\python_embeded\Lib\site-packages\onnx\defs_init_.py" to cause error when initialing.
  3. starting comfyui.
  4. load the face id sample workflow and prompt, you will find error reporting
  5. changing \python_embeded\Lib\site-packages\onnx\defs_init_.py file back.
  6. prompt the workflow again, it works

There may be some other way to solve the problem.

@Edmaximus
Copy link

@ultimatech-cn Strange workaround indeed. Unfortunately, once comfyui is restarted we go back to the same situation. Maybe something is being cached once ONNX is initially loaded and causing a conflict with insightface or the other modules. Once we make the change to init.py, the cache is purged. This is all a guess tho since I know next to nothing about the onnx module.

@ultimatech-cn
Copy link
Author

ultimatech-cn commented Dec 26, 2023

@ultimatech-cn Strange workaround indeed. Unfortunately, once comfyui is restarted we go back to the same situation. Maybe something is being cached once ONNX is initially loaded and causing a conflict with insightface or the other modules. Once we make the change to init.py, the cache is purged. This is all a guess tho since I know next to nothing about the onnx module.

You are right, it is related to insightface package importing. I have changed the code of IPAdapterPlus.py. First and # to line from 457 to 460. And add "from insightface.app import FaceAnalysis" to top of the code

def load_insight_face(self, provider):
# try:
# from insightface.app import FaceAnalysis
# except ImportError:
# raise Exception('IPAdapter: InsightFace is not installed! Install the missing dependencies if you wish to use FaceID models.')

It worked.

@harelc
Copy link

harelc commented Dec 27, 2023

Had the same problem. If comfyui-reactor-node is loaded as well, the problem persis even when moving the import to the beginning of IPAdapterPlus.py as suggested above. It's some kind of clash between reactor-node's use of onnx/protobuf and IPAdapter-plus's use of it when loading the insightface/buffalo model.

@Edmaximus
Copy link

I can confirm the issue is indeed caused by a conflict with the comfyui-reactor node.

@chlowden
Copy link

chlowden commented Jan 7, 2024

I am getting the error below ... If the ReActor Node for ComfyUI node is ENABLED in the ComfyUI Manager. DISABLING the ReActor node in the manager resolves the issue.

`Error occurred when executing InsightFaceLoader:

No module named 'onnx.onnx_cpp2py_export.defs'; 'onnx.onnx_cpp2py_export' is not a package

File "/home/admin/ComfyUI/execution.py", line 154, in recursive_execute
output_data, output_ui = get_output_data(obj, input_data_all)
File "/home/admin/ComfyUI/execution.py", line 84, in get_output_data
return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
File "/home/admin/ComfyUI/execution.py", line 77, in map_node_over_list
results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
File "/home/admin/ComfyUI/custom_nodes/ComfyUI_IPAdapter_plus/IPAdapterPlus.py", line 529, in load_insight_face
raise Exception(e)`

@balibell
Copy link

balibell commented Jan 8, 2024

I am getting the error below ... If the ReActor Node for ComfyUI node is ENABLED in the ComfyUI Manager. DISABLING the ReActor node in the manager resolves the issue.

`Error occurred when executing InsightFaceLoader:

No module named 'onnx.onnx_cpp2py_export.defs'; 'onnx.onnx_cpp2py_export' is not a package

File "/home/admin/ComfyUI/execution.py", line 154, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) File "/home/admin/ComfyUI/execution.py", line 84, in get_output_data return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True) File "/home/admin/ComfyUI/execution.py", line 77, in map_node_over_list results.append(getattr(obj, func)(**slice_dict(input_data_all, i))) File "/home/admin/ComfyUI/custom_nodes/ComfyUI_IPAdapter_plus/IPAdapterPlus.py", line 529, in load_insight_face raise Exception(e)`

And also ComfyUI_roop may cause the same problem.

@zejacky
Copy link

zejacky commented Jan 11, 2024

The same "problem" here. I did already reinstall as mentioned. (using python 3.10.10 on Windows)
Reactor works without issues.

As workaround I move the custom node "reactor" out of comfyui, and it works.
However, I would like to use faceid together with reactor. As many other users too, I guess ;-)

I will try to reinstall comfyui from scratch, and see if it works.

Thank you for a hint.

@zejacky
Copy link

zejacky commented Jan 12, 2024

The same "problem" here. I did already reinstall as mentioned. (using python 3.10.10 on Windows) Reactor works without issues.

As workaround I move the custom node "reactor" out of comfyui, and it works. However, I would like to use faceid together with reactor. As many other users too, I guess ;-)

I will try to reinstall comfyui from scratch, and see if it works.

Thank you for a hint.

It works for me! Yesterday I reinstalled comfy from scratch (not portable).
After I installed first Reactor, then ipadapter-plus.

Now I just did a Update all inside comfyui manager. Enabled Reactor node again, and no errors anymore,
I tried with SD1.5 and SDXL.

Thanks a lot👍

@bihailantian655
Copy link

Had the same problem

@xiaohaihui-smart
Copy link

I find a strange workaround for that, but I think it is related to python module importing on Windows.

  1. stop comfyUI.
  2. changing something in "..\ComfyUI_windows_portable\python_embeded\Lib\site-packages\onnx\defs__init__.py" to cause error when initialing.
  3. starting comfyui.
  4. load the face id sample workflow and prompt, you will find error reporting
  5. changing \python_embeded\Lib\site-packages\onnx\defs__init__.py file back.
  6. prompt the workflow again, it works

There may be some other way to solve the problem.

how to chang defs__init_.py file ,i had same problem

@bihailantian655
Copy link

I find a strange workaround for that, but I think it is related to python module importing on Windows.

  1. stop comfyUI.
  2. changing something in "..\ComfyUI_windows_portable\python_embeded\Lib\site-packages\onnx\defs__init__.py" to cause error when initialing.
  3. starting comfyui.
  4. load the face id sample workflow and prompt, you will find error reporting
  5. changing \python_embeded\Lib\site-packages\onnx\defs__init__.py file back.
  6. prompt the workflow again, it works

There may be some other way to solve the problem.

how to chang defs__init_.py file ,i had same problem

我觉得他的意思大概是,随便写点什么,让comfui启动报错。

@ultimatech-cn
Copy link
Author

ultimatech-cn commented Jan 16, 2024

还可以参考我那个修改代码的方法。
You are right, it is related to insightface package importing. I have changed the code of IPAdapterPlus.py. First and # to line from 457 to 460. And add "from insightface.app import FaceAnalysis" to top of the code

def load_insight_face(self, provider):
# try:
# from insightface.app import FaceAnalysis
# except ImportError:
# raise Exception('IPAdapter: InsightFace is not installed! Install the missing dependencies if you wish to use FaceID models.')

@zejacky
Copy link

zejacky commented Jan 16, 2024

The same "problem" here. I did already reinstall as mentioned. (using python 3.10.10 on Windows) Reactor works without issues.
As workaround I move the custom node "reactor" out of comfyui, and it works. However, I would like to use faceid together with reactor. As many other users too, I guess ;-)
I will try to reinstall comfyui from scratch, and see if it works.
Thank you for a hint.

It works for me! Yesterday I reinstalled comfy from scratch (not portable). After I installed first Reactor, then ipadapter-plus.

Now I just did a Update all inside comfyui manager. Enabled Reactor node again, and no errors anymore, I tried with SD1.5 and SDXL.

Thanks a lot👍

What I need to mention. I installed comfyui from scratch using python 3.12 and the nightly version of pytorch.

@xiaohaihui-smart
Copy link

还可以参考我那个修改代码的方法。 You are right, it is related to insightface package importing. I have changed the code of IPAdapterPlus.py. First and # to line from 457 to 460. And add "from insightface.app import FaceAnalysis" to top of the code

def load_insight_face(self, provider):
# try:
# from insightface.app import FaceAnalysis
# except ImportError:
# raise Exception('IPAdapter: InsightFace is not installed! Install the missing dependencies if you wish to use FaceID models.')

方便提供一下具体代码吗,我把from insightface.app import FaceAnalysis这个加载首行,直接就报错,IPAdapterPlus直接就不可用,非常感谢

@xiaohaihui-smart
Copy link

I find a strange workaround for that, but I think it is related to python module importing on Windows.

  1. stop comfyUI.
  2. changing something in "..\ComfyUI_windows_portable\python_embeded\Lib\site-packages\onnx\defs__init__.py" to cause error when initialing.
  3. starting comfyui.
  4. load the face id sample workflow and prompt, you will find error reporting
  5. changing \python_embeded\Lib\site-packages\onnx\defs__init__.py file back.
  6. prompt the workflow again, it works

There may be some other way to solve the problem.

how to chang defs__init_.py file ,i had same problem

我觉得他的意思大概是,随便写点什么,让comfui启动报错。

你配置的IPAdapterPlus插件是可以工作了吗

@superfruitymusic
Copy link

superfruitymusic commented Jan 16, 2024

You are right, it is related to insightface package importing. I have changed the code of IPAdapterPlus.py. First and # to line from 457 to 460. And add "from insightface.app import FaceAnalysis" to top of the code

def load_insight_face(self, provider):
# try:
# from insightface.app import FaceAnalysis
# except ImportError:
# raise Exception('IPAdapter: InsightFace is not installed! Install the missing dependencies if you wish to use FaceID models.')

worked for me as well, thanks 🙏 IP-Adapter && Reactor both work in the same flow with this fix.

For others with same problem, trying to clarify what is meant: Find this method def load_insight_face(self, provider): in IPAdapterPlus.py and add # in front of the first 4 lines, like mentioned above. Note It might not be lines 457 to 460, depending on your version - doesnt matter.

Then change top of the file to be like this:

import torch
import contextlib
import os
import math
from insightface.app import FaceAnalysis

Then restart ComfyUI and error should be gone.

@xiaohaihui-smart
Copy link

You are right, it is related to insightface package importing. I have changed the code of IPAdapterPlus.py. First and # to line from 457 to 460. And add "from insightface.app import FaceAnalysis" to top of the code

def load_insight_face(self, provider):
# try:
# from insightface.app import FaceAnalysis
# except ImportError:
# raise Exception('IPAdapter: InsightFace is not installed! Install the missing dependencies if you wish to use FaceID models.')

worked for me as well, thanks 🙏 IP-Adapter && Reactor both work in the same flow with this fix.

For others with same problem, trying to clarify what is meant: Find this method def load_insight_face(self, provider): in IPAdapterPlus.py and add # in front of the first 4 lines, like mentioned above. Note It might not be lines 457 to 460, depending on your version - doesnt matter.

Then change top of the file to be like this:

import torch
import contextlib
import os
import math
from insightface.app import FaceAnalysis

Then restart ComfyUI and error should be gone.
更改了之后还是报一样的错误,是跟系统环境有关系吗,我用的cuda 11.7 torch 2.0.1 windows系统

@cubiq
Copy link
Owner

cubiq commented Jan 17, 2024

we already have a thread about insightface

#162

moving the import position is not a great solution anyway

@cubiq cubiq closed this as completed Jan 17, 2024
Gourieff added a commit to Gourieff/comfyui-reactor-node that referenced this issue Jan 27, 2024
@Gourieff
Copy link

Gourieff commented Jan 28, 2024

Hi @cubiq
Fixed from my side!
FaceID + ReActor work fine now, without any conflicts!

@chlowden
Copy link

@Gourieff Thank you so much. This is great news.

@weisy11
Copy link

weisy11 commented May 8, 2024

I find a strange workaround for that, but I think it is related to python module importing on Windows.

  1. stop comfyUI.
  2. changing something in "..\ComfyUI_windows_portable\python_embeded\Lib\site-packages\onnx\defs__init__.py" to cause error when initialing.
  3. starting comfyui.
  4. load the face id sample workflow and prompt, you will find error reporting
  5. changing \python_embeded\Lib\site-packages\onnx\defs__init__.py file back.
  6. prompt the workflow again, it works

There may be some other way to solve the problem.

how to chang defs__init_.py file ,i had same problem

我觉得他的意思大概是,随便写点什么,让comfui启动报错。

你配置的IPAdapterPlus插件是可以工作了吗

Add
from insightface.app import FaceAnalysis
at the top of main.py of ComfyUI will solve the problem. You should import FaceAnalysis first, then other modules which have conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests