1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Merge pull request #29079 from varun-jaiswal17:feat/dnn-int8-optimization

dnn int8 optimization #29079

all_layers.hpp 
- Add float_input flag to Conv2Int8Params and Conv2Int8Layer to let the first conv accept raw FP32 input and quantize internally.

graph_fusion_qdq.cpp : 
- Fuse DQ → Sigmoid → QL into SigmoidInt8, Similarly for MAxPool.
- Fuse the input QuantizeLinear node into the first Conv2Int8.

conv2_int8_layer.cpp
- Add quantizeInterleaveBlock()


conv2_int8_kernels.simd.hpp
- Add spatial tiling to both convInt8BlockVNNI and convInt8BlockDepthwise: splits output pixels into tiles so total task count is N × ngroups × Kblk × ntiles, fully utilizing all threads even when the channel count is small.

elementwise_layers.cpp
- Widen CV_Assert to accept CV_8U in addition to CV_8S.

eltwise2_int8_layer.cpp
- Add QLinearMul support: new Mul math path for both signed and unsigned int8.
- Add numpy-style broadcast support so QLinearMul / QLinearAdd with scalar

### 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
This commit is contained in:
Varun Jaiswal
2026-05-26 14:04:47 +05:30
committed by GitHub
parent be2c53c2b7
commit bae8cb1915
7 changed files with 1158 additions and 102 deletions
+13 -3
View File
@@ -5,6 +5,8 @@
#include "test_precomp.hpp"
#include <opencv2/dnn/shape_utils.hpp>
#include "npy_blob.hpp"
#include <map>
#include <set>
namespace opencv_test { namespace {
template<typename TString>
@@ -817,12 +819,20 @@ TEST_P(Reproducibility_ResNet50_QDQ_ONNX, Accuracy)
topK(out, res, K);
ASSERT_EQ(int(res.size()), K);
// Top 4 class's score must be within eps of its reference value.
std::vector<std::pair<int, float> > ref = {{285, 10.44}, {287, 10.13}, {283, 8.89}, {278, 8.43}};
const float eps = 0.5f;
for (int i = 0; i < (int)ref.size(); i++) {
EXPECT_EQ(ref[i].first, res[i].first);
EXPECT_NEAR(ref[i].second, res[i].second, eps);
std::map<int, float> res_map;
for (int i = 0; i < (int)res.size(); i++)
res_map[res[i].first] = res[i].second;
for (const auto& r : ref) {
auto it = res_map.find(r.first);
EXPECT_NE(it, res_map.end()) << "Expected class " << r.first << " not found in top-4";
if (it != res_map.end()) {
EXPECT_NEAR(r.second, it->second, eps) << "Score mismatch for class " << r.first;
}
}
}
INSTANTIATE_TEST_CASE_P(/**/, Reproducibility_ResNet50_QDQ_ONNX,