1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 00:03:03 +04:00

Merge pull request #20535 from SamFC10:onnx-q

dnn : int8 quantized layers support in onnx importer

* added quantized layers support in onnx importer

* added more cases in eltwise node, some more checks

* added tests for quantized nodes

* relax thresholds for failed tests, address review comments

* refactoring based on review comments

* added support for unsupported cases and pre-quantized resnet50 test

* relax thresholds due to int8 resize layer
This commit is contained in:
Jebastin Nadar
2021-10-04 23:37:38 +05:30
committed by GitHub
parent 9085b933d8
commit cce78cc5e2
9 changed files with 795 additions and 54 deletions
+4 -4
View File
@@ -583,7 +583,7 @@ TEST_P(Test_Int8_nets, ResNet50)
Mat blob = blobFromImage(inp, 1.0, Size(224, 224), Scalar(), false);
Mat ref = blobFromNPY(_tf("resnet50_prob.npy"));
float l1 = 3e-4, lInf = 0.035;
float l1 = 3e-4, lInf = 0.04;
testClassificationNet(net, blob, ref, l1, lInf);
}
@@ -714,7 +714,7 @@ TEST_P(Test_Int8_nets, MobileNet_v1_SSD_PPN)
Mat blob = blobFromImage(inp, 1.0, Size(300, 300), Scalar(), true, false);
Mat ref = blobFromNPY(_tf("tensorflow/ssd_mobilenet_v1_ppn_coco.detection_out.npy"));
float confThreshold = 0.51, scoreDiff = 0.04, iouDiff = 0.06;
float confThreshold = 0.51, scoreDiff = 0.05, iouDiff = 0.06;
testDetectionNet(net, blob, ref, confThreshold, scoreDiff, iouDiff);
}
@@ -815,7 +815,7 @@ TEST_P(Test_Int8_nets, FasterRCNN_resnet50)
Mat blob = blobFromImage(inp, 1.0, Size(800, 600), Scalar(), true, false);
Mat ref = blobFromNPY(_tf("tensorflow/faster_rcnn_resnet50_coco_2018_01_28.detection_out.npy"));
float confThreshold = 0.5, scoreDiff = 0.025, iouDiff = 0.15;
float confThreshold = 0.5, scoreDiff = 0.05, iouDiff = 0.15;
testDetectionNet(net, blob, ref, confThreshold, scoreDiff, iouDiff);
}
@@ -1127,7 +1127,7 @@ TEST_P(Test_Int8_nets, YOLOv4)
std::string config_file = "yolov4.cfg";
std::string weights_file = "yolov4.weights";
double scoreDiff = 0.1, iouDiff = 0.17;
double scoreDiff = 0.15, iouDiff = 0.2;
{
SCOPED_TRACE("batch size 1");
testDarknetModel(config_file, weights_file, ref.rowRange(0, N0), scoreDiff, iouDiff);
+111
View File
@@ -991,6 +991,112 @@ TEST_P(Test_ONNX_layers, ConvResizePool1d)
testONNXModels("conv_resize_pool_1d");
}
TEST_P(Test_ONNX_layers, Quantized_Convolution)
{
testONNXModels("quantized_conv_uint8_weights", npy, 0.004, 0.02);
testONNXModels("quantized_conv_int8_weights", npy, 0.03, 0.5);
testONNXModels("quantized_conv_per_channel_weights", npy, 0.06, 0.4);
}
TEST_P(Test_ONNX_layers, Quantized_MatMul)
{
testONNXModels("quantized_matmul_uint8_weights", npy, 0.005, 0.007);
testONNXModels("quantized_matmul_int8_weights", npy, 0.06, 0.2);
testONNXModels("quantized_matmul_per_channel_weights", npy, 0.06, 0.22);
}
TEST_P(Test_ONNX_layers, Quantized_MatMul_Variable_Weights)
{
// Unsupported
EXPECT_THROW(
{
testONNXModels("quantized_matmul_variable_inputs");
}, cv::Exception);
}
TEST_P(Test_ONNX_layers, Quantized_Eltwise)
{
testONNXModels("quantized_eltwise");
}
TEST_P(Test_ONNX_layers, Quantized_Eltwise_Scalar)
{
testONNXModels("quantized_eltwise_scalar");
}
TEST_P(Test_ONNX_layers, Quantized_Eltwise_Broadcast)
{
testONNXModels("quantized_eltwise_broadcast");
}
TEST_P(Test_ONNX_layers, Quantized_LeakyReLU)
{
testONNXModels("quantized_leaky_relu");
}
TEST_P(Test_ONNX_layers, Quantized_Sigmoid)
{
testONNXModels("quantized_sigmoid");
}
TEST_P(Test_ONNX_layers, Quantized_MaxPool)
{
testONNXModels("quantized_maxpool");
}
TEST_P(Test_ONNX_layers, Quantized_AvgPool)
{
testONNXModels("quantized_avgpool");
}
TEST_P(Test_ONNX_layers, Quantized_Split)
{
testONNXModels("quantized_split");
}
TEST_P(Test_ONNX_layers, Quantized_Pad)
{
testONNXModels("quantized_padding");
}
TEST_P(Test_ONNX_layers, Quantized_Reshape)
{
testONNXModels("quantized_reshape");
}
TEST_P(Test_ONNX_layers, Quantized_Transpose)
{
testONNXModels("quantized_transpose");
}
TEST_P(Test_ONNX_layers, Quantized_Squeeze)
{
testONNXModels("quantized_squeeze");
}
TEST_P(Test_ONNX_layers, Quantized_Unsqueeze)
{
testONNXModels("quantized_unsqueeze");
}
TEST_P(Test_ONNX_layers, Quantized_Resize)
{
testONNXModels("quantized_resize_nearest");
testONNXModels("quantized_resize_bilinear", npy, 2e-4, 0.003);
testONNXModels("quantized_resize_bilinear_align", npy, 3e-4, 0.003);
}
TEST_P(Test_ONNX_layers, Quantized_Concat)
{
testONNXModels("quantized_concat");
testONNXModels("quantized_concat_const_blob");
}
TEST_P(Test_ONNX_layers, Quantized_Constant)
{
testONNXModels("quantized_constant", npy, 0.002, 0.008);
}
INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_ONNX_layers, dnnBackendsAndTargets());
class Test_ONNX_nets : public Test_ONNX_layers
@@ -1127,6 +1233,11 @@ TEST_P(Test_ONNX_nets, ResNet50v1)
testONNXModels("resnet50v1", pb, default_l1, default_lInf, true, target != DNN_TARGET_MYRIAD);
}
TEST_P(Test_ONNX_nets, ResNet50_Int8)
{
testONNXModels("resnet50_int8", pb, default_l1, default_lInf, true);
}
TEST_P(Test_ONNX_nets, ResNet101_DUC_HDC)
{
applyTestTag(CV_TEST_TAG_VERYLONG);