deepcam-cn / yolov5-face

YOLO5Face: Why Reinventing a Face Detector (https://arxiv.org/abs/2105.12931) ECCV Workshops 2022)
GNU General Public License v3.0
2.09k stars 500 forks source link

ONNX file generated by export.py cannot be loaded by OpenCV #183

Open WorldTreeBug opened 2 years ago

WorldTreeBug commented 2 years ago
  1. Downloaded yolov5n-face.pt from the following link: https://drive.google.com/file/d/18oenL6tjFkdR1f5IgpYeQfDFqU4w3jEr/view?usp=sharing

  2. Generated onnx file by export.py script

export PYTHONPATH="$PWD" && python export.py --weights weights/yolov5n-face.pt --img 640 --batch 1

  1. Tried to run opencv demo (yolov5-face-landmarks-opencv-v2) using generated onnx file but failed

[ERROR:0@0.287] global /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/onnx/onnx_importer.cpp (1021) handleNode DNN/ONNX: ERROR during processing node with 1 inputs and 1 outputs: [Identity]:(onnx_node!Identity_0) from domain='ai.onnx' Traceback (most recent call last): File "/faceDetection/yolov5-face-landmarks-opencv-v2/main.py", line 114, in <module> yolonet = yolov5(args.yolo_type, confThreshold=args.confThreshold, nmsThreshold=args.nmsThreshold, objThreshold=args.objThreshold) File "/faceDetection/yolov5-face-landmarks-opencv-v2/main.py", line 17, in __init__ self.net = cv2.dnn.readNet(yolo_type+'-face.onnx') cv2.error: OpenCV(4.6.0) /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/onnx/onnx_importer.cpp:1040: error: (-2:Unspecified error) in function 'handleNode' \> Node [Identity@ai.onnx]:(onnx_node!Identity_0) parse error: OpenCV(4.6.0) /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/layer.cpp:246: error: (-215:Assertion failed) inputs.size() in function 'getMemoryShapes'

PS. main_export_onnx.py script from the yolov5-face-landmarks-opencv-v2 demo fails to generate onnx model.

File "/faceDetection/yolov5-face/main_export_onnx.py", line 89, in forward x[0] = x[0].view(-1, self.no) TypeError: 'tuple' object does not support item assignment

vivision1 commented 2 years ago

Having a similar error

[ERROR:0@2.127] global C:/M/mingw-w64-opencv/src/opencv-4.6.0/modules/dnn/src/onnx/onnx_importer.cpp (1018) handleNode DNN/ONNX: ERROR during processing node with 1 inputs and 1 outputs: [Identity]:(onnx_node!Identity_0) from domain='ai.onnx' OpenCV: terminate handler is called! The last OpenCV error is: OpenCV(4.6.0) Error: Unspecified error (> Node [Identity@ai.onnx]:(onnx_node!Identity_0) parse error: OpenCV(4.6.0) C:/M/mingw-w64-opencv/src/opencv-4.6.0/modules/dnn/src/layer.cpp:246: error: (-215:Assertion failed) inputs.size() in function 'getMemoryShapes' ) in handleNode, file C:/M/mingw-w64-opencv/src/opencv-4.6.0/modules/dnn/src/onnx/onnx_importer.cpp, line 1040

HGS-1998 commented 1 year ago
  1. 从以下链接下载 yolov5n-face.pt:https://drive.google.com/file/d/18oenL6tjFkdR1f5IgpYeQfDFqU4w3jEr/view?usp=sharing
  2. 通过脚本生成的 onnx 文件 export.py

export PYTHONPATH="$PWD" && python export.py --weights weights/yolov5n-face.pt --img 640 --batch 1

  1. 尝试使用生成的onnx文件运行opencv演示(yolov5-face-landmarks-opencv-v2),但失败了

[ERROR:0@0.287] global /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/onnx/onnx_importer.cpp (1021) handleNode DNN/ONNX: ERROR during processing node with 1 inputs and 1 outputs: [Identity]:(onnx_node!Identity_0) from domain='ai.onnx' Traceback (most recent call last): File "/faceDetection/yolov5-face-landmarks-opencv-v2/main.py", line 114, in <module> yolonet = yolov5(args.yolo_type, confThreshold=args.confThreshold, nmsThreshold=args.nmsThreshold, objThreshold=args.objThreshold) File "/faceDetection/yolov5-face-landmarks-opencv-v2/main.py", line 17, in __init__ self.net = cv2.dnn.readNet(yolo_type+'-face.onnx') cv2.error: OpenCV(4.6.0) /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/onnx/onnx_importer.cpp:1040: error: (-2:Unspecified error) in function 'handleNode' \> Node [Identity@ai.onnx]:(onnx_node!Identity_0) parse error: OpenCV(4.6.0) /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/layer.cpp:246: error: (-215:Assertion failed) inputs.size() in function 'getMemoryShapes'

来自yolov5-face-landmarks-opencv-v2演示main_export_onnx.py脚本无法生成onnx模型。

File "/faceDetection/yolov5-face/main_export_onnx.py", line 89, in forward x[0] = x[0].view(-1, self.no) TypeError: 'tuple' object does not support item assignment

请问有解决办法吗?我也在这里遇到了问题