Skip to content

Commutative rules for DNN subgraphs fusion#24483

Merged
asmorkalov merged 14 commits intoopencv:4.xfrom
dkurt:dnn_fusion_commutative_ops
Nov 8, 2023
Merged

Commutative rules for DNN subgraphs fusion#24483
asmorkalov merged 14 commits intoopencv:4.xfrom
dkurt:dnn_fusion_commutative_ops

Conversation

@dkurt
Copy link
Copy Markdown
Member

@dkurt dkurt commented Nov 2, 2023

Pull Request Readiness Checklist

related: #24463 (comment)

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • 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

@dkurt dkurt force-pushed the dnn_fusion_commutative_ops branch from bfe0b32 to fc640ad Compare November 3, 2023 12:30
@dkurt dkurt marked this pull request as ready for review November 3, 2023 14:29
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.

Overall looks good to me. I plan to work on a test for subgraph fusion this weekend (load a net and see whether it can be simplified to the expected dnn layer). Could you wait a bit for that?

@fengyuentau
Copy link
Copy Markdown
Member

Also note this warning:

/build/precommit_linux64/4.x/opencv/modules/dnn/src/graph_simplifier.hpp:48:25: warning: inline function 'virtual bool cv::dnn::ImportGraphWrapper::isCommutativeOp(const string&) const' used but never defined

@dkurt
Copy link
Copy Markdown
Member Author

dkurt commented Nov 3, 2023

@fengyuentau , sure, thanks!

@fengyuentau
Copy link
Copy Markdown
Member

a test for subgraph fusion

While I am making this, I found there are two patterns for softplus, which can be merged into one in this PR:

class SoftplusSubgraph: public Subgraph
{
public:
SoftplusSubgraph()
{
int input = addNodeToMatch("");
int exp = addNodeToMatch("Exp", input);
int addVal = addNodeToMatch("");
int add = addNodeToMatch("Add", addVal, exp);
addNodeToMatch("Log", add);
setFusedNode("Softplus", input);
}
};
class SoftplusSubgraph2: public Subgraph
{
public:
SoftplusSubgraph2()
{
int input = addNodeToMatch("");
int exp = addNodeToMatch("Exp", input);
int addVal = addNodeToMatch("");
int add = addNodeToMatch("Add", exp, addVal);
addNodeToMatch("Log", add);
setFusedNode("Softplus", input);
}
};

The only difference of these two subgraphs is

         int add = addNodeToMatch("Add", addVal, exp); 

         int add = addNodeToMatch("Add", exp, addVal); 

@dkurt dkurt force-pushed the dnn_fusion_commutative_ops branch from 18bb307 to 6b9b1e8 Compare November 7, 2023 19:34
@dkurt dkurt requested a review from fengyuentau November 7, 2023 19:38
@fengyuentau
Copy link
Copy Markdown
Member

These warnings from default Win64 are not related to changes in this PR:

C:\build\precommit_windows64\4.x\opencv\modules\videoio\test\test_gstreamer.cpp(193): warning C4244: 'initializing': conversion from 'int' to 'float', possible loss of data [C:\build\precommit_windows64\build\modules\videoio\opencv_test_videoio.vcxproj]
C:\build\precommit_windows64\4.x\opencv\modules\videoio\test\test_gstreamer.cpp(193): warning C4244: 'initializing': conversion from 'int' to 'const float', possible loss of data [C:\build\precommit_windows64\build\modules\videoio\opencv_test_videoio.vcxproj]

@asmorkalov asmorkalov added this to the 4.9.0 milestone Nov 8, 2023
@asmorkalov asmorkalov merged commit b7ec2eb into opencv:4.x Nov 8, 2023
IskXCr pushed a commit to Haosonn/opencv that referenced this pull request Dec 20, 2023
Commutative rules for DNN subgraphs fusion opencv#24483

### Pull Request Readiness Checklist

related: opencv#24463 (comment)

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
thewoz pushed a commit to thewoz/opencv that referenced this pull request Jan 4, 2024
Commutative rules for DNN subgraphs fusion opencv#24483

### Pull Request Readiness Checklist

related: opencv#24463 (comment)

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
@asmorkalov asmorkalov mentioned this pull request Jan 19, 2024
thewoz pushed a commit to thewoz/opencv that referenced this pull request May 29, 2024
Commutative rules for DNN subgraphs fusion opencv#24483

### Pull Request Readiness Checklist

related: opencv#24463 (comment)

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants