Skip to content

Add model maxim for dehaze#82

Closed
yunongLiu1 wants to merge 19 commits intoopencv:masterfrom
yunongLiu1:master
Closed

Add model maxim for dehaze#82
yunongLiu1 wants to merge 19 commits intoopencv:masterfrom
yunongLiu1:master

Conversation

@yunongLiu1
Copy link
Copy Markdown

@yunongLiu1 yunongLiu1 commented Aug 15, 2022

Hi~ below is the info for this pull request:

Contributor: Yunong Liu
Model: MAXIM: Multi-Axis MLP for Image Processing (CVPR 2022 Oral)

Checklist:

  • MAXIM ONNX model
  • Simplified the ONNX model using onnx-simplifier
  • demo.py & maxim.py
  • License
  • ReadMe
  • Sample Images and Results
  • A yaml config
  • The quantized model.

@yunongLiu1 yunongLiu1 marked this pull request as ready for review August 15, 2022 21:49
Copy link
Copy Markdown
Member

@fengyuentau fengyuentau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution! Please take a look at the comments below.

from maxim import MAXIM
import cv2 as cv
import numpy as np
from PIL import Image
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use opencv for all image processing and display

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try loading this model and inference with opencv? This zoo is intended to provide models work with opencv.

Copy link
Copy Markdown
Author

@yunongLiu1 yunongLiu1 Aug 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Simplify the model using onnxsim, try to load using OpenCV
  2. 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updates are not forwarded to 5.x yet. So please have a try with latest 4.6: pip install “opencv-python-rolling<5.0”

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'
`

Copy link
Copy Markdown
Member

@fengyuentau fengyuentau Oct 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

@yunongLiu1 yunongLiu1 Nov 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@fengyuentau
Copy link
Copy Markdown
Member

@yunongLiu1 friendly reminder

@fengyuentau fengyuentau added the stale Issues or PRs marked as stale will be closed in 7 days label Mar 14, 2023
@fengyuentau fengyuentau closed this Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add model request to add a new model stale Issues or PRs marked as stale will be closed in 7 days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants