-
-
Notifications
You must be signed in to change notification settings - Fork 55.6k
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
dnn: better net exporter that works with netron #25582
Conversation
Here is one example I get from this patch models.zip. They all can be opened with Netron. Note that I did not test other models. |
I propose to add dump call to |
Unfortunately it cannot be added to However, we can add option in the app asking for the input dimension and then we can call the new exporter to get the graph. In this case, I need |
@fengyuentau Let's extend the tool or add the call to some generic sample. It'll be great to have the option available without codding. It helps to triage incoming issues. |
I mean we can extend the tool only after we figure out how to set the input for the net. Current
Do you mean existing ones in |
I propose to add several cmdline options line |
Ok. Although this is not a perfact solution, it can satisfy most of our needs. |
@asmorkalov It is implemented. It works as follows ./build/bin/opencv_model_diagnostics -model=/workspace/opencv_zoo/models/face_detection_yunet/face_detection_yunet_2023mar.onnx -input0_name=input -input0_shape=1,3,640,640 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Current net exporter `dump` and `dumpToFile` exports the network structure (and its params) to a .dot file which works with `graphviz`. This is hard to use and not friendly to new user. What's worse, the produced picture is not looking pretty. dnn: better net exporter that works with netron opencv#25582 This PR introduces new exporter `dumpToPbtxt` and uses this new exporter by default with environment variable `OPENCV_DNN_NETWORK_DUMP`. It mimics the string output of a onnx model but modified with dnn-specific changes, see below for an example. ![image](https://github.com/opencv/opencv/assets/17219438/0644bed1-da71-4019-8466-88390698e4df) ## Usage Call `cv::dnn::Net::dumpToPbtxt`: ```cpp TEST(DumpNet, dumpToPbtxt) { std::string path = "/path/to/model.onnx"; auto net = readNet(path); Mat input(std::vector<int>{1, 3, 640, 480}, CV_32F); net.setInput(input); net.dumpToPbtxt("yunet.pbtxt"); } ``` Set `export OPENCV_DNN_NETWORK_DUMP=1` ```cpp TEST(DumpNet, env) { std::string path = "/path/to/model.onnx"; auto net = readNet(path); Mat input(std::vector<int>{1, 3, 640, 480}, CV_32F); net.setInput(input); net.forward(); } ``` --- Note: - `pbtxt` is registered as one of the ONNX model suffix in netron. So you can see `module: ai.onnx` and such in the model. - We can get the string output of an ONNX model with the following script ```python import onnx net = onnx.load("/path/to/model.onnx") net_str = str(net) file = open("/path/to/model.pbtxt", "w") file.write(net_str) file.close() ``` ### 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 - [ ] There is a reference to the original bug report and related work - [ ] 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
Current net exporter
dump
anddumpToFile
exports the network structure (and its params) to a .dot file which works withgraphviz
. This is hard to use and not friendly to new user. What's worse, the produced picture is not looking pretty.This PR introduces new exporter
dumpToPbtxt
and uses this new exporter by default with environment variableOPENCV_DNN_NETWORK_DUMP
. It mimics the string output of a onnx model but modified with dnn-specific changes, see below for an example.Usage
Call
cv::dnn::Net::dumpToPbtxt
:Set
export OPENCV_DNN_NETWORK_DUMP=1
Note:
pbtxt
is registered as one of the ONNX model suffix in netron. So you can seemodule: ai.onnx
and such in the model.Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.