GSoC Add ONNX Support for GatherElements#1082
Conversation
testdata/dnn/download_models.py
Outdated
| models = [ | ||
| Model( | ||
| name='RAFT', | ||
| url='https://drive.google.com/u/0/uc?id=1yWIbF4birkpZMhNNhqzy75d4EvJW-UXE&export=download', |
There was a problem hiding this comment.
Please share a source of that link in comment (i.e. origin repository)
There was a problem hiding this comment.
The model is sourced from here https://github.com/Aser-Abdelfatah/opencv_zoo/tree/gsoc_RAFT_Model_ONNX/models/optical_flow_estimation_raft
There was a problem hiding this comment.
I mean it there an officially distributed model? There is a little chance that custom file will be available for a long time.
There was a problem hiding this comment.
This share link is actually from the opencv.org google drive. I uploaded it to OpenCV Shared -> Deep Models if you have access to it.
Source of the model is from https://github.com/PINTO0309/PINTO_model_zoo/tree/main/252_RAFT, where it uses external cloud drive called wasabi stoarge.
There was a problem hiding this comment.
Too big file. What are the data type and dimensions?
dkurt
left a comment
There was a problem hiding this comment.
input_RAFT_0.npy and input_RAFT_1.npy sizes too big
|
Could you use one of the existing image in this repo, such as https://github.com/opencv/opencv_extra/blob/4.x/testdata/dnn/dog_orig_size.png? You can resize it to the target scale, run inference, then collect the corresponding output, so that the total size can be cut by half, which passes the limit check. |
Sorry for getting back late to this. Since it's an optical flow model, the input should be two images. I can use the same image twice for both inputs, but it wouldn't really make much sense. Another approach would be finding two lightweight images, but a question is what is the limit check? |
|
@Aser-Abdelfatah, you may use images from https://github.com/opencv/opencv_extra/tree/4.x/testdata/gpu/opticalflow. Preprocess them in runtime. |
|
@dkurt I didn't get the part about pre-processing in runtime. The testing code in opencv/modules/dnn/test/test_onnx_importer.cpp is essentially,
|
|
And sorry for keeping getting back late to this. The time difference is crazy |
So you can do the same in C++ - imread two images and preprocess using OpenCV methods. |
|
I'm struggling with the C++ implementation. Essentially, I can't find a way to export the 4-dimensional opencv Mat to npy file in C++. |
|
You can do it in Python with OpenCV and NumPy. import cv2 as cv
import numpy as np
img1 = cv.imread("/path/to/img1")
img2 = cv.imread("/path/to/img2")
import onnxruntime as ort
net = ort.InferenceSession("/path/to/raft/model")
output = net.run(["output_name"], {"input1_name": img1, "input2_name": img2})
np.save("output_file_name.npy", output[0])Maybe you need to debug a little bit to run the code above, but it should be mostly correct. |
|
I did it before. The problem is that the resulting npy file is also 2 mega bytes |
|
2MB is fine. IIRC, the limit is 3MB. |
@fengyuentau, this is not fine. The preprocessing might be done in C++ without any issues. Such 2MB will be added to git history forever.
@Aser-Abdelfatah, share Python implementation for preprocessing. Show how .npy are saved so we can propose an alternative C++ impl. |
|
How is it possible to test model accuracy if the output reference is not preserved in this repository? What I am saying is we don't need to check the exact correct results as what common users expect, we don't need to perform preprocessings to make results correct and meaningful. Just put two input images that has the input scale that the model requires, save outputs as a npy file, put the output file here, and thats it. |
|
There is no problem with output - it takes just 21Kb (see
No need to add preprocessed input .npy to this PR. |
|
Sorry, seems like there is a misunderstanding. Proposed solution by @fengyuentau at #1082 (comment) is correct. I don't understand what is |
This is the python code for pre-processing, inference, and saving output. The input files are numpy float arrays of dimension (1, 3, 360, 480). The output is an optical flow map not an image. |
|
@Aser-Abdelfatah, thanks! This is C++ function you need to use: Mat image1 = cv::imread("frame0.png");
Mat input1 = cv::dnn::blobFromImage(image1, 1.0, Size(input_width, input_height), Scalar(), true); |
4680481 to
41de2d7
Compare
5ed338a to
127d9f1
Compare
…ments_ONNX GSoC Add ONNX Support for GatherElements #24092 Merge with: opencv/opencv_extra#1082 Adds support to the ONNX operator GatherElements [operator docs](https://github.com/onnx/onnx/blob/main/docs/Operators.md#GatherElements) Added tests to opencv_extra at pull request opencv/opencv_extra#1082 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
…herElements_ONNX GSoC Add ONNX Support for GatherElements opencv#24092 Merge with: opencv/opencv_extra#1082 Adds support to the ONNX operator GatherElements [operator docs](https://github.com/onnx/onnx/blob/main/docs/Operators.md#GatherElements) Added tests to opencv_extra at pull request opencv/opencv_extra#1082 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
…herElements_ONNX GSoC Add ONNX Support for GatherElements opencv#24092 Merge with: opencv/opencv_extra#1082 Adds support to the ONNX operator GatherElements [operator docs](https://github.com/onnx/onnx/blob/main/docs/Operators.md#GatherElements) Added tests to opencv_extra at pull request opencv/opencv_extra#1082 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
…herElements_ONNX GSoC Add ONNX Support for GatherElements opencv#24092 Merge with: opencv/opencv_extra#1082 Adds support to the ONNX operator GatherElements [operator docs](https://github.com/onnx/onnx/blob/main/docs/Operators.md#GatherElements) Added tests to opencv_extra at pull request opencv/opencv_extra#1082 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
Merge with opencv/opencv#24092
This pull request serves as an addition to the pull request "GSoC Add ONNX Support for GatherElements #24092", which is submitted to the original OpenCV repository. It contains three tests to the GatherElements operator.
The three tests are sourced from:
And the models were configured using the code provided by Yuantao Feng at https://github.com/fengyuentau/onnx_utils to confirm output shape in pre-run.
Reference outputs for
optical_flow_estimation_raft_2023aug.onnxis generated with the following script: