From 8fff47caf923c61a2f70f6ec5069e90a045411d7 Mon Sep 17 00:00:00 2001 From: Vitaliy Urusovskij Date: Tue, 17 Oct 2023 18:35:19 +0400 Subject: [PATCH] `ROIPooling`, `ROIAlign` layer tests to API2.0 (#20086) * `ROIPoolingLayerTest` to API2.0 * `ROIAlignLayerTest` to API2.0 --- .../single_layer_tests/roi_align.cpp | 39 ++-- .../single_layer_tests/roi_pooling.cpp | 74 ++++--- .../include/single_op_tests/roi_align.hpp | 19 ++ .../include/single_op_tests/roi_pooling.hpp | 15 ++ .../single_op/roi_align.hpp | 54 +++++ .../single_op/roi_pooling.hpp | 34 +++ .../src/base/utils/generate_inputs.cpp | 18 +- .../src/single_op/roi_align.cpp | 203 ++++++++++++++++++ .../src/single_op/roi_pooling.cpp | 74 +++++++ 9 files changed, 472 insertions(+), 58 deletions(-) create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/roi_align.hpp create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/roi_pooling.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/roi_align.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/roi_pooling.hpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/roi_align.cpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/roi_pooling.cpp diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/roi_align.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/roi_align.cpp index 7009da24763..58eaa5174ee 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/roi_align.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/roi_align.cpp @@ -4,30 +4,32 @@ #include -#include "single_layer_tests/roi_align.hpp" +#include "single_op_tests/roi_align.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; +using ov::test::ROIAlignLayerTest; +namespace { -const std::vector netPRCs = { - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32 +const std::vector model_types = { + ov::element::f16, + ov::element::f32 }; const auto ROIAlignCases_average = ::testing::Combine( ::testing::ValuesIn( - std::vector> { - { 3, 8, 16, 16 }, - { 2, 1, 16, 16 }, - { 2, 1, 8, 16 }}), - ::testing::Values(std::vector{ 2, 4 }), + ov::test::static_shapes_to_test_representation( + std::vector>{ + {{ 3, 8, 16, 16 }}, + {{ 2, 1, 16, 16 }}, + {{ 2, 1, 8, 16 }}})), + ::testing::Values(ov::Shape{ 2, 4 }), ::testing::Values(2), ::testing::Values(2), ::testing::ValuesIn(std::vector { 1, 0.625 }), ::testing::Values(2), ::testing::Values("avg"), - ::testing::ValuesIn(netPRCs), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_CPU) ); @@ -35,18 +37,21 @@ INSTANTIATE_TEST_SUITE_P(smoke_TestsROIAlign_average, ROIAlignLayerTest, ROIAlig const auto ROIAlignCases_max = ::testing::Combine( ::testing::ValuesIn( - std::vector> { - { 2, 8, 20, 20 }, - { 2, 1, 20, 20 }, - { 2, 1, 10, 20 }}), - ::testing::Values(std::vector{ 2, 4 }), + ov::test::static_shapes_to_test_representation( + std::vector>{ + {{ 2, 8, 20, 20 }}, + {{ 2, 1, 20, 20 }}, + {{ 2, 1, 10, 20 }}})), + ::testing::Values(ov::Shape{ 2, 4 }), ::testing::Values(2), ::testing::Values(2), ::testing::ValuesIn(std::vector { 1, 0.625 }), ::testing::Values(2), ::testing::Values("max"), - ::testing::ValuesIn(netPRCs), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_CPU) ); INSTANTIATE_TEST_SUITE_P(smoke_TestsROIAlign_max, ROIAlignLayerTest, ROIAlignCases_max, ROIAlignLayerTest::getTestCaseName); + +} // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/roi_pooling.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/roi_pooling.cpp index ff2be946948..ca68bc6fa4d 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/roi_pooling.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/roi_pooling.cpp @@ -4,62 +4,72 @@ #include -#include "single_layer_tests/roi_pooling.hpp" +#include "single_op_tests/roi_pooling.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; +using ov::test::ROIPoolingLayerTest; -const std::vector> inShapes = { - {1, 3, 8, 8}, - {3, 4, 50, 50} +namespace { + +const std::vector param_shapes = { + {{1, 3, 8, 8}}, + {{3, 4, 50, 50}} }; -const std::vector> pooledShapes_max = { - {1, 1}, - {2, 2}, - {3, 3}, - {6, 6} +const std::vector coord_shapes = { + {{1, 5}}, + {{3, 5}}, + {{5, 5}} }; -const std::vector> pooledShapes_bilinear = { - {1, 1}, - {2, 2}, - {3, 3}, - {6, 6} +auto input_shapes = [](const std::vector& in1, const std::vector& in2) { + std::vector> res; + for (const auto& sh1 : in1) + for (const auto& sh2 : in2) + res.push_back(ov::test::static_shapes_to_test_representation({sh1, sh2})); + return res; +}(param_shapes, coord_shapes); + +const std::vector pooled_shapes_max = { + {{1, 1}}, + {{2, 2}}, + {{3, 3}}, + {{6, 6}} }; -const std::vector> coordShapes = { - {1, 5}, - {3, 5}, - {5, 5} +const std::vector pooled_shapes_bilinear = { + {{1, 1}}, + {{2, 2}}, + {{3, 3}}, + {{6, 6}} }; -const std::vector netPRCs = { - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32 +const std::vector model_types = { + ov::element::f16, + ov::element::f32 }; const std::vector spatial_scales = {0.625f, 1.f}; const auto test_ROIPooling_max = ::testing::Combine( - ::testing::ValuesIn(inShapes), - ::testing::ValuesIn(coordShapes), - ::testing::ValuesIn(pooledShapes_max), + ::testing::ValuesIn(input_shapes), + ::testing::ValuesIn(pooled_shapes_max), ::testing::ValuesIn(spatial_scales), - ::testing::Values(ngraph::helpers::ROIPoolingTypes::ROI_MAX), - ::testing::ValuesIn(netPRCs), + ::testing::Values(ov::test::utils::ROIPoolingTypes::ROI_MAX), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_CPU) ); const auto test_ROIPooling_bilinear = ::testing::Combine( - ::testing::ValuesIn(inShapes), - ::testing::ValuesIn(coordShapes), - ::testing::ValuesIn(pooledShapes_bilinear), + ::testing::ValuesIn(input_shapes), + ::testing::ValuesIn(pooled_shapes_bilinear), ::testing::Values(spatial_scales[1]), - ::testing::Values(ngraph::helpers::ROIPoolingTypes::ROI_BILINEAR), - ::testing::ValuesIn(netPRCs), + ::testing::Values(ov::test::utils::ROIPoolingTypes::ROI_BILINEAR), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_CPU) ); INSTANTIATE_TEST_SUITE_P(smoke_TestsROIPooling_max, ROIPoolingLayerTest, test_ROIPooling_max, ROIPoolingLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_TestsROIPooling_bilinear, ROIPoolingLayerTest, test_ROIPooling_bilinear, ROIPoolingLayerTest::getTestCaseName); + +} // namespace diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/roi_align.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/roi_align.hpp new file mode 100644 index 00000000000..96e1bbeeeac --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/roi_align.hpp @@ -0,0 +1,19 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/roi_align.hpp" + +namespace ov { +namespace test { +TEST_P(ROIAlignLayerTest, Inference) { + run(); +} + +TEST_P(ROIAlignV9LayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/roi_pooling.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/roi_pooling.hpp new file mode 100644 index 00000000000..3b89b91aa15 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/roi_pooling.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/roi_pooling.hpp" + +namespace ov { +namespace test { +TEST_P(ROIPoolingLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/roi_align.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/roi_align.hpp new file mode 100644 index 00000000000..57257c7154a --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/roi_align.hpp @@ -0,0 +1,54 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +using roialignParams = std::tuple< + std::vector, // Feature map shape + ov::Shape, // Proposal coords shape + int, // Bin's row count + int, // Bin's column count + float, // Spatial scale + int, // Pooling ratio + std::string, // Pooling mode + ov::element::Type, // Model type + ov::test::TargetDevice>; // Device name + +class ROIAlignLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + static void fillCoordTensor(std::vector& coords, int height, int width, + float spatialScale, int pooledRatio, int pooledH, int pooledW); + static void fillIdxTensor(std::vector& idx, int batchSize); + +protected: + void SetUp() override; +}; + +using roialignV9Params = std::tuple< + std::vector, // Feature map shape + ov::Shape, // Proposal coords shape + int, // Bin's row count + int, // Bin's column count + float, // Spatial scale + int, // Pooling ratio + std::string, // Pooling mode + std::string, // ROI aligned mode + ov::element::Type, // Model type + ov::test::TargetDevice>; // Device name +class ROIAlignV9LayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/roi_pooling.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/roi_pooling.hpp new file mode 100644 index 00000000000..ecd714f6ef5 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/roi_pooling.hpp @@ -0,0 +1,34 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "common_test_utils/test_enums.hpp" + +namespace ov { +namespace test { +using roiPoolingParamsTuple = std::tuple< + std::vector, // Input, coords shapes + ov::Shape, // Pooled shape {pooled_h, pooled_w} + float, // Spatial scale + ov::test::utils::ROIPoolingTypes, // ROIPooling method + ov::element::Type, // Model type + ov::test::TargetDevice>; // Device name + +class ROIPoolingLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp b/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp index 139678a602f..0d8909c4658 100644 --- a/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp +++ b/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp @@ -9,7 +9,7 @@ #include "common_test_utils/ov_tensor_utils.hpp" -#include "shared_test_classes/single_layer/roi_align.hpp" +#include "shared_test_classes/single_op/roi_align.hpp" #include "shared_test_classes/single_layer/psroi_pooling.hpp" #include "shared_test_classes/base/utils/generate_inputs.hpp" #include "shared_test_classes/base/utils/ranges.hpp" @@ -537,13 +537,13 @@ ov::runtime::Tensor generate(const std::shared_ptr& node, if (node->get_sampling_ratio() != 0) { const auto &inputShape = node->get_input_shape(0); std::vector blobData(node->get_shape()[0] * 4); - LayerTestsDefinitions::ROIAlignLayerTest::fillCoordTensor(blobData, - inputShape[2], - inputShape[3], - node->get_spatial_scale(), - node->get_sampling_ratio(), - node->get_pooled_h(), - node->get_pooled_w()); + ov::test::ROIAlignLayerTest::fillCoordTensor(blobData, + inputShape[2], + inputShape[3], + node->get_spatial_scale(), + node->get_sampling_ratio(), + node->get_pooled_h(), + node->get_pooled_w()); return ov::test::utils::create_tensor(ov::element::f32, targetShape, blobData); } else { return generate(std::dynamic_pointer_cast(node), port, elemType, targetShape); @@ -551,7 +551,7 @@ ov::runtime::Tensor generate(const std::shared_ptr& node, } case 2: { std::vector roiIdxVector(node->get_shape()[0]); - LayerTestsDefinitions::ROIAlignLayerTest::fillIdxTensor(roiIdxVector, node->get_shape()[0]); + ov::test::ROIAlignLayerTest::fillIdxTensor(roiIdxVector, node->get_shape()[0]); return ov::test::utils::create_tensor(elemType, targetShape, roiIdxVector); } default: diff --git a/src/tests/functional/shared_test_classes/src/single_op/roi_align.cpp b/src/tests/functional/shared_test_classes/src/single_op/roi_align.cpp new file mode 100644 index 00000000000..d191e7dda95 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/roi_align.cpp @@ -0,0 +1,203 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "shared_test_classes/single_op/roi_align.hpp" + +#include "openvino/core/enum_names.hpp" + +namespace ov { +namespace test { +std::string ROIAlignLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector input_shapes; + ov::Shape coords_shape; + int pooled_h; + int pooled_w; + float spatial_scale; + int pooling_ratio; + std::string pooling_mode; + ov::element::Type model_type; + std::string target_device; + std::tie(input_shapes, coords_shape, pooled_h, pooled_w, spatial_scale, + pooling_ratio, pooling_mode, model_type, target_device) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < input_shapes.size(); i++) { + result << ov::test::utils::partialShape2str({input_shapes[i].first}) + << (i < input_shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < input_shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < input_shapes.size(); j++) { + result << ov::test::utils::vec2str(input_shapes[j].second[i]) << (j < input_shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "coordShape=" << ov::test::utils::vec2str(coords_shape) << "_"; + result << "pooledH=" << pooled_h << "_"; + result << "pooledW=" << pooled_w << "_"; + result << "spatialScale=" << spatial_scale << "_"; + result << "poolingRatio=" << pooling_ratio << "_"; + result << "poolingMode=" << pooling_mode << "_"; + result << "modelType=" << model_type.to_string() << "_"; + result << "trgDev=" << target_device; + return result.str(); +} + +static int randInt(int low, int high) { + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution dis(low, high); + return dis(gen); +} + +void ROIAlignLayerTest::fillCoordTensor(std::vector& coords, int height, int width, + float spatial_scale, int pooled_ratio, int pooled_h, int pooled_w) { + int min_roi_width = pooled_w; + int max_roi_width = width / pooled_ratio; + int min_roi_height = pooled_h; + int max_roi_height = height / pooled_ratio; + + for (int i = 0; i < coords.size() / 4; i++) { + int size_x = std::min(width, randInt(min_roi_width, max_roi_width)); + int size_y = std::min(height, randInt(min_roi_height, max_roi_height)); + int start_x = randInt(0, std::max(1, width - size_x - 1)); + int start_y = randInt(0, std::max(1, height - size_y - 1)); + + coords[i * 4] = start_x / spatial_scale; + coords[i * 4 + 1] = start_y / spatial_scale; + coords[i * 4 + 2] = (start_x + size_x - 1) / spatial_scale; + coords[i * 4 + 3] = (start_y + size_y - 1) / spatial_scale; + } +} +void ROIAlignLayerTest::fillIdxTensor(std::vector& idx, int batch_size) { + int batch_id = 0; + for (int i = 0; i < idx.size(); i++) { + idx[i] = batch_id; + batch_id = (batch_id + 1) % batch_size; + } +} + +void ROIAlignLayerTest::SetUp() { + std::vector input_shapes; + ov::Shape coords_shape; + int pooled_h; + int pooled_w; + float spatial_scale; + int pooling_ratio; + std::string pooling_mode; + ov::element::Type model_type; + std::tie(input_shapes, coords_shape, pooled_h, pooled_w, spatial_scale, + pooling_ratio, pooling_mode, model_type, targetDevice) = this->GetParam(); + + init_input_shapes(input_shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes[0]); + std::vector proposal_vector; + std::vector roi_idx_vector; + proposal_vector.resize(coords_shape[0] * 4); + roi_idx_vector.resize(coords_shape[0]); + + fillCoordTensor(proposal_vector, inputDynamicShapes[0][2].get_length(), inputDynamicShapes[0][3].get_length(), + spatial_scale, pooling_ratio, pooled_h, pooled_w); + fillIdxTensor(roi_idx_vector, inputDynamicShapes[0][0].get_length()); + auto idx_shape = ov::Shape{coords_shape[0]}; + + auto coords = std::make_shared(model_type, coords_shape, proposal_vector.data()); + auto rois_Idx = std::make_shared(ov::element::i32, idx_shape, roi_idx_vector.data()); + auto roi_align = std::make_shared(param, + coords, + rois_Idx, + pooled_h, + pooled_w, + pooling_ratio, + spatial_scale, + pooling_mode); + function = std::make_shared(roi_align->outputs(), ov::ParameterVector{param}, "roi_align"); +} + +std::string ROIAlignV9LayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector input_shapes; + ov::Shape coords_shape; + int pooled_h; + int pooled_w; + float spatial_scale; + int pooling_ratio; + std::string pooling_mode; + std::string roi_aligned_mode; + ov::element::Type model_type; + std::string target_device; + std::tie(input_shapes, coords_shape, pooled_h, pooled_w, spatial_scale, + pooling_ratio, pooling_mode, roi_aligned_mode, model_type, target_device) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < input_shapes.size(); i++) { + result << ov::test::utils::partialShape2str({input_shapes[i].first}) + << (i < input_shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < input_shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < input_shapes.size(); j++) { + result << ov::test::utils::vec2str(input_shapes[j].second[i]) << (j < input_shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "coordShape=" << ov::test::utils::vec2str(coords_shape) << "_"; + result << "pooledH=" << pooled_h << "_"; + result << "pooledW=" << pooled_w << "_"; + result << "spatialScale=" << spatial_scale << "_"; + result << "poolingRatio=" << pooling_ratio << "_"; + result << "poolingMode=" << pooling_mode << "_"; + result << "ROIMode=" << roi_aligned_mode << "_"; + result << "modelType=" << model_type.to_string() << "_"; + result << "trgDev=" << target_device; + return result.str(); +} + +void ROIAlignV9LayerTest::SetUp() { + std::vector input_shapes; + ov::Shape coords_shape; + int pooled_h; + int pooled_w; + float spatial_scale; + int pooling_ratio; + std::string pooling_mode; + std::string roi_aligned_mode; + ov::element::Type model_type; + std::tie(input_shapes, coords_shape, pooled_h, pooled_w, spatial_scale, + pooling_ratio, pooling_mode, roi_aligned_mode, model_type, targetDevice) = this->GetParam(); + + init_input_shapes(input_shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes[0]); + std::vector proposal_vector; + std::vector roi_idx_vector; + proposal_vector.resize(coords_shape[0] * 4); + roi_idx_vector.resize(coords_shape[0]); + + ROIAlignLayerTest::fillCoordTensor(proposal_vector, inputDynamicShapes[0][2].get_length(), inputDynamicShapes[0][3].get_length(), + spatial_scale, pooling_ratio, pooled_h, pooled_w); + ROIAlignLayerTest::fillIdxTensor(roi_idx_vector, inputDynamicShapes[0][0].get_length()); + auto idx_shape = ov::Shape{coords_shape[0]}; + + auto coords = std::make_shared(model_type, coords_shape, proposal_vector.data()); + auto rois_Idx = std::make_shared(ov::element::i32, idx_shape, roi_idx_vector.data()); + auto roi_align = std::make_shared(param, + coords, + rois_Idx, + pooled_h, + pooled_w, + pooling_ratio, + spatial_scale, + ov::EnumNames::as_enum(pooling_mode), + ov::EnumNames::as_enum(roi_aligned_mode)); + function = std::make_shared(roi_align->outputs(), ov::ParameterVector{param}, "roi_align"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/roi_pooling.cpp b/src/tests/functional/shared_test_classes/src/single_op/roi_pooling.cpp new file mode 100644 index 00000000000..f4867abe662 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/roi_pooling.cpp @@ -0,0 +1,74 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/roi_pooling.hpp" + +namespace ov { +namespace test { +std::string ROIPoolingLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector input_shapes; + ov::Shape pool_shape; + float spatial_scale; + ov::test::utils::ROIPoolingTypes pool_method; + ov::element::Type model_type; + std::string target_device; + std::tie(input_shapes, pool_shape, spatial_scale, pool_method, model_type, target_device) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < input_shapes.size(); i++) { + result << ov::test::utils::partialShape2str({input_shapes[i].first}) + << (i < input_shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < input_shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < input_shapes.size(); j++) { + result << ov::test::utils::vec2str(input_shapes[j].second[i]) << (j < input_shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "PS=" << ov::test::utils::vec2str(pool_shape) << "_"; + result << "Scale=" << spatial_scale << "_"; + switch (pool_method) { + case utils::ROIPoolingTypes::ROI_MAX: + result << "Max_"; + break; + case utils::ROIPoolingTypes::ROI_BILINEAR: + result << "Bilinear_"; + break; + } + result << "modelType=" << model_type.to_string() << "_"; + result << "trgDev=" << target_device; + return result.str(); +} + +void ROIPoolingLayerTest::SetUp() { + std::vector input_shapes; + ov::Shape pool_shape; + float spatial_scale; + ov::test::utils::ROIPoolingTypes pool_method; + ov::element::Type model_type; + std::string target_device; + std::tie(input_shapes, pool_shape, spatial_scale, pool_method, model_type, targetDevice) = this->GetParam(); + + abs_threshold = 0.08f; + + init_input_shapes(input_shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes[0]); + auto coord_param = std::make_shared(model_type, inputDynamicShapes[1]); + std::string pool_method_str; + if (pool_method == ov::test::utils::ROIPoolingTypes::ROI_MAX) { + pool_method_str = "max"; + } else if (pool_method == ov::test::utils::ROIPoolingTypes::ROI_BILINEAR) { + pool_method_str = "bilinear"; + } else { + FAIL() << "Incorrect type of ROIPooling operation"; + } + auto roi_pooling = std::make_shared(param, coord_param, pool_shape, spatial_scale, pool_method_str); + function = std::make_shared(roi_pooling->outputs(), ov::ParameterVector{param, coord_param}, "roi_pooling"); +} +} // namespace test +} // namespace ov