Skip to content

dnn: fix inconsistent input dtype for nary eltwise layers#24386

Merged
asmorkalov merged 9 commits intoopencv:4.xfrom
fengyuentau:fix_dtype_nary_eltwise
Oct 13, 2023
Merged

dnn: fix inconsistent input dtype for nary eltwise layers#24386
asmorkalov merged 9 commits intoopencv:4.xfrom
fengyuentau:fix_dtype_nary_eltwise

Conversation

@fengyuentau
Copy link
Copy Markdown
Member

Resolves #24385
Merge with opencv/opencv_extra#1107
Relates #24092 (comment)

Pull Request Readiness Checklist

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

@vpisarev
Copy link
Copy Markdown
Contributor

@opencv-alalek, the label "test" means what here? The new test was added that tests the case

@fengyuentau
Copy link
Copy Markdown
Member Author

@dkurt Looks like a lot problems occur after the latest commit.

@opencv-alalek
Copy link
Copy Markdown
Contributor

@opencv-alalek, the label "test" means what here? The new test was added that tests the case

There are 2 labels: "test" (PR includes appropriate test) / "pr: needs test" (test is required for new functionality / bugfix)

@dkurt
Copy link
Copy Markdown
Member

dkurt commented Oct 11, 2023

@fengyuentau, there is one failed test [ FAILED ] DNNTestNetwork.CRNN/0, where GetParam() = OCV/CPU which refers to Concat layer:

[ RUN      ] DNNTestNetwork.CRNN/0, where GetParam() = OCV/CPU
[ERROR:0@32.375] global onnx_importer.cpp:1029 handleNode DNN/ONNX: ERROR during processing node with 2 inputs and 1 outputs: [Concat]:(onnx_node!Concat_46) from domain='ai.onnx'
/home/ci/opencv/modules/ts/src/ts_perf.cpp:1965: Failure
Failed
Expected: PerfTestBody() doesn't throw an exception.
  Actual: it throws cv::Exception:
  OpenCV(4.8.0-dev) /home/ci/opencv/modules/dnn/src/onnx/onnx_importer.cpp:1051: error: (-2:Unspecified error) in function 'handleNode'
> Node [Concat@ai.onnx]:(onnx_node!Concat_46) parse error: OpenCV(4.8.0-dev) /home/ci/opencv/modules/dnn/src/onnx/onnx_importer.cpp:386: error: (-213:The function/feature is not implemented) Mixed input data types. in function 'runLayer'

@fengyuentau
Copy link
Copy Markdown
Member Author

There are more in the "Accuracy: dnn" category:

[  FAILED  ] 5 tests, listed below:
[  FAILED  ] Test_Int8_layers.Reshape/0, where GetParam() = OCV/CPU
[  FAILED  ] Test_ONNX_layers.Convolution_variable_weight_bias/0, where GetParam() = OCV/CPU
[  FAILED  ] Test_ONNX_layers.DynamicReshape/0, where GetParam() = OCV/CPU
[  FAILED  ] Test_ONNX_layers.CalculatePads/0, where GetParam() = OCV/CPU
[  FAILED  ] Test_ONNX_layers.Conv1d_variable_weight_bias/0, where GetParam() = OCV/CPU

@dkurt
Copy link
Copy Markdown
Member

dkurt commented Oct 11, 2023

The reason is the same - "Mixed input data types". So can you please determine what actually data types are passed to Concat?

@fengyuentau
Copy link
Copy Markdown
Member Author

Mixed input data types

image

The left two inputs of Concat is CV_32S, while the right input of Concat is CV_32F with this patch. Maybe we should do the type convertion in runtime instead of importing stage.

@fengyuentau
Copy link
Copy Markdown
Member Author

fengyuentau commented Oct 11, 2023

Mixed input data types

image The left two inputs of Concat is `CV_32S`, while the right input of Concat is `CV_32F` with this patch. Maybe we should do the type convertion in runtime instead of importing stage.

Update:

Runtime type convertion does not work. I did some type checks in const_layer.cpp with the new test case,

std::vector<Mat> outputs;
outputs_arr.getMatVector(outputs);
blobs[0].copyTo(outputs[0]);

tried to print the type of outputs[0] before and after blobs[0].copyTo, and found that outputs[0] did change to CV_32S after, but its type is somehow cast to CV_32F in the forward in nary_eltwise_layer.cpp.


Another update:

Trying a type conversion in const layer in runtime.

@fengyuentau fengyuentau changed the title dnn: fix incorrect input dtype in nary eltwise layers dnn: fix incorrect input dtype for nary eltwise layers Oct 12, 2023
Copy link
Copy Markdown
Member

@dkurt dkurt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@fengyuentau fengyuentau changed the title dnn: fix incorrect input dtype for nary eltwise layers dnn: fix inconsistent input dtype for nary eltwise layers Oct 13, 2023
asmorkalov pushed a commit to opencv/opencv_extra that referenced this pull request Oct 13, 2023
Merge with opencv/opencv#24386

Also noted that random seed is added in this pr, so previous data is regenerated to keep consistency.
@asmorkalov asmorkalov merged commit 0507043 into opencv:4.x Oct 13, 2023
@fengyuentau fengyuentau deleted the fix_dtype_nary_eltwise branch October 13, 2023 09:01
@asmorkalov asmorkalov mentioned this pull request Oct 17, 2023
IskXCr pushed a commit to Haosonn/opencv that referenced this pull request Dec 20, 2023
dnn: fix inconsistent input dtype for nary eltwise layers opencv#24386

Resolves opencv#24385
Merge with opencv/opencv_extra#1107
Relates opencv#24092 (comment)

### 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
thewoz pushed a commit to thewoz/opencv that referenced this pull request Jan 4, 2024
dnn: fix inconsistent input dtype for nary eltwise layers opencv#24386

Resolves opencv#24385
Merge with opencv/opencv_extra#1107
Relates opencv#24092 (comment)

### 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
thewoz pushed a commit to thewoz/opencv that referenced this pull request May 29, 2024
dnn: fix inconsistent input dtype for nary eltwise layers opencv#24386

Resolves opencv#24385
Merge with opencv/opencv_extra#1107
Relates opencv#24092 (comment)

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dnn: inconsistant input data type for element-wise layers

5 participants