Skip to content

Commit

Permalink
[GPU] Handle negative axis in concat op (openvinotoolkit#6839)
Browse files Browse the repository at this point in the history
* [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

* Add tests for negative axis in Concat op
  • Loading branch information
mateusztabaka authored Aug 4, 2021
1 parent 8d36e8f commit 8c4cee1
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
8 changes: 4 additions & 4 deletions inference-engine/src/cldnn_engine/ops/concat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32_t>(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<size_t>(rank, 4) - 2;
cldnn_axis = spatial_size - spatial_axis - 1 + 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using namespace LayerTestsDefinitions;

namespace {

std::vector<size_t >axes = {0, 1, 2, 3};
std::vector<int> axes = {-3, -2, -1, 0, 1, 2, 3};
std::vector<std::vector<std::vector<size_t>>> inShapes = {
{{10, 10, 10, 10}},
{{10, 10, 10, 10}, {10, 10, 10, 10}},
Expand All @@ -36,4 +36,4 @@ INSTANTIATE_TEST_SUITE_P(smoke_NoReshape, ConcatLayerTest,
::testing::Values(CommonTestUtils::DEVICE_CPU)),
ConcatLayerTest::getTestCaseName);

} // namespace
} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using namespace LayerTestsDefinitions;

namespace {

std::vector<size_t > axes = {1};
std::vector<int> axes = {1};
std::vector<std::vector<std::vector<size_t>>> inShapes = {
{{10, 10, 10, 10}, {10, 10, 10, 10}},
{{10, 10, 10, 10}, {10, 10, 10, 10}, {10, 10, 10, 10}},
Expand All @@ -34,4 +34,4 @@ INSTANTIATE_TEST_SUITE_P(smoke_NoReshape, ConcatLayerTest,
::testing::Values(CommonTestUtils::DEVICE_GNA)),
ConcatLayerTest::getTestCaseName);

} // namespace
} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using namespace LayerTestsDefinitions;

namespace {

std::vector<size_t > axes = {0, 1, 2, 3};
std::vector<int> axes = {-3, -2, -1, 0, 1, 2, 3};
std::vector<std::vector<std::vector<size_t>>> inShapes = {
{{10, 10, 10, 10}},
{{10, 10, 10, 10}, {10, 10, 10, 10}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using namespace LayerTestsDefinitions;

namespace {
std::vector<size_t> axes = {0, 1, 2, 3};
std::vector<int> axes = {0, 1, 2, 3};
std::vector<std::vector<std::vector<size_t>>> inShapes = {
{{10, 10, 10, 10}, {10, 10, 10, 10}},
{{10, 10, 10, 10}, {10, 10, 10, 10}, {10, 10, 10, 10}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::vector<size_t>>, // Input shapes
InferenceEngine::Precision, // Network precision
InferenceEngine::Precision, // Input precision
Expand Down

0 comments on commit 8c4cee1

Please sign in to comment.