From 9aa401a7d0510720728f71bcd65e9ffdda954db2 Mon Sep 17 00:00:00 2001 From: Sergei Slashchinin <62052793+sl-sergei@users.noreply.github.com> Date: Wed, 26 Aug 2020 13:15:59 +0300 Subject: [PATCH] Merge pull request #17978 from sl-sergei:fix_17516_17531 * Fix ONNX loading in issues opencv#17516, opencv#17531 * Add tests for Linear and Matmul layers * Disable tests for IE versions lower than 20.4 * Skip unstable tests with OpenCL FP16 on Intel GPU * Add correct test filtering for OpenCL FP16 tests --- modules/dnn/src/onnx/onnx_importer.cpp | 13 +++++++++++++ modules/dnn/test/test_onnx_importer.cpp | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index ccef2f6936..8cb2c5eda1 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -946,6 +946,19 @@ void ONNXImporter::populateNet(Net dstNet) Mat bias = getBlob(node_proto, constBlobs, 2); layerParams.blobs.push_back(bias); } + if (constBlobs.find(node_proto.input(0)) != constBlobs.end()) + { + Mat inputBuf = getBlob(node_proto, constBlobs, 0); + + LayerParams constParams; + constParams.name = node_proto.input(0); + constParams.type = "Const"; + constParams.blobs.push_back(inputBuf); + + opencv_onnx::NodeProto proto; + proto.add_output(constParams.name); + addLayer(dstNet, constParams, proto, layer_id, outShapes); + } layerParams.set("num_output", layerParams.blobs[0].size[ind_num_out]); layerParams.set("bias_term", node_proto.input_size() == 3); diff --git a/modules/dnn/test/test_onnx_importer.cpp b/modules/dnn/test/test_onnx_importer.cpp index c68215ee30..1eb848897c 100644 --- a/modules/dnn/test/test_onnx_importer.cpp +++ b/modules/dnn/test/test_onnx_importer.cpp @@ -611,6 +611,26 @@ TEST_P(Test_ONNX_layers, Pad2d_Unfused) testONNXModels("ZeroPad2d"); } +TEST_P(Test_ONNX_layers, LinearWithConstant) +{ + if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16) + applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16); +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2020040000) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE); +#endif + testONNXModels("lin_with_constant"); +} + +TEST_P(Test_ONNX_layers, MatmulWithTwoInputs) +{ + if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16) + applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16); +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2020040000) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE); +#endif + testONNXModels("matmul_with_two_inputs"); +} + INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_ONNX_layers, dnnBackendsAndTargets()); class Test_ONNX_nets : public Test_ONNX_layers