Skip to content

Support ONNX operator QLinearSoftmax in dnn#23655

Merged
asmorkalov merged 8 commits intoopencv:4.xfrom
fengyuentau:qlinearsoftmax
May 25, 2023
Merged

Support ONNX operator QLinearSoftmax in dnn#23655
asmorkalov merged 8 commits intoopencv:4.xfrom
fengyuentau:qlinearsoftmax

Conversation

@fengyuentau
Copy link
Copy Markdown
Member

@fengyuentau fengyuentau commented May 22, 2023

Resolves #23636.
Merge with opencv/opencv_extra#1064.

This PR maps the QLinearSoftmax (from com.microsoft domain) to SoftmaxInt8 in dnn along with some speed optimization.

Todo:

  • support QLinearSoftmax with opset = 13
  • add model and test data for QLinearSoftmax with opset = 13
  • ensure all models have dims >= 3.
  • add the script to generate model and test data

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

@asmorkalov asmorkalov requested review from dkurt and zihaomu May 22, 2023 08:31
@asmorkalov asmorkalov changed the title dnn: support ONNX operator QLinearSoftmax WIP: support ONNX operator QLinearSoftmax in dnn May 23, 2023
TEST_P(Test_ONNX_layers, QLinearSoftmax)
{
// threshold is set for fusion with dequantization
testONNXModels("qlinearsoftmax_11", npy, 0.001, 0.002);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this test cover all 4 scenarios?

SoftmaxInt8Invoker<true>::run(src, dst, blobs[0], N, D, output_sc, output_zp);
SoftmaxInt8Invoker<false>::run(src, dst, blobs[0], N, D, output_sc, output_zp);
SoftmaxInt8OutputFloatInvoker<true>::run(src, dst, blobs[0], N, D);
SoftmaxInt8OutputFloatInvoker<false>::run(src, dst, blobs[0], N, D);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This test does not cover log softmax, but it is tested by the existing test Test_Int8_layers.Softmax_log_ONNX/0 instead.

The model architecture of this test is like [input]->QuantizeLinear -> QLinearSoftmax -> DequantizeLinear -> [output]. Since we have tryFuse in SoftmaxInt8 which fuses DequantizeLinear and therefore we have output in float instead of int8 in the end, SoftmaxInt8OutputFloatInvoker<false>::run(...) is triggered here in the test. I tested locally with tryFuse disabled which triggers SoftmaxInt8Invoker<false>::run(...) and it passes. Do you think it necessary to add another test case for int8 output like [input] -> QLinearSoftmax -> [output]?

@fengyuentau fengyuentau changed the title WIP: support ONNX operator QLinearSoftmax in dnn Support ONNX operator QLinearSoftmax in dnn May 24, 2023
@fengyuentau
Copy link
Copy Markdown
Member Author

All todo items are clear. Please review if possible.

@fengyuentau fengyuentau added this to the 4.8.0 milestone May 24, 2023
@asmorkalov asmorkalov merged commit f07b01c into opencv:4.x May 25, 2023
@fengyuentau fengyuentau deleted the qlinearsoftmax branch May 31, 2023 06:12
@asmorkalov asmorkalov mentioned this pull request May 31, 2023
thewoz pushed a commit to thewoz/opencv that referenced this pull request Jan 4, 2024
Support ONNX operator QLinearSoftmax in dnn opencv#23655

Resolves opencv#23636.
Merge with opencv/opencv_extra#1064.

This PR maps the QLinearSoftmax (from com.microsoft domain) to SoftmaxInt8 in dnn along with some speed optimization.

Todo:
- [x] support QLinearSoftmax with opset = 13
- [x] add model and test data for QLinearSoftmax with opset = 13
- [x] ensure all models have dims >= 3.
- [x] add the script to generate model and test data 

### 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
@fengyuentau fengyuentau mentioned this pull request Feb 21, 2024
48 tasks
thewoz pushed a commit to thewoz/opencv that referenced this pull request May 29, 2024
Support ONNX operator QLinearSoftmax in dnn opencv#23655

Resolves opencv#23636.
Merge with opencv/opencv_extra#1064.

This PR maps the QLinearSoftmax (from com.microsoft domain) to SoftmaxInt8 in dnn along with some speed optimization.

Todo:
- [x] support QLinearSoftmax with opset = 13
- [x] add model and test data for QLinearSoftmax with opset = 13
- [x] ensure all models have dims >= 3.
- [x] add the script to generate model and test data 

### 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.

SoftmaxInt8 is implemented but ONNX importer does not parse QLinearSoftmax

4 participants