From 50811e04f200fddf59ef92909bb22c8d66632707 Mon Sep 17 00:00:00 2001 From: Lubov Batanina Date: Mon, 8 Oct 2018 22:18:41 +0300 Subject: [PATCH] Merge pull request #12596 from l-bat:l-bat/shufflenet_onnx * Add Shufflenet support in ONNX * Add test for transpose layer --- modules/dnn/src/layers/permute_layer.cpp | 2 -- modules/dnn/src/onnx/onnx_importer.cpp | 5 +++++ modules/dnn/test/test_onnx_importer.cpp | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/modules/dnn/src/layers/permute_layer.cpp b/modules/dnn/src/layers/permute_layer.cpp index ac294a9a10..8d14d9ca95 100644 --- a/modules/dnn/src/layers/permute_layer.cpp +++ b/modules/dnn/src/layers/permute_layer.cpp @@ -132,8 +132,6 @@ public: for (size_t i = 0; i < inputs.size(); i++) { - CV_Assert(inputs[i].size() == 4); - CV_Assert(inputs[i][2] == shapeBefore[2] && inputs[i][3] == shapeBefore[3]); CV_Assert(total(inputs[i]) == total(shapeAfter)); outputs.push_back(shapeAfter); } diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index a9daa198df..3c50566449 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -486,6 +486,11 @@ void ONNXImporter::populateNet(Net dstNet) layerParams.set("num_output", layerParams.blobs[0].size[0]); layerParams.set("bias_term", node_proto.input_size() == 3); } + else if (layer_type == "Transpose") + { + layerParams.type = "Permute"; + replaceLayerParam(layerParams, "perm", "order"); + } else if (layer_type == "Unsqueeze") { CV_Assert(node_proto.input_size() == 1); diff --git a/modules/dnn/test/test_onnx_importer.cpp b/modules/dnn/test/test_onnx_importer.cpp index 9415bea754..52e867a499 100644 --- a/modules/dnn/test/test_onnx_importer.cpp +++ b/modules/dnn/test/test_onnx_importer.cpp @@ -108,6 +108,14 @@ TEST_P(Test_ONNX_layers, BatchNormalization) testONNXModels("batch_norm"); } +TEST_P(Test_ONNX_layers, Transpose) +{ + if (backend == DNN_BACKEND_INFERENCE_ENGINE && + (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_OPENCL || target == DNN_TARGET_MYRIAD)) + throw SkipTestException(""); + testONNXModels("transpose"); +} + TEST_P(Test_ONNX_layers, Multiplication) { if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16 || @@ -351,6 +359,14 @@ TEST_P(Test_ONNX_nets, Inception_v1) testONNXModels("inception_v1", pb); } +TEST_P(Test_ONNX_nets, Shufflenet) +{ + if (backend == DNN_BACKEND_INFERENCE_ENGINE && + (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_OPENCL || target == DNN_TARGET_MYRIAD)) + throw SkipTestException(""); + testONNXModels("shufflenet", pb); +} + INSTANTIATE_TEST_CASE_P(/**/, Test_ONNX_nets, dnnBackendsAndTargets()); }} // namespace