From d16e5b5b0eae694c70a7d9029f68f7fa9886d8d1 Mon Sep 17 00:00:00 2001 From: Mateusz Tabaka Date: Wed, 28 Jul 2021 07:55:37 +0000 Subject: [PATCH 1/2] [clDNN] Handle negative axis in concat op That enables following models for onnx importer path: yolact-resnet50-fpn-pytorch yolact-resnet101-fpn-pytorch yolact-darknet53-fpn-pytorch swin-tiny-patch4-window7-224 action-recognition-mkinetics-res34-mhsa driver-action-recognition-adas-0002-decoder horizontal-text-detection-0001 --- inference-engine/src/cldnn_engine/ops/concat.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inference-engine/src/cldnn_engine/ops/concat.cpp b/inference-engine/src/cldnn_engine/ops/concat.cpp index 9d37f959f03fb7..453e99965309da 100644 --- a/inference-engine/src/cldnn_engine/ops/concat.cpp +++ b/inference-engine/src/cldnn_engine/ops/concat.cpp @@ -12,14 +12,14 @@ namespace CLDNNPlugin { static cldnn::concatenation::concatenation_axis GetConcatAxis(int32_t axis, size_t rank) { - if (axis >= rank) + unsigned cldnn_axis = axis >= 0 ? axis : axis + static_cast(rank); + if (cldnn_axis >= rank) IE_THROW() << "Concatenation axis exceeds number of dimensions"; // Difference in dimension ordering between IE and clDNN, // reverse spatial dimensions after batch and feature. - unsigned cldnn_axis = axis; - if (axis >= 2) { - auto spatial_axis = axis - 2; + if (cldnn_axis >= 2) { + auto spatial_axis = cldnn_axis - 2; // Default and minimum number of dimensions is 4 auto spatial_size = std::max(rank, 4) - 2; cldnn_axis = spatial_size - spatial_axis - 1 + 2; From e1071b4819de0733a337fc3836299d3fa15c0643 Mon Sep 17 00:00:00 2001 From: Mateusz Tabaka Date: Thu, 29 Jul 2021 19:16:11 +0000 Subject: [PATCH 2/2] Add tests for negative axis in Concat op --- .../cpu/shared_tests_instances/single_layer_tests/concat.cpp | 4 ++-- .../gna/shared_tests_instances/single_layer_tests/concat.cpp | 4 ++-- .../gpu/shared_tests_instances/single_layer_tests/concat.cpp | 2 +- .../shared_tests_instances/single_layer_tests/concat.cpp | 2 +- .../include/shared_test_classes/single_layer/concat.hpp | 3 +-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/concat.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/concat.cpp index e983d4a65ec428..d78d6bd39502ae 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/concat.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/concat.cpp @@ -11,7 +11,7 @@ using namespace LayerTestsDefinitions; namespace { -std::vectoraxes = {0, 1, 2, 3}; +std::vector axes = {-3, -2, -1, 0, 1, 2, 3}; std::vector>> inShapes = { {{10, 10, 10, 10}}, {{10, 10, 10, 10}, {10, 10, 10, 10}}, @@ -36,4 +36,4 @@ INSTANTIATE_TEST_SUITE_P(smoke_NoReshape, ConcatLayerTest, ::testing::Values(CommonTestUtils::DEVICE_CPU)), ConcatLayerTest::getTestCaseName); -} // namespace \ No newline at end of file +} // namespace diff --git a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/single_layer_tests/concat.cpp b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/single_layer_tests/concat.cpp index 68107baee29bd3..fa6fd4348f4118 100644 --- a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/single_layer_tests/concat.cpp +++ b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/single_layer_tests/concat.cpp @@ -11,7 +11,7 @@ using namespace LayerTestsDefinitions; namespace { -std::vector axes = {1}; +std::vector axes = {1}; std::vector>> inShapes = { {{10, 10, 10, 10}, {10, 10, 10, 10}}, {{10, 10, 10, 10}, {10, 10, 10, 10}, {10, 10, 10, 10}}, @@ -34,4 +34,4 @@ INSTANTIATE_TEST_SUITE_P(smoke_NoReshape, ConcatLayerTest, ::testing::Values(CommonTestUtils::DEVICE_GNA)), ConcatLayerTest::getTestCaseName); -} // namespace \ No newline at end of file +} // namespace diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/concat.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/concat.cpp index a57887e900fbab..f1231de1f711fd 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/concat.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/concat.cpp @@ -11,7 +11,7 @@ using namespace LayerTestsDefinitions; namespace { -std::vector axes = {0, 1, 2, 3}; +std::vector axes = {-3, -2, -1, 0, 1, 2, 3}; std::vector>> inShapes = { {{10, 10, 10, 10}}, {{10, 10, 10, 10}, {10, 10, 10, 10}}, diff --git a/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/single_layer_tests/concat.cpp b/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/single_layer_tests/concat.cpp index 228c892fa3ac3e..5fd5329068756c 100644 --- a/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/single_layer_tests/concat.cpp +++ b/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/single_layer_tests/concat.cpp @@ -10,7 +10,7 @@ using namespace LayerTestsDefinitions; namespace { -std::vector axes = {0, 1, 2, 3}; +std::vector axes = {0, 1, 2, 3}; std::vector>> inShapes = { {{10, 10, 10, 10}, {10, 10, 10, 10}}, {{10, 10, 10, 10}, {10, 10, 10, 10}, {10, 10, 10, 10}}, diff --git a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/concat.hpp b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/concat.hpp index bdc6cb44de0306..3485562acacd94 100644 --- a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/concat.hpp +++ b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/concat.hpp @@ -16,8 +16,7 @@ namespace LayerTestsDefinitions { using concatParamsTuple = typename std::tuple< - //TODO: according to specification axis have to be int, negative values are allowed - size_t, // Concat axis + int, // Concat axis std::vector>, // Input shapes InferenceEngine::Precision, // Network precision InferenceEngine::Precision, // Input precision