PSROIPooling and Proposal layer tests to API2.0 (#20761)

* `PSROIPoolingLayerTest` to API2.0

* `ProposalLayerTest` to API2.0
This commit is contained in:
Vitaliy Urusovskij 2023-10-31 10:21:20 +04:00 committed by Alexander Nesterov
parent 80bc87bdb0
commit 225c063ff2
8 changed files with 352 additions and 33 deletions

View File

@ -4,44 +4,44 @@
#include <vector>
#include "single_layer_tests/proposal.hpp"
#include "single_op_tests/proposal.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace ngraph::helpers;
using namespace LayerTestsDefinitions;
using ov::test::ProposalLayerTest;
namespace {
/* ============= Proposal ============= */
const std::vector<base_size_type> base_size_ = {16};
const std::vector<pre_nms_topn_type> pre_nms_topn_ = {100};
const std::vector<post_nms_topn_type> post_nms_topn_ = {100};
const std::vector<nms_thresh_type> nms_thresh_ = {0.7f};
const std::vector<min_size_type> min_size_ = {1};
const std::vector<ratio_type> ratio_ = {{1.0f, 2.0f}};
const std::vector<scale_type> scale_ = {{1.2f, 1.5f}};
const std::vector<clip_before_nms_type> clip_before_nms_ = {false};
const std::vector<clip_after_nms_type> clip_after_nms_ = {false};
const std::vector<size_t> base_size = {16};
const std::vector<size_t> pre_nms_topn = {100};
const std::vector<size_t> post_nms_topn = {100};
const std::vector<float> nms_thresh = {0.7f};
const std::vector<size_t> min_size = {1};
const std::vector<std::vector<float>> ratio = {{1.0f, 2.0f}};
const std::vector<std::vector<float>> scale = {{1.2f, 1.5f}};
const std::vector<bool> clip_before_nms = {false};
const std::vector<bool> clip_after_nms = {false};
// empty string corresponds to Caffe framework
const std::vector<framework_type> framework_ = {""};
const std::vector<std::string> framework = {""};
const auto proposalParams = ::testing::Combine(
::testing::ValuesIn(base_size_),
::testing::ValuesIn(pre_nms_topn_),
::testing::ValuesIn(post_nms_topn_),
::testing::ValuesIn(nms_thresh_),
::testing::ValuesIn(min_size_),
::testing::ValuesIn(ratio_),
::testing::ValuesIn(scale_),
::testing::ValuesIn(clip_before_nms_),
::testing::ValuesIn(clip_after_nms_),
::testing::ValuesIn(framework_)
const auto proposal_params = ::testing::Combine(
::testing::ValuesIn(base_size),
::testing::ValuesIn(pre_nms_topn),
::testing::ValuesIn(post_nms_topn),
::testing::ValuesIn(nms_thresh),
::testing::ValuesIn(min_size),
::testing::ValuesIn(ratio),
::testing::ValuesIn(scale),
::testing::ValuesIn(clip_before_nms),
::testing::ValuesIn(clip_after_nms),
::testing::ValuesIn(framework)
);
INSTANTIATE_TEST_SUITE_P(smoke_Proposal_tests, ProposalLayerTest,
INSTANTIATE_TEST_SUITE_P(proposal_params, ProposalLayerTest,
::testing::Combine(
proposalParams,
proposal_params,
::testing::Values(ov::element::f16),
::testing::Values(ov::test::utils::DEVICE_CPU)),
ProposalLayerTest::getTestCaseName
);

View File

@ -4,23 +4,23 @@
#include <vector>
#include "single_layer_tests/psroi_pooling.hpp"
#include "single_op_tests/psroi_pooling.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
using ov::test::PSROIPoolingLayerTest;
std::vector<float> spatialScales = {1, 0.625};
std::vector<float> spatial_scales = {1, 0.625};
const auto PSROICases_average = ::testing::Combine(
::testing::Values(std::vector<size_t>{3, 8, 16, 16}),
::testing::Values(std::vector<size_t>{10, 5}),
::testing::Values(2),
::testing::Values(2),
::testing::ValuesIn(spatialScales),
::testing::ValuesIn(spatial_scales),
::testing::Values(1),
::testing::Values(1),
::testing::Values("average"),
::testing::Values(InferenceEngine::Precision::FP32),
::testing::Values(ov::element::f32),
::testing::Values(ov::test::utils::DEVICE_CPU)
);
@ -32,11 +32,11 @@ const auto PSROICases_bilinear = ::testing::Combine(
::testing::Values(std::vector<size_t>{10, 5}),
::testing::Values(4),
::testing::Values(3),
::testing::ValuesIn(spatialScales),
::testing::ValuesIn(spatial_scales),
::testing::Values(4),
::testing::Values(2),
::testing::Values("bilinear"),
::testing::Values(InferenceEngine::Precision::FP32),
::testing::Values(ov::element::f32),
::testing::Values(ov::test::utils::DEVICE_CPU)
);

View File

@ -0,0 +1,15 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "shared_test_classes/single_op/proposal.hpp"
namespace ov {
namespace test {
TEST_P(ProposalLayerTest, Inference) {
run();
}
} // namespace test
} // namespace ov

View File

@ -0,0 +1,15 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "shared_test_classes/single_op/psroi_pooling.hpp"
namespace ov {
namespace test {
TEST_P(PSROIPoolingLayerTest, Inference) {
run();
}
} // namespace test
} // namespace ov

View File

@ -0,0 +1,44 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <tuple>
#include <string>
#include <vector>
#include <memory>
#include "shared_test_classes/base/ov_subgraph.hpp"
#include "common_test_utils/test_enums.hpp"
namespace ov {
namespace test {
using proposalSpecificParams = std::tuple<
size_t, // base_size
size_t, // pre_nms_topn
size_t, // post_nms_topn
float, // nms_thresh
size_t, // min_size
std::vector<float>, // ratio
std::vector<float>, // scale
bool, // clip_before_nms
bool, // clip_after_nms
std::string // framework
>;
using proposalLayerTestParamsSet = std::tuple<
proposalSpecificParams,
ov::element::Type,
ov::test::TargetDevice
>;
class ProposalLayerTest : public testing::WithParamInterface<proposalLayerTestParamsSet>,
virtual public ov::test::SubgraphBaseStaticTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<proposalLayerTestParamsSet>& obj);
protected:
void SetUp() override;
};
} // namespace test
} // namespace ov

View File

@ -0,0 +1,43 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <tuple>
#include <string>
#include <vector>
#include <memory>
#include "ov_models/builders.hpp"
#include "ov_models/utils/ov_helpers.hpp"
#include "shared_test_classes/base/ov_subgraph.hpp"
#include "common_test_utils/test_enums.hpp"
namespace ov {
namespace test {
using psroiParams = std::tuple<
std::vector<size_t>, // Input shape
std::vector<size_t>, // Coords shape
size_t, // Output_dim
size_t, // group_size
float, // Spatial scale
size_t, // spatial_bins_x
size_t, // spatial_bins_y
std::string, // Mode
ov::element::Type, // Model type
ov::test::TargetDevice // Device name
>;
class PSROIPoolingLayerTest : public testing::WithParamInterface<psroiParams>,
virtual public ov::test::SubgraphBaseStaticTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<psroiParams>& obj);
protected:
void SetUp() override;
};
} // namespace test
} // namespace ov

View File

@ -0,0 +1,139 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/single_op/proposal.hpp"
namespace ov {
namespace test {
const bool normalize = true;
const size_t feat_stride = 1;
const float box_size_scale = 2.0f;
const float box_coordinate_scale = 2.0f;
// std::string ProposalLayerTest::SerializeProposalSpecificParams(proposalSpecificParams& params) {
// size_t base_size;
// size_t pre_nms_topn;
// size_t post_nms_topn;
// float nms_thresh;
// size_t min_size;
// std::vector<float> ratio;
// std::vector<float> scale;
// bool clip_before_nms;
// bool clip_after_nms;
// std::string framework;
// std::tie(base_size, pre_nms_topn,
// post_nms_topn,
// nms_thresh,
// min_size,
// ratio,
// scale,
// clip_before_nms,
// clip_after_nms,
// framework) = params;
// std::ostringstream result;
// result << "base_size=" << base_size << "_";
// result << "pre_nms_topn=" << pre_nms_topn << "_";
// result << "post_nms_topn=" << post_nms_topn << "_";
// result << "nms_thresh=" << nms_thresh << "_";
// result << "feat_stride=" << feat_stride << "_";
// result << "min_size=" << min_size << "_";
// result << "ratio = " << ov::test::utils::vec2str(ratio) << "_";
// result << "scale = " << ov::test::utils::vec2str(scale) << "_";
// result << "clip_before_nms=" << clip_before_nms << "_";
// result << "clip_after_nms=" << clip_after_nms << "_";
// result << "normalize=" << normalize << "_";
// result << "box_size_scale=" << box_size_scale << "_";
// result << "box_coordinate_scale=" << box_coordinate_scale << "_";
// result << "framework=" << framework << "_";
// return result.str();
// }
std::string ProposalLayerTest::getTestCaseName(const testing::TestParamInfo<proposalLayerTestParamsSet>& obj) {
proposalSpecificParams proposal_params;
ov::element::Type model_type;
std::string target_device;
std::tie(proposal_params, model_type, target_device) = obj.param;
size_t base_size, pre_nms_topn, post_nms_topn, min_size;
float nms_thresh;
std::vector<float> ratio, scale;
bool clip_before_nms, clip_after_nms;
std::string framework;
std::tie(base_size, pre_nms_topn, post_nms_topn,
nms_thresh, min_size, ratio, scale,
clip_before_nms, clip_after_nms, framework) = proposal_params;
std::ostringstream result;
result << "base_size=" << base_size << "_";
result << "pre_nms_topn=" << pre_nms_topn << "_";
result << "post_nms_topn=" << post_nms_topn << "_";
result << "nms_thresh=" << nms_thresh << "_";
result << "feat_stride=" << feat_stride << "_";
result << "min_size=" << min_size << "_";
result << "ratio = " << ov::test::utils::vec2str(ratio) << "_";
result << "scale = " << ov::test::utils::vec2str(scale) << "_";
result << "clip_before_nms=" << clip_before_nms << "_";
result << "clip_after_nms=" << clip_after_nms << "_";
result << "normalize=" << normalize << "_";
result << "box_size_scale=" << box_size_scale << "_";
result << "box_coordinate_scale=" << box_coordinate_scale << "_";
result << "framework=" << framework << "_";
result << "modelType=" << model_type.to_string() << "_";
result << "trgDev=" << target_device;
return result.str();
}
void ProposalLayerTest::SetUp() {
std::vector<float> img_info = {225.0f, 225.0f, 1.0f};
proposalSpecificParams proposal_params;
ov::element::Type model_type;
std::tie(proposal_params, model_type, targetDevice) = this->GetParam();
size_t base_size, pre_nms_topn, post_nms_topn, min_size;
float nms_thresh;
std::vector<float> ratio, scale;
bool clip_before_nms, clip_after_nms;
std::string framework;
std::tie(base_size, pre_nms_topn, post_nms_topn,
nms_thresh, min_size, ratio, scale,
clip_before_nms, clip_after_nms, framework) = proposal_params;
size_t bottom_w = base_size;
size_t bottom_h = base_size;
size_t num_anchors = ratio.size() * scale.size();
ov::Shape scores_shape = {1, 2 * num_anchors, bottom_h, bottom_w};
ov::Shape boxes_shape = {1, 4 * num_anchors, bottom_h, bottom_w};
ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(model_type, scores_shape),
std::make_shared<ov::op::v0::Parameter>(model_type, boxes_shape)};
ov::op::v4::Proposal::Attributes attrs;
attrs.base_size = base_size;
attrs.pre_nms_topn = pre_nms_topn;
attrs.post_nms_topn = post_nms_topn;
attrs.nms_thresh = nms_thresh;
attrs.feat_stride = feat_stride;
attrs.min_size = min_size;
attrs.ratio = ratio;
attrs.scale = scale;
attrs.clip_before_nms = clip_before_nms;
attrs.clip_after_nms = clip_after_nms;
attrs.normalize = normalize;
attrs.box_size_scale = box_size_scale;
attrs.box_coordinate_scale = box_coordinate_scale;
attrs.framework = framework;
attrs.infer_probs = true;
auto image_shape = std::make_shared<ov::op::v0::Constant>(ov::element::f32, ov::Shape{3}, img_info);
auto proposal = std::make_shared<ov::op::v4::Proposal>(params[0], params[1], image_shape, attrs);
function = std::make_shared<ov::Model>(proposal->outputs(), params, "proposal");
}
} // namespace test
} // namespace ov

View File

@ -0,0 +1,63 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/single_op/psroi_pooling.hpp"
namespace ov {
namespace test {
std::string PSROIPoolingLayerTest::getTestCaseName(const testing::TestParamInfo<psroiParams>& obj) {
std::vector<size_t> input_shape;
std::vector<size_t> coords_shape;
size_t output_dim;
size_t group_size;
float spatial_scale;
size_t spatial_bins_x;
size_t spatial_bins_y;
std::string mode;
ov::element::Type model_type;
std::string target_device;
std::tie(input_shape, coords_shape, output_dim, group_size, spatial_scale, spatial_bins_x, spatial_bins_y, mode, model_type, target_device) = obj.param;
std::ostringstream result;
result << "IS=" << ov::test::utils::vec2str(input_shape) << "_";
result << "coord_shape=" << ov::test::utils::vec2str(coords_shape) << "_";
result << "out_dim=" << output_dim << "_";
result << "group_size=" << group_size << "_";
result << "scale=" << spatial_scale << "_";
result << "bins_x=" << spatial_bins_x << "_";
result << "bins_y=" << spatial_bins_y << "_";
result << "mode=" << mode << "_";
result << "modelType=" << model_type.to_string() << "_";
result << "trgDev=" << target_device;
return result.str();
}
void PSROIPoolingLayerTest::SetUp() {
std::vector<size_t> input_shape;
std::vector<size_t> coords_shape;
size_t output_dim;
size_t group_size;
float spatial_scale;
size_t spatial_bins_x;
size_t spatial_bins_y;
std::string mode;
ov::element::Type model_type;
std::tie(input_shape, coords_shape, output_dim, group_size, spatial_scale,
spatial_bins_x, spatial_bins_y, mode, model_type, targetDevice) = this->GetParam();
ov::ParameterVector params {std::make_shared<ov::op::v0::Parameter>(model_type, ov::Shape(input_shape)),
std::make_shared<ov::op::v0::Parameter>(model_type, ov::Shape(coords_shape))};
auto psroi_pooling = std::make_shared<ov::op::v0::PSROIPooling>(params[0],
params[1],
output_dim,
group_size,
spatial_scale,
spatial_bins_x,
spatial_bins_y,
mode);
function = std::make_shared<ov::Model>(psroi_pooling->outputs(), params, "psroi_pooling");
}
} // namespace test
} // namespace ov