[GNA] Added multi crop test (#10459)

This commit is contained in:
Andrey Noskov 2022-03-11 15:05:14 +03:00 committed by GitHub
parent caaacb2db4
commit 6fdd983750
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 170 additions and 0 deletions

View File

@ -0,0 +1,53 @@
// Copyright (C) 2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <subgraph_tests/multi_crops_to_concat.hpp>
#include "common_test_utils/test_constants.hpp"
namespace SubgraphTestsDefinitions {
namespace {
const std::vector<std::vector<size_t>> input_shapes = {
{1, 48},
{1, 64}
};
const std::vector<std::vector<std::pair<int64_t, int64_t>>> offsets = {
{
{0, 16},
{33, 48}
},
{
{17, 32},
{33, 48}
},
{
{5, 14},
{17, 26}
},
{
{1, 8},
{9, 16},
{17, 24}
}
};
const std::vector<std::map<std::string, std::string>> additional_config = {
{
{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}
},
{
{"GNA_DEVICE_MODE", "GNA_SW_FP32"}
}
};
} // namespace
INSTANTIATE_TEST_SUITE_P(smoke_multi_crop_to_concat, MultiCropsToConcatTest,
::testing::Combine(
::testing::Values(InferenceEngine::Precision::FP32),
::testing::Values(CommonTestUtils::DEVICE_GNA),
::testing::ValuesIn(input_shapes),
::testing::ValuesIn(offsets),
::testing::ValuesIn(additional_config)),
MultiCropsToConcatTest::getTestCaseName);
} // namespace SubgraphTestsDefinitions

View File

@ -0,0 +1,13 @@
// Copyright (C) 2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/subgraph/multi_crops_to_concat.hpp"
namespace SubgraphTestsDefinitions {
TEST_P(MultiCropsToConcatTest, CompareWithRefs) {
Run();
};
} // namespace SubgraphTestsDefinitions

View File

@ -0,0 +1,35 @@
// Copyright (C) 2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <tuple>
#include <vector>
#include <string>
#include <memory>
#include "shared_test_classes/base/layer_test_utils.hpp"
#include "ngraph_functions/utils/ngraph_helpers.hpp"
#include "ngraph_functions/builders.hpp"
namespace SubgraphTestsDefinitions {
typedef std::tuple<
InferenceEngine::Precision, // Network Precision
std::string, // Target Device
std::vector<size_t>, // Input Shapes
std::vector<std::pair<int64_t, int64_t>>, // Offset pairs (begin, end)
std::map<std::string, std::string> // Configuration
> MultiCropsToConcatParams;
class MultiCropsToConcatTest : public testing::WithParamInterface<MultiCropsToConcatParams>,
public LayerTestsUtils::LayerTestsCommon {
public:
static std::string getTestCaseName(const testing::TestParamInfo<MultiCropsToConcatParams>& obj);
protected:
void SetUp() override;
};
} // namespace SubgraphTestsDefinitions

View File

@ -0,0 +1,69 @@
// Copyright (C) 2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/subgraph/multi_crops_to_concat.hpp"
#include "ngraph_functions/builders.hpp"
namespace SubgraphTestsDefinitions {
std::string MultiCropsToConcatTest::getTestCaseName(const testing::TestParamInfo<MultiCropsToConcatParams>& obj) {
InferenceEngine::Precision netPrecision;
std::string targetDevice;
std::map<std::string, std::string> configuration;
std::vector<size_t> inputShape;
std::vector<std::pair<int64_t, int64_t>> offsets;
std::tie(netPrecision, targetDevice, inputShape, offsets, configuration) = obj.param;
std::ostringstream result;
result << "IS=" << CommonTestUtils::vec2str(inputShape) << "_";
result << "netPRC=" << netPrecision.name() << "_";
result << "targetDevice=" << targetDevice << "_";
result << "offset=";
for (auto offset : offsets) {
result << "(" << offset.first << "," << offset.second << ")";
}
for (auto const& configItem : configuration) {
result << "_configItem=" << configItem.first << "_" << configItem.second;
}
return result.str();
}
void MultiCropsToConcatTest::SetUp() {
InferenceEngine::Precision netPrecision;
std::map<std::string, std::string> tempConfig;
std::vector<size_t> inputShape;
std::vector<std::pair<int64_t, int64_t>> offsets;
std::tie(netPrecision, targetDevice, inputShape, offsets, tempConfig) = this->GetParam();
configuration.insert(tempConfig.begin(), tempConfig.end());
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
auto params = ngraph::builder::makeParams(ngPrc, { inputShape });
auto crop1 = ngraph::builder::makeStridedSlice(params[0], std::vector<int64_t>{0, offsets[0].first}, std::vector<int64_t>{1, offsets[0].second},
std::vector<int64_t>{1, 1}, ngPrc, std::vector<int64_t>{1, 0},
std::vector<int64_t>{1, 0}, std::vector<int64_t>{0, 0},
std::vector<int64_t>{0, 0}, std::vector<int64_t>{0, 0});
auto crop2 = ngraph::builder::makeStridedSlice(params[0], std::vector<int64_t>{0, offsets[1].first}, std::vector<int64_t>{1, offsets[1].second},
std::vector<int64_t>{1, 1}, ngPrc, std::vector<int64_t>{1, 0},
std::vector<int64_t>{1, 0}, std::vector<int64_t>{0, 0},
std::vector<int64_t>{0, 0}, std::vector<int64_t>{0, 0});
auto concat1 = std::make_shared<ngraph::opset8::Concat>(ngraph::OutputVector{crop1, crop2}, 1);
std::shared_ptr<ov::op::v0::Result> result;
// Case with 3 crops
if (offsets.size() == 3) {
auto crop3 = ngraph::builder::makeStridedSlice(params[0], std::vector<int64_t>{0, offsets[2].first}, std::vector<int64_t>{1, offsets[2].second},
std::vector<int64_t>{1, 1}, ngPrc, std::vector<int64_t>{1, 0},
std::vector<int64_t>{1, 0}, std::vector<int64_t>{0, 0},
std::vector<int64_t>{0, 0}, std::vector<int64_t>{0, 0});
auto concat2 = std::make_shared<ngraph::opset8::Concat>(ngraph::OutputVector{crop1, crop2}, 1);
result = std::make_shared<ngraph::opset8::Result>(concat2);
} else {
result = std::make_shared<ngraph::opset8::Result>(concat1);
}
function = std::make_shared<ngraph::Function>(result, params, "InputSplitConcatTest");
}
} // namespace SubgraphTestsDefinitions