Skip to content

Commit

Permalink
Refactor negative ProposalBehTest (openvinotoolkit#21190)
Browse files Browse the repository at this point in the history
Co-authored-by: Ilya Lavrenov <ilya.lavrenov@intel.com>
  • Loading branch information
olpipi and ilya-lavrenov authored Nov 21, 2023
1 parent 5d6d6a2 commit a7edeb5
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@
// SPDX-License-Identifier: Apache-2.0
//

#include <vector>
#include "single_layer_tests/invalid_cases/proposal.hpp"

using namespace ngraph::helpers;
using namespace LayerTestsDefinitions;
using namespace BehaviorTestsDefinitions;
#include <vector>

namespace {
using ov::test::ProposalBehTest;

/* ============= 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};
const std::vector<std::vector<float>> img_info_invalid = {{0.f, 225.f, 1.f},
{225.f, -1.f, 1.f},
{225.f, NAN, 1.f},
Expand All @@ -29,27 +27,24 @@ const std::vector<std::vector<float>> img_info_invalid = {{0.f, 225.f, 1.f},
{225.f, 100.f, INFINITY}};

// empty string corresponds to Caffe framework
const std::vector<framework_type> 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_)
);

INSTANTIATE_TEST_SUITE_P(invalid, ProposalBehTest,
::testing::Combine(
proposalParams,
::testing::ValuesIn(img_info_invalid),
::testing::Values(ov::test::utils::DEVICE_CPU)),
ProposalBehTest::getTestCaseName
);
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_));

INSTANTIATE_TEST_SUITE_P(invalid,
ProposalBehTest,
::testing::Combine(proposalParams,
::testing::ValuesIn(img_info_invalid),
::testing::Values(ov::test::utils::DEVICE_CPU)),
ProposalBehTest::getTestCaseName);

} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,21 @@

#pragma once

#include "shared_test_classes/single_layer/proposal.hpp"
#include "shared_test_classes/single_op/proposal.hpp"

namespace BehaviorTestsDefinitions {
namespace ov {
namespace test {
typedef std::tuple<proposalSpecificParams, std::vector<float>, std::string> proposalBehTestParamsSet;

typedef std::tuple<
LayerTestsDefinitions::proposalSpecificParams,
std::vector<float>,
std::string> proposalBehTestParamsSet;

class ProposalBehTest
: public testing::WithParamInterface<proposalBehTestParamsSet>,
virtual public LayerTestsUtils::LayerTestsCommon {
class ProposalBehTest : public testing::WithParamInterface<proposalBehTestParamsSet>,
virtual public ov::test::SubgraphBaseStaticTest {
public:
static std::string getTestCaseName(testing::TestParamInfo<proposalBehTestParamsSet> obj);
InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo &info) const override;

protected:
void SetUp() override;
void Validate() override {};
void Run() override;

const LayerTestsDefinitions::normalize_type normalize = true;
const LayerTestsDefinitions::feat_stride_type feat_stride = 1;
const LayerTestsDefinitions::box_size_scale_type box_size_scale = 2.0f;
const LayerTestsDefinitions::box_coordinate_scale_type box_coordinate_scale = 2.0f;
void run() override;
};

} // namespace BehaviorTestsDefinitions
} // namespace test
} // namespace ov
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,68 @@

#include "single_layer_tests/invalid_cases/proposal.hpp"

using namespace BehaviorTestsDefinitions;
using namespace LayerTestsDefinitions;
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 ProposalBehTest::getTestCaseName(testing::TestParamInfo<proposalBehTestParamsSet> obj) {
proposalSpecificParams proposalParams;
std::string targetDevice;
proposalSpecificParams proposal_params;
std::string target_device;
std::vector<float> img_info;
std::tie(proposalParams, img_info, targetDevice) = obj.param;
auto proposalPramString = ProposalLayerTest::SerializeProposalSpecificParams(proposalParams);

std::ostringstream result;
result << "targetDevice=" << targetDevice;
result << "img_info = " << ov::test::utils::vec2str(img_info) << "_";
std::tie(proposal_params, img_info, target_device) = obj.param;

return proposalPramString + result.str();
}
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;

InferenceEngine::Blob::Ptr ProposalBehTest::GenerateInput(const InferenceEngine::InputInfo &info) const {
InferenceEngine::Blob::Ptr blobPtr;

const std::string name = info.name();
if (name == "scores") {
blobPtr = FuncTestUtils::createAndFillBlobFloat(info.getTensorDesc(), 1, 0, 1000, 8234231);
} else if (name == "boxes") {
blobPtr = FuncTestUtils::createAndFillBlobFloatNormalDistribution(info.getTensorDesc(), 0.0f, 0.2f, 7235346);
}
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;

return blobPtr;
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 << "targetDevice=" << target_device;
result << "img_info = " << ov::test::utils::vec2str(img_info) << "_";
result << "framework=" << framework << "_";
return result.str();
}

void ProposalBehTest::SetUp() {
proposalSpecificParams proposalParams;
std::vector<float> img_info;

std::tie(proposalParams, img_info, targetDevice) = this->GetParam();
base_size_type base_size;
pre_nms_topn_type pre_nms_topn;
post_nms_topn_type post_nms_topn;
nms_thresh_type nms_thresh;
min_size_type min_size;
ratio_type ratio;
scale_type scale;
clip_before_nms_type clip_before_nms;
clip_after_nms_type clip_after_nms;
framework_type framework;

std::tie(base_size, pre_nms_topn,

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,
Expand All @@ -64,15 +79,11 @@ void ProposalBehTest::SetUp() {
size_t bottom_h = base_size;
size_t num_anchors = ratio.size() * scale.size();

std::vector<size_t> scoresShape = {1, 2 * num_anchors, bottom_h, bottom_w};
std::vector<size_t> boxesShape = {1, 4 * num_anchors, bottom_h, bottom_w};
std::vector<size_t> imageInfoShape = {3};
ov::Shape scores_shape = {1, 2 * num_anchors, bottom_h, bottom_w};
ov::Shape boxes_shape = {1, 4 * num_anchors, bottom_h, bottom_w};

auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(InferenceEngine::Precision::FP16);
ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(ngPrc, ov::Shape(scoresShape)),
std::make_shared<ov::op::v0::Parameter>(ngPrc, ov::Shape(boxesShape))};
params[0]->set_friendly_name("scores");
params[1]->set_friendly_name("boxes");
ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(ov::element::f16, scores_shape),
std::make_shared<ov::op::v0::Parameter>(ov::element::f16, boxes_shape)};

ov::op::v0::Proposal::Attributes attrs;
attrs.base_size = base_size;
Expand All @@ -95,18 +106,24 @@ void ProposalBehTest::SetUp() {

auto proposal = std::make_shared<ov::op::v4::Proposal>(params[0], params[1], image_shape, attrs);

ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(proposal)};
function = std::make_shared<ngraph::Function>(results, params, "proposal");
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(proposal)};
function = std::make_shared<ov::Model>(results, params, "proposal");
}

void ProposalBehTest::Run() {
LoadNetwork();
GenerateInputs();
Infer();
void ProposalBehTest::run() {
std::vector<ov::Shape> input_shapes;
for (const auto& param : function->get_parameters())
input_shapes.emplace_back(param->get_shape());
init_input_shapes(ov::test::static_shapes_to_test_representation(input_shapes));

compile_model();
for (const auto& targetStaticShapeVec : targetStaticShapes) {
generate_inputs(targetStaticShapeVec);
validate();
}
}

TEST_P(ProposalBehTest, CompareWithRefs) {
SKIP_IF_CURRENT_TEST_IS_DISABLED()

ASSERT_THROW(Run(), InferenceEngine::Exception);
TEST_P(ProposalBehTest, Inference) {
ASSERT_THROW(run(), ov::Exception);
}
} // namespace test
} // namespace ov
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,35 @@

#pragma once

#include <tuple>
#include <memory>
#include <string>
#include <tuple>
#include <vector>
#include <memory>

#include "shared_test_classes/base/ov_subgraph.hpp"
#include "common_test_utils/test_enums.hpp"
#include "shared_test_classes/base/ov_subgraph.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
>;
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 {
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<proposalLayerTestParamsSet>& obj);

protected:
void SetUp() override;
};
Expand Down

0 comments on commit a7edeb5

Please sign in to comment.