Refactor BinaryConvolutionLayerTest and BucketizeLayerTest (#19654)

* Refactor BinaryConvolutionLayerTest

* Refactor BucketizeLayerTest
This commit is contained in:
Oleg Pipikin 2023-10-10 11:25:57 +02:00 committed by GitHub
parent 0fec05ecf2
commit 34a86ecb3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 287 additions and 48 deletions

View File

@ -4,16 +4,17 @@
#include <vector>
#include "single_layer_tests/binary_convolution.hpp"
#include "single_op_tests/binary_convolution.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
using ov::test::BinaryConvolutionLayerTest;
namespace {
const std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::FP32, InferenceEngine::Precision::FP16,
InferenceEngine::Precision::I32};
const std::vector<ov::element::Type> model_types = {
ov::element::f32,
ov::element::f16,
ov::element::i32};
/* ============= 2D Binary Convolution ============= */
const std::vector<std::vector<size_t>> kernels = {{3, 3}, {3, 5}};
@ -24,6 +25,10 @@ const std::vector<std::vector<size_t>> dilations = {{1, 1}, {3, 1}};
const std::vector<size_t> numOutChannels = {1, 5};
const std::vector<float> padValues = {0, 1};
const std::vector<std::vector<ov::Shape>> input_shapes_static = {
{{ 1, 3, 30, 30}},
};
const auto binConv2DParams_ExplicitPadding = ::testing::Combine(
::testing::ValuesIn(kernels),
::testing::ValuesIn(strides),
@ -48,12 +53,8 @@ INSTANTIATE_TEST_SUITE_P(
smoke_BinaryConvolution2D_ExplicitPadding, BinaryConvolutionLayerTest,
::testing::Combine(
binConv2DParams_ExplicitPadding,
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(std::vector<size_t>({1, 3, 30, 30})),
::testing::ValuesIn(model_types),
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)),
::testing::Values(ov::test::utils::DEVICE_CPU)),
BinaryConvolutionLayerTest::getTestCaseName);
@ -61,12 +62,8 @@ INSTANTIATE_TEST_SUITE_P(
smoke_BinaryConvolution2D_AutoPadValid, BinaryConvolutionLayerTest,
::testing::Combine(
binConv2DParams_ValidPadding,
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(std::vector<size_t>({1, 3, 30, 30})),
::testing::ValuesIn(model_types),
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)),
::testing::Values(ov::test::utils::DEVICE_CPU)),
BinaryConvolutionLayerTest::getTestCaseName);

View File

@ -4,53 +4,52 @@
#include <vector>
#include "single_layer_tests/bucketize.hpp"
#include "single_op_tests/bucketize.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
using ov::test::BucketizeLayerTest;
const std::vector<std::vector<size_t>> dataShapes = {
{1, 20, 20},
{2, 3, 50, 50}
namespace {
const std::vector<std::vector<ov::Shape>> input_shapes_static = {
//data_shape, bucket_shape
{{ 1, 20, 20 }, {5}},
{{ 1, 20, 20 }, {20}},
{{ 1, 20, 20 }, {100}},
{{ 2, 3, 50, 50 }, {5}},
{{ 2, 3, 50, 50 }, {20}},
{{ 2, 3, 50, 50 }, {100}}
};
const std::vector<std::vector<size_t>> bucketsShapes = {
{5},
{20},
{100}
const std::vector<ov::element::Type> in_types = {
ov::element::f32,
ov::element::f16,
ov::element::i64,
ov::element::i32
};
const std::vector<InferenceEngine::Precision> inPrc = {
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16,
InferenceEngine::Precision::I64,
InferenceEngine::Precision::I32
};
const std::vector<InferenceEngine::Precision> netPrc = {
InferenceEngine::Precision::I64,
InferenceEngine::Precision::I32
const std::vector<ov::element::Type> model_types = {
ov::element::i64,
ov::element::i32
};
const auto test_Bucketize_right_edge = ::testing::Combine(
::testing::ValuesIn(dataShapes),
::testing::ValuesIn(bucketsShapes),
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)),
::testing::Values(true),
::testing::ValuesIn(inPrc),
::testing::ValuesIn(inPrc),
::testing::ValuesIn(netPrc),
::testing::ValuesIn(in_types),
::testing::ValuesIn(in_types),
::testing::ValuesIn(model_types),
::testing::Values(ov::test::utils::DEVICE_CPU)
);
const auto test_Bucketize_left_edge = ::testing::Combine(
::testing::ValuesIn(dataShapes),
::testing::ValuesIn(bucketsShapes),
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)),
::testing::Values(false),
::testing::ValuesIn(inPrc),
::testing::ValuesIn(inPrc),
::testing::ValuesIn(netPrc),
::testing::ValuesIn(in_types),
::testing::ValuesIn(in_types),
::testing::ValuesIn(model_types),
::testing::Values(ov::test::utils::DEVICE_CPU)
);
INSTANTIATE_TEST_SUITE_P(smoke_TestsBucketize_right, BucketizeLayerTest, test_Bucketize_right_edge, BucketizeLayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_TestsBucketize_left, BucketizeLayerTest, test_Bucketize_left_edge, BucketizeLayerTest::getTestCaseName);
} // namespace

View File

@ -7,7 +7,6 @@
#include "shared_test_classes/single_layer/binary_convolution.hpp"
namespace LayerTestsDefinitions {
TEST_P(BinaryConvolutionLayerTest, CompareWithRefs) {
Run();
}

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/binary_convolution.hpp"
namespace ov {
namespace test {
TEST_P(BinaryConvolutionLayerTest, 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/bucketize.hpp"
namespace ov {
namespace test {
TEST_P(BucketizeLayerTest, Inference) {
run();
}
} // namespace test
} // namespace ov

View File

@ -0,0 +1,42 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <tuple>
#include <vector>
#include <string>
#include <memory>
#include "shared_test_classes/base/ov_subgraph.hpp"
namespace ov {
namespace test {
using binConvSpecificParams = std::tuple<
std::vector<size_t>, // Kernel size
std::vector<size_t>, // Strides
std::vector<ptrdiff_t>, // Pads begin
std::vector<ptrdiff_t>, // Pads end
std::vector<size_t>, // Dilations
size_t, // Num Output channels
ov::op::PadType, // Padding type
float>; // Padding value
using binaryConvolutionTestParamsSet = std::tuple<
binConvSpecificParams, //
ov::element::Type, // Model Type
std::vector<InputShape>, // Input shape
std::string>; // Device name
class BinaryConvolutionLayerTest : public testing::WithParamInterface<binaryConvolutionTestParamsSet>,
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<binaryConvolutionTestParamsSet>& obj);
protected:
void SetUp() override;
};
} // namespace test
} // namespace ov

View File

@ -0,0 +1,33 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <tuple>
#include <string>
#include "shared_test_classes/base/ov_subgraph.hpp"
namespace ov {
namespace test {
using bucketizeParamsTuple = std::tuple<
std::vector<InputShape>, // data shape, bucket shape
bool, // Right edge of interval
ov::element::Type, // Data input precision
ov::element::Type, // Buckets input precision
ov::element::Type, // Output precision
std::string>; // Device name
class BucketizeLayerTest : public testing::WithParamInterface<bucketizeParamsTuple>,
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<bucketizeParamsTuple>& obj);
protected:
void SetUp() override;
};
} // namespace test
} // namespace ov

View File

@ -5,7 +5,6 @@
#include "shared_test_classes/single_layer/bucketize.hpp"
namespace LayerTestsDefinitions {
std::string BucketizeLayerTest::getTestCaseName(const testing::TestParamInfo<bucketizeParamsTuple>& obj) {
InferenceEngine::SizeVector dataShape;
InferenceEngine::SizeVector bucketsShape;

View File

@ -0,0 +1,79 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/single_op/binary_convolution.hpp"
#include "ov_models/builders.hpp"
#include "common_test_utils/ov_tensor_utils.hpp"
namespace ov {
namespace test {
std::string BinaryConvolutionLayerTest::getTestCaseName(const testing::TestParamInfo<binaryConvolutionTestParamsSet>& obj) {
binConvSpecificParams bin_conv_params;
ov::element::Type model_type;
std::vector<InputShape> shapes;
std::string target_device;
std::tie(bin_conv_params, model_type, shapes, target_device) = obj.param;
ov::op::PadType pad_type;
std::vector<size_t> kernel, stride, dilation;
std::vector<ptrdiff_t> pad_begin, padEnd;
size_t conv_out_channels;
float pad_value;
std::tie(kernel, stride, pad_begin, padEnd, dilation, conv_out_channels, pad_type, pad_value) = bin_conv_params;
std::ostringstream result;
result << "IS=(";
for (size_t i = 0lu; i < shapes.size(); i++) {
result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : "");
}
result << ")_TS=";
for (size_t i = 0lu; i < shapes.front().second.size(); i++) {
result << "{";
for (size_t j = 0lu; j < shapes.size(); j++) {
result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : "");
}
result << "}_";
}
result << "KS=" << ov::test::utils::vec2str(kernel) << "_";
result << "S=" << ov::test::utils::vec2str(stride) << "_";
result << "PB=" << ov::test::utils::vec2str(pad_begin) << "_";
result << "PE=" << ov::test::utils::vec2str(padEnd) << "_";
result << "D=" << ov::test::utils::vec2str(dilation) << "_";
result << "O=" << conv_out_channels << "_";
result << "AP=" << pad_type << "_";
result << "PV=" << pad_value << "_";
result << "netPRC=" << model_type.get_type_name() << "_";
result << "trgDev=" << target_device;
return result.str();
}
void BinaryConvolutionLayerTest::SetUp() {
binConvSpecificParams bin_conv_params;
ov::element::Type model_type;
std::vector<InputShape> shapes;
std::tie(bin_conv_params, model_type, shapes, targetDevice) = this->GetParam();
init_input_shapes(shapes);
ov::op::PadType pad_type;
std::vector<size_t> kernel_size, strides, dilations;
std::vector<ptrdiff_t> pads_begin, pads_end;
size_t num_out_channels;
float pad_value;
std::tie(kernel_size, strides, pads_begin, pads_end, dilations, num_out_channels, pad_type, pad_value) = bin_conv_params;
ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(model_type, inputDynamicShapes.front())};
params[0]->set_friendly_name("a_data_batch");
// TODO: refactor build BinaryConvolution op to accept filters input as Parameter
auto bin_conv =
ngraph::builder::makeBinaryConvolution(params[0], kernel_size, strides, pads_begin, pads_end, dilations, pad_type, num_out_channels, pad_value);
auto result = std::make_shared<ov::op::v0::Result>(bin_conv);
function = std::make_shared<ov::Model>(ov::OutputVector{result}, params, "BinaryConvolution");
}
} // namespace test
} // namespace ov

View File

@ -0,0 +1,61 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/single_op/bucketize.hpp"
#include "common_test_utils/ov_tensor_utils.hpp"
namespace ov {
namespace test {
std::string BucketizeLayerTest::getTestCaseName(const testing::TestParamInfo<bucketizeParamsTuple>& obj) {
std::vector<InputShape> shapes;
bool with_right_bound;
ov::element::Type in_data_type, in_buckets_type, model_type;
std::string target_device;
std::tie(shapes, with_right_bound, in_data_type, in_buckets_type, model_type, target_device) = obj.param;
std::ostringstream result;
result << "IS=(";
for (size_t i = 0lu; i < shapes.size(); i++) {
result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : "");
}
result << ")_TS=";
for (size_t i = 0lu; i < shapes.front().second.size(); i++) {
result << "{";
for (size_t j = 0lu; j < shapes.size(); j++) {
result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : "");
}
result << "}_";
}
if (with_right_bound)
result << "rightIntervalEdge_";
else
result << "leftIntervalEdge_";
result << "in_data_type=" << in_data_type.get_type_name() << "_";
result << "in_buckets_type=" << in_buckets_type.get_type_name() << "_";
result << "model_type=" << model_type.get_type_name() << "_";
result << "target_device=" << target_device;
return result.str();
}
void BucketizeLayerTest::SetUp() {
std::vector<InputShape> shapes;
bool with_right_bound;
ov::element::Type in_data_type, in_buckets_type, model_type;
std::tie(shapes, with_right_bound, in_data_type, in_buckets_type, model_type, targetDevice) = this->GetParam();
init_input_shapes(shapes);
auto data = std::make_shared<ov::op::v0::Parameter>(in_data_type, inputDynamicShapes[0]);
data->set_friendly_name("a_data");
auto buckets = std::make_shared<ov::op::v0::Parameter>(in_buckets_type, inputDynamicShapes[1]);
buckets->set_friendly_name("b_buckets");
auto bucketize = std::make_shared<ov::op::v3::Bucketize>(data, buckets, model_type, with_right_bound);
auto result = std::make_shared<ov::op::v0::Result>(bucketize);
function = std::make_shared<ov::Model>(result, ov::ParameterVector{data, buckets}, "Bucketize");
}
} // namespace test
} // namespace ov