Conversation
replace with ONNX model
fengyuentau
left a comment
There was a problem hiding this comment.
Thank you for the contribution! Please take a look at the comments below.
models/dehaze_maxim/demo.py
Outdated
| from maxim import MAXIM | ||
| import cv2 as cv | ||
| import numpy as np | ||
| from PIL import Image |
There was a problem hiding this comment.
Please, use opencv for all image processing and display
There was a problem hiding this comment.
Thanks for your reply! I have replace all commands that used PIL.Image with opencv function :)
|
|
||
| def _create_maxim_model(self): | ||
| print("Loading model....") | ||
| self.model = ort.InferenceSession(self._modelPath) |
There was a problem hiding this comment.
Did you try loading this model and inference with opencv? This zoo is intended to provide models work with opencv.
There was a problem hiding this comment.
Thanks so much for pointing this out. However, when I tried use cv2.dnn.readNetFromONNX() or cv2.dnn.readNet(). It raise an error below:
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 [Gather@ai.onnx]:(onnx_node!jax2tf_predict_/MAXIM/jit__resize_/GatherV2_2) parse error: OpenCV(4.6.0) /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/onnx/onnx_importer.cpp:2907: error: (-215:Assertion failed) indexMat.total() == 1 in function 'parseGather'
`
Could you be so kind to give me any advice on how to solve it?
Many thanks!
There was a problem hiding this comment.
- Simplify the model using onnxsim, try to load using OpenCV
- If problem persists, have a try with last OpenCV: pip install opencv-python-rolling.
If problem still persists, we will need a fix in the opencv source code.
There was a problem hiding this comment.
Thanks a lot for your very fast reply!
- The ONNX model I tried before is already simplified. However, in case it's not, I re-run onnxsim for it.
- and install the last OpenCV pip install opencv-python-rolling. make sure get the successful message below:
Successfully installed opencv-python-rolling-4.6.0.20220820
After that the same error msg still persists. In case it helps, I attached the full error msg below.
Many thanks again!
[ERROR:0@16.068] global /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/onnx/onnx_importer.cpp (1044) handleNode DNN/ONNX: ERROR during processing node with 2 inputs and 1 outputs: [Gather]:(onnx_node!jax2tf_predict_/MAXIM/jit__resize_/GatherV2_2) from domain='ai.onnx'
Traceback (most recent call last):
File "/Users/lyn/Github/opencv_zoo/models/dehaze_maxim/demo.py", line 21, in
model = MAXIM(modelPath=args.model,
File "/Users/lyn/Github/opencv_zoo/models/dehaze_maxim/maxim.py", line 85, in init
self._create_maxim_model()
File "/Users/lyn/Github/opencv_zoo/models/dehaze_maxim/maxim.py", line 101, in create_maxim_model
self.model = cv.dnn.readNetFromONNX(self.modelPath)
cv2.error: OpenCV(4.6.0-dev) /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/onnx/onnx_importer.cpp:1063: error: (-2:Unspecified error) in function 'handleNode'
Node [Gather@ai.onnx]:(onnx_node!jax2tf_predict/MAXIM/jit__resize/GatherV2_2) parse error: OpenCV(4.6.0-dev) /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/onnx/onnx_importer.cpp:2645: error: (-215:Assertion failed) indexMat.total() == 1 in function 'parseGather'
There was a problem hiding this comment.
parse error: OpenCV(4.6.0-dev) /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/onnx/onnx_importer.cpp:2645: error: (-215:Assertion failed) indexMat.total() == 1 in function 'parseGather'
Looks like we have a problem parsing the gather op in opencv. You can try solving it or wait a bit for my fix if possible.
There was a problem hiding this comment.
Thanks a lot! And apologize for the late reply, I was a bit busy after term start. I tried to install opencv-python-rolling-5.0.0.20220924 . Unfortunately, the same error persists.
There was a problem hiding this comment.
Updates are not forwarded to 5.x yet. So please have a try with latest 4.6: pip install “opencv-python-rolling<5.0”
There was a problem hiding this comment.
Thanks a lot for your help! I tried with 4.6. The error mentioned above was solved then.
But, there's a new error appears, which seems like opencv does not support the op 'GreaterOrEqual' currently.
`[ERROR:0@18.681] global /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/onnx/onnx_importer.cpp (1019) handleNode DNN/ONNX: ERROR during processing node with 2 inputs and 1 outputs: [GreaterOrEqual]:(onnx_node!jax2tf_predict_/MAXIM/stage_0_encoder_block_0/channel_attention_block_10/jit_leaky_relu_/GreaterEqual) from domain='ai.onnx'
Traceback (most recent call last):
File "demo.py", line 21, in
model = MAXIM(modelPath=args.model,
File "/Users/lyn/Library/Mobile Documents/comappleCloudDocs/.Trash/opencv_zoo 3/models/dehaze_maxim/maxim.py", line 85, in init
self._create_maxim_model()
File "/Users/lyn/Library/Mobile Documents/comappleCloudDocs/.Trash/opencv_zoo 3/models/dehaze_maxim/maxim.py", line 101, in _create_maxim_model
self.model = cv.dnn.readNetFromONNX(self._modelPath)
cv2.error: OpenCV(4.6.0-dev) /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/onnx/onnx_importer.cpp:1038: error: (-2:Unspecified error) in function 'handleNode'
Node [GreaterOrEqual@ai.onnx]:(onnx_node!jax2tf_predict_/MAXIM/stage_0_encoder_block_0/channel_attention_block_10/jit_leaky_relu_/GreaterEqual) parse error: OpenCV(4.6.0-dev) /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/layer_internals.hpp:110: error: (-2:Unspecified error) Can't create layer "onnx_node!jax2tf_predict_/MAXIM/stage_0_encoder_block_0/channel_attention_block_10/jit_leaky_relu_/GreaterEqual" of type "GreaterOrEqual" in function 'getLayerInstance'
`
There was a problem hiding this comment.
opencv/opencv#22611 for supporting GreaterOrEqual has been merged. Please have a try after this Saturday. Install with pip install "opencv-python-rolling<5.0", the suffix should be 20221015.
There was a problem hiding this comment.
Thanks for reminder :) The new version did solve the previous problem. I encountered another problem then.
[ERROR:0@15.250] global /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/onnx/onnx_importer.cpp (1050) handleNode DNN/ONNX: ERROR during processing node with 2 inputs and 1 outputs: [Gemm]:(onnx_node!Gemm__9265) from domain='ai.onnx'
Traceback (most recent call last):
File "demo.py", line 21, in
model = MAXIM(modelPath=args.model,
File "/Users/lyn/Documents/opencv_zoo_20221022/models/dehaze_maxim/maxim.py", line 85, in init
self._create_maxim_model()
File "/Users/lyn/Documents/opencv_zoo_20221022/models/dehaze_maxim/maxim.py", line 101, in _create_maxim_model
self.model = cv.dnn.readNetFromONNX(self._modelPath)
cv2.error: OpenCV(4.6.0-dev) /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/onnx/onnx_importer.cpp:1069: error: (-2:Unspecified error) in function 'handleNode'
Node [Gemm@ai.onnx]:(onnx_node!Gemm__9265) parse error: OpenCV(4.6.0-dev) /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/onnx/onnx_importer.cpp:587: error: (-5:Bad argument) Blob Reshape__9264:0 not found in const blobs in function 'getBlob'
i left it until today since it seems not like a problem in the source code and I was distracted by my university courses. Apologize for the delay! Any suggestions at this stage would be helpful!
|
@yunongLiu1 friendly reminder |
Hi~ below is the info for this pull request:
Contributor: Yunong Liu
Model: MAXIM: Multi-Axis MLP for Image Processing (CVPR 2022 Oral)
Checklist: