opencv/modules
Yuantao Feng bc0618b688
Merge pull request #25582 from fengyuentau:dnn/dump_pbtxt
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 #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
2024-05-17 11:07:05 +03:00
..
calib3d Merge pull request #25308 from dkurt:not_normalized_findHomography 2024-04-29 14:35:14 +03:00
core Merge pull request #25598 from asmorkalov:as/tables_range_check_core 2024-05-17 10:48:40 +03:00
dnn Merge pull request #25582 from fengyuentau:dnn/dump_pbtxt 2024-05-17 11:07:05 +03:00
features2d Merge pull request #25424 from mshabunin:fix-features2d-test 2024-04-17 14:19:05 +03:00
flann Merge pull request #25024 from vrabaud:neon 2024-02-20 11:29:23 +03:00
gapi Disable more streaming test in G-API due to instability. 2024-05-15 15:41:23 +03:00
highgui Restored and extended Highgui test logic for small windows. 2024-05-15 12:47:22 +03:00
imgcodecs Got rid of deprecated convertFp16 in imgcodecs module. 2024-05-03 11:05:08 +03:00
imgproc Merge pull request #25566 from asmorkalov:as/moments_documentation 2024-05-14 17:19:41 +03:00
java doc: fix formulas in JavaDoc broken after Doxygen upgrade 2024-03-11 23:47:23 +03:00
js Merge pull request #25084 from EDVTAZ:emscripten-3.1.54-compat 2024-02-26 10:30:56 +03:00
ml Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
objc Merge pull request #24136 from komakai:visionos_support 2023-12-20 15:35:10 +03:00
objdetect Merge pull request #25378 from AleksandrPanov:move_charuco_tutorial 2024-04-16 12:14:33 +03:00
photo Merge pull request #25402 from Linaname:4.x 2024-04-17 11:26:56 +03:00
python python: adapt test to NumPy 2.x 2024-05-03 20:10:41 +03:00
stitching Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
ts Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
video Merge pull request #25092 from klatism:libjpeg-upgrade 2024-03-28 17:03:05 +03:00
videoio videoio: decreased log level for failed backends in VideoCapture and VideoWriter open 2024-05-06 20:48:17 +03:00
world cmake: use /INCREMENTAL:NO with MSVS 2015 2023-12-07 19:46:27 +00:00