Added PyTorch fcnresnet101 segmentation conversion cases #24397
Added PyTorch fcnresnet101 segmentation conversion cases #24397asmorkalov merged 11 commits intoopencv:4.xfrom richard28039:add_fcnresnet101_to_dnn_sample
Conversation
samples/dnn/dnn_model_runner/dnn_conversion/pytorch/segmantation/pytorch_fcnresnet101.py
Outdated
Show resolved
Hide resolved
samples/dnn/dnn_model_runner/dnn_conversion/pytorch/segmantation/data/cat_and_bike.jpg
Outdated
Show resolved
Hide resolved
samples/dnn/models.yml
Outdated
| width: 500 | ||
| height: 500 | ||
| rgb: false | ||
| classes: "object_detection_classes_pascal_voc.txt" |
There was a problem hiding this comment.
Please add an image with resulting segmentation from a sample launch. I have a concern that classes might be 1 position shifted (depends on background id).
So please run a sample on an image with more that one segmented object and put to PR description or in this thread,
There was a problem hiding this comment.
Hello @dkurt , I think your concern is right, the background classes might have to be add.
Should I add background class to https://github.com/opencv/opencv/blob/4.x/samples/data/dnn/object_detection_classes_pascal_voc.txt ?
There was a problem hiding this comment.
Thanks, problem should be solved in a common.py script which will affect other samples so I'd like to merge this PR as is.
There was a problem hiding this comment.
I got it, thank you!
asmorkalov
left a comment
There was a problem hiding this comment.
python3 ./segmentation.py fcnresnet101
[ WARN:0@0.019] global samples.cpp:61 findFile cv::samples::findFile('object_detection_classes_pascal_voc.txt') => ''
[ERROR:0@0.332] global onnx_importer.cpp:2441 parseShape DNN/ONNX(Shape): dynamic 'zero' shapes are not supported, input input [ 0 3 0 0 ]
[ERROR:0@0.332] global onnx_importer.cpp:1033 handleNode DNN/ONNX: ERROR during processing node with 1 inputs and 1 outputs: [Shape]:(onnx_node!Shape_0) from domain='ai.onnx'
Traceback (most recent call last):
File "./segmentation.py", line 83, in <module>
net = cv.dnn.readNet(args.model, args.config, args.framework)
cv2.error: OpenCV(4.8.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/onnx/onnx_importer.cpp:1052: error: (-2:Unspecified error) in function 'handleNode'
> Node [Shape@ai.onnx]:(onnx_node!Shape_0) parse error: OpenCV(4.8.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/onnx/onnx_importer.cpp:2442: error: (-215:Assertion failed) !isDynamicShape in function 'parseShape'
>
What do I do wrong?
|
With related patch from @dkurt (DNN graph fusion with shared nodes): |
|
@asmorkalov, can confirm, let me check. UPD: solved by cc40308 |
|
I can confirm that fix from @dkurt works. The sample works properly, if I add "background" to the beggining of I propose to force add background in the sample code if len(classes) - len(colors) = 1 |
|
@dkurt on the background question about object_detection_classes_pascal_voc.txt , the problem should be solved in a common.py in another pr as you originally said, or should I modify it in the way that @asmorkalov propose, thank you! |
|
I propose to add the hack to current PR, because the sample just crashed in default configuration. Python part may be modified in a separate PR. |
|
@richard28039, there are two ways to avoid crash: 1) temporary add "backdround" label to the classes array 2) remove |
|
Hello, I removed the |
DNN graph fusion with shared nodes #24463 ### Pull Request Readiness Checklist For now, nodes from matched pattern are removed during the matching process so if nodes are used in similar subgraph, they cannot be found. required for #24397 **Merge with extra**: opencv/opencv_extra#1115 A part from [model_name ](https://github.com/onnx/models/blob/main/vision/object_detection_segmentation/fcn/model/fcn-resnet101-11.onnx) with two Resize subgraphs with shared nodes:  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
DNN graph fusion with shared nodes opencv#24463 ### Pull Request Readiness Checklist For now, nodes from matched pattern are removed during the matching process so if nodes are used in similar subgraph, they cannot be found. required for opencv#24397 **Merge with extra**: opencv/opencv_extra#1115 A part from [model_name ](https://github.com/onnx/models/blob/main/vision/object_detection_segmentation/fcn/model/fcn-resnet101-11.onnx) with two Resize subgraphs with shared nodes:  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
…_dnn_sample Added PyTorch fcnresnet101 segmentation conversion cases opencv#24397 We write a sample code about transforming Pytorch fcnresnet101 to ONNX running on OpenCV. The input source image was shooted by ourself. ### 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. - [ ] The feature is well documented and sample code can be built with the project CMake
DNN graph fusion with shared nodes opencv#24463 ### Pull Request Readiness Checklist For now, nodes from matched pattern are removed during the matching process so if nodes are used in similar subgraph, they cannot be found. required for opencv#24397 **Merge with extra**: opencv/opencv_extra#1115 A part from [model_name ](https://github.com/onnx/models/blob/main/vision/object_detection_segmentation/fcn/model/fcn-resnet101-11.onnx) with two Resize subgraphs with shared nodes:  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
…_dnn_sample Added PyTorch fcnresnet101 segmentation conversion cases opencv#24397 We write a sample code about transforming Pytorch fcnresnet101 to ONNX running on OpenCV. The input source image was shooted by ourself. ### 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. - [ ] The feature is well documented and sample code can be built with the project CMake
DNN graph fusion with shared nodes opencv#24463 ### Pull Request Readiness Checklist For now, nodes from matched pattern are removed during the matching process so if nodes are used in similar subgraph, they cannot be found. required for opencv#24397 **Merge with extra**: opencv/opencv_extra#1115 A part from [model_name ](https://github.com/onnx/models/blob/main/vision/object_detection_segmentation/fcn/model/fcn-resnet101-11.onnx) with two Resize subgraphs with shared nodes:  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
…_dnn_sample Added PyTorch fcnresnet101 segmentation conversion cases opencv#24397 We write a sample code about transforming Pytorch fcnresnet101 to ONNX running on OpenCV. The input source image was shooted by ourself. ### 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. - [ ] The feature is well documented and sample code can be built with the project CMake




We write a sample code about transforming Pytorch fcnresnet101 to ONNX running on OpenCV.
The input source image was shooted by ourself.
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.