Refactor ConvReshapeAct (#21219)
This commit is contained in:
parent
558e713043
commit
eaa3098920
@ -6,6 +6,9 @@
|
||||
#include "subgraph_tests/reshape_permute_conv_permute_reshape_act.hpp"
|
||||
#include "common_test_utils/test_constants.hpp"
|
||||
|
||||
namespace {
|
||||
using ov::test::ConvReshapeAct;
|
||||
|
||||
std::vector<std::array<size_t, 4>> input_shapes {
|
||||
{1, 1, 166, 2},
|
||||
{1, 1, 144, 2},
|
||||
@ -24,23 +27,21 @@ std::vector<size_t> output_channels {
|
||||
4,
|
||||
};
|
||||
|
||||
std::vector<InferenceEngine::Precision> netPrecisions = {
|
||||
InferenceEngine::Precision::FP32,
|
||||
InferenceEngine::Precision::FP16,
|
||||
std::vector<ov::element::Type> model_types = {
|
||||
ov::element::f32,
|
||||
ov::element::f16,
|
||||
};
|
||||
|
||||
std::map<std::string, std::string> additional_config = { };
|
||||
|
||||
namespace SubgraphTestsDefinitions {
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_basic, ConvReshapeAct,
|
||||
::testing::Combine(
|
||||
::testing::ValuesIn(netPrecisions),
|
||||
::testing::Values(ov::test::utils::DEVICE_CPU),
|
||||
::testing::ValuesIn(input_shapes),
|
||||
::testing::ValuesIn(kernel_shapes),
|
||||
::testing::ValuesIn(output_channels),
|
||||
::testing::Values(additional_config)),
|
||||
ConvReshapeAct::getTestCaseName);
|
||||
} // namespace SubgraphTestsDefinitions
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_basic, ConvReshapeAct,
|
||||
::testing::Combine(
|
||||
::testing::ValuesIn(model_types),
|
||||
::testing::Values(ov::test::utils::DEVICE_CPU),
|
||||
::testing::ValuesIn(input_shapes),
|
||||
::testing::ValuesIn(kernel_shapes),
|
||||
::testing::ValuesIn(output_channels),
|
||||
::testing::Values(additional_config)),
|
||||
ConvReshapeAct::getTestCaseName);
|
||||
|
||||
} // namespace
|
@ -8,6 +8,9 @@
|
||||
|
||||
#include "common_test_utils/test_constants.hpp"
|
||||
|
||||
namespace {
|
||||
using ov::test::ConvReshapeAct;
|
||||
|
||||
std::vector<std::array<size_t, 4>> input_shapes{
|
||||
{1, 1, 166, 2},
|
||||
{1, 1, 144, 2},
|
||||
@ -26,23 +29,21 @@ std::vector<size_t> output_channels{
|
||||
4,
|
||||
};
|
||||
|
||||
std::vector<InferenceEngine::Precision> netPrecisions = {
|
||||
InferenceEngine::Precision::FP32,
|
||||
InferenceEngine::Precision::FP16,
|
||||
std::vector<ov::element::Type> model_types = {
|
||||
ov::element::f32,
|
||||
};
|
||||
|
||||
std::vector<std::map<std::string, std::string>> configs = {
|
||||
{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "2340"}},
|
||||
{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}};
|
||||
|
||||
namespace SubgraphTestsDefinitions {
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_basic,
|
||||
ConvReshapeAct,
|
||||
::testing::Combine(::testing::ValuesIn(netPrecisions),
|
||||
::testing::Combine(::testing::ValuesIn(model_types),
|
||||
::testing::Values(ov::test::utils::DEVICE_GNA),
|
||||
::testing::ValuesIn(input_shapes),
|
||||
::testing::ValuesIn(kernel_shapes),
|
||||
::testing::ValuesIn(output_channels),
|
||||
::testing::ValuesIn(configs)),
|
||||
ConvReshapeAct::getTestCaseName);
|
||||
} // namespace SubgraphTestsDefinitions
|
||||
} // namespace
|
||||
|
@ -6,6 +6,9 @@
|
||||
#include "subgraph_tests/reshape_permute_conv_permute_reshape_act.hpp"
|
||||
#include "common_test_utils/test_constants.hpp"
|
||||
|
||||
namespace {
|
||||
using ov::test::ConvReshapeAct;
|
||||
|
||||
std::vector<std::array<size_t, 4>> input_shapes {
|
||||
{1, 1, 166, 2},
|
||||
{1, 1, 144, 2},
|
||||
@ -24,23 +27,21 @@ std::vector<size_t> output_channels {
|
||||
4,
|
||||
};
|
||||
|
||||
std::vector<InferenceEngine::Precision> netPrecisions = {
|
||||
InferenceEngine::Precision::FP32,
|
||||
InferenceEngine::Precision::FP16,
|
||||
std::vector<ov::element::Type> model_types = {
|
||||
ov::element::f32,
|
||||
ov::element::f16,
|
||||
};
|
||||
|
||||
std::map<std::string, std::string> additional_config = {};
|
||||
|
||||
namespace SubgraphTestsDefinitions {
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_basic, ConvReshapeAct,
|
||||
::testing::Combine(
|
||||
::testing::ValuesIn(netPrecisions),
|
||||
::testing::Values(ov::test::utils::DEVICE_GPU),
|
||||
::testing::ValuesIn(input_shapes),
|
||||
::testing::ValuesIn(kernel_shapes),
|
||||
::testing::ValuesIn(output_channels),
|
||||
::testing::Values(additional_config)),
|
||||
ConvReshapeAct::getTestCaseName);
|
||||
} // namespace SubgraphTestsDefinitions
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_basic, ConvReshapeAct,
|
||||
::testing::Combine(
|
||||
::testing::ValuesIn(model_types),
|
||||
::testing::Values(ov::test::utils::DEVICE_GPU),
|
||||
::testing::ValuesIn(input_shapes),
|
||||
::testing::ValuesIn(kernel_shapes),
|
||||
::testing::ValuesIn(output_channels),
|
||||
::testing::Values(additional_config)),
|
||||
ConvReshapeAct::getTestCaseName);
|
||||
|
||||
} // namespace
|
||||
|
@ -6,10 +6,10 @@
|
||||
|
||||
#include "shared_test_classes/subgraph/reshape_permute_conv_permute_reshape_act.hpp"
|
||||
|
||||
namespace SubgraphTestsDefinitions {
|
||||
|
||||
TEST_P(ConvReshapeAct, CompareWithRefs) {
|
||||
Run();
|
||||
namespace ov {
|
||||
namespace test {
|
||||
TEST_P(ConvReshapeAct, Inference) {
|
||||
run();
|
||||
}
|
||||
|
||||
} // namespace SubgraphTestsDefinitions
|
||||
} // namespace test
|
||||
} // namespace ov
|
||||
|
@ -10,13 +10,13 @@
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include "shared_test_classes/base/layer_test_utils.hpp"
|
||||
#include "shared_test_classes/base/ov_subgraph.hpp"
|
||||
#include "ov_models/utils/ov_helpers.hpp"
|
||||
#include "ov_models/builders.hpp"
|
||||
|
||||
namespace SubgraphTestsDefinitions {
|
||||
namespace ov {
|
||||
namespace test {
|
||||
typedef std::tuple<
|
||||
InferenceEngine::Precision, // Network Precision
|
||||
ov::element::Type, // Network Type
|
||||
std::string, // Target Device
|
||||
std::array<size_t, 4>, // Input shape
|
||||
std::array<size_t, 2>, // Kernel shape
|
||||
@ -25,13 +25,13 @@ namespace SubgraphTestsDefinitions {
|
||||
> ConvReshapeActParams;
|
||||
|
||||
class ConvReshapeAct : public testing::WithParamInterface<ConvReshapeActParams>,
|
||||
virtual public LayerTestsUtils::LayerTestsCommon {
|
||||
virtual public ov::test::SubgraphBaseStaticTest {
|
||||
public:
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<ConvReshapeActParams>& obj);
|
||||
|
||||
protected:
|
||||
void SetUp() override;
|
||||
void Run() override;
|
||||
};
|
||||
|
||||
} // namespace SubgraphTestsDefinitions
|
||||
} // namespace test
|
||||
} // namespace ov
|
||||
|
@ -3,103 +3,82 @@
|
||||
//
|
||||
|
||||
#include "shared_test_classes/subgraph/reshape_permute_conv_permute_reshape_act.hpp"
|
||||
#include "ov_models/builders.hpp"
|
||||
|
||||
namespace SubgraphTestsDefinitions {
|
||||
std::string ConvReshapeAct::getTestCaseName(const testing::TestParamInfo<ConvReshapeActParams>& obj) {
|
||||
InferenceEngine::Precision netPrecision;
|
||||
std::string targetName;
|
||||
std::array<size_t, 4> input_shape;
|
||||
std::array<size_t, 2> kernel_shape;
|
||||
size_t output_channels;
|
||||
std::map<std::string, std::string> configuration;
|
||||
namespace ov {
|
||||
namespace test {
|
||||
std::string ConvReshapeAct::getTestCaseName(const testing::TestParamInfo<ConvReshapeActParams>& obj) {
|
||||
ov::element::Type model_type;
|
||||
std::string targetName;
|
||||
std::array<size_t, 4> input_shape;
|
||||
std::array<size_t, 2> kernel_shape;
|
||||
size_t output_channels;
|
||||
std::map<std::string, std::string> configuration;
|
||||
|
||||
|
||||
std::tie(netPrecision, targetName, input_shape, kernel_shape, output_channels, configuration) = obj.param;
|
||||
std::ostringstream results;
|
||||
std::tie(model_type, targetName, input_shape, kernel_shape, output_channels, configuration) = obj.param;
|
||||
std::ostringstream results;
|
||||
|
||||
results << "IS=" << ov::test::utils::vec2str(std::vector<size_t>(input_shape.begin(), input_shape.end())) << "_";
|
||||
results << "KS=" << ov::test::utils::vec2str(std::vector<size_t>(kernel_shape.begin(), kernel_shape.end())) << "_";
|
||||
results << "OC=" << output_channels << "_";
|
||||
results << "netPRC=" << netPrecision.name() << "_";
|
||||
results << "targetDevice=" << targetName;
|
||||
for (auto const& configItem : configuration) {
|
||||
results << "_configItem=" << configItem.first << "_" << configItem.second;
|
||||
}
|
||||
return results.str();
|
||||
results << "IS=" << ov::test::utils::vec2str(std::vector<size_t>(input_shape.begin(), input_shape.end())) << "_";
|
||||
results << "KS=" << ov::test::utils::vec2str(std::vector<size_t>(kernel_shape.begin(), kernel_shape.end())) << "_";
|
||||
results << "OC=" << output_channels << "_";
|
||||
results << "netPRC=" << model_type.get_type_name() << "_";
|
||||
results << "targetDevice=" << targetName;
|
||||
for (auto const& configItem : configuration) {
|
||||
results << "_configItem=" << configItem.first << "_" << configItem.second;
|
||||
}
|
||||
return results.str();
|
||||
}
|
||||
|
||||
void ConvReshapeAct::SetUp() {
|
||||
InferenceEngine::Precision netPrecision;
|
||||
std::array<size_t, 4> input_shape;
|
||||
std::array<size_t, 2> kernel_shape;
|
||||
size_t output_channels;
|
||||
std::map<std::string, std::string> additional_config;
|
||||
void ConvReshapeAct::SetUp() {
|
||||
ov::element::Type model_type;
|
||||
std::array<size_t, 4> input_shape;
|
||||
std::array<size_t, 2> kernel_shape;
|
||||
size_t output_channels;
|
||||
std::map<std::string, std::string> additional_config;
|
||||
|
||||
std::tie(netPrecision, targetDevice, input_shape, kernel_shape, output_channels, additional_config) = this->GetParam();
|
||||
std::tie(model_type, targetDevice, input_shape, kernel_shape, output_channels, additional_config) = this->GetParam();
|
||||
|
||||
configuration.insert(additional_config.begin(), additional_config.end());
|
||||
configuration.insert(additional_config.begin(), additional_config.end());
|
||||
|
||||
const std::size_t input_dim = std::accumulate(input_shape.begin(), input_shape.end(), 1, std::multiplies<size_t>());
|
||||
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
|
||||
const std::size_t input_dim = std::accumulate(input_shape.begin(), input_shape.end(), 1, std::multiplies<size_t>());
|
||||
|
||||
std::vector<size_t> input_dims { 1, input_dim };
|
||||
std::vector<size_t> reshape_in_dims = std::vector<size_t>(input_shape.begin(), input_shape.end());
|
||||
std::vector<size_t> permute_in_order = { 0, 3, 1, 2 };
|
||||
std::vector<size_t> permute_out_order = { 0, 2, 3, 1 };
|
||||
std::vector<size_t> reshape_out_dims = { 1, input_shape[0] * input_shape[1] * (input_shape[2] - kernel_shape[1] + 1) * output_channels };
|
||||
std::vector<size_t> input_dims { 1, input_dim };
|
||||
std::vector<size_t> reshape_in_dims = std::vector<size_t>(input_shape.begin(), input_shape.end());
|
||||
std::vector<size_t> permute_in_order = { 0, 3, 1, 2 };
|
||||
std::vector<size_t> permute_out_order = { 0, 2, 3, 1 };
|
||||
std::vector<size_t> reshape_out_dims = { 1, input_shape[0] * input_shape[1] * (input_shape[2] - kernel_shape[1] + 1) * output_channels };
|
||||
|
||||
ov::ParameterVector input_parameter {std::make_shared<ov::op::v0::Parameter>(ngPrc, ov::Shape(input_dims))};
|
||||
ov::ParameterVector input_parameter {std::make_shared<ov::op::v0::Parameter>(model_type, ov::Shape(input_dims))};
|
||||
|
||||
auto reshape_in_pattern = std::make_shared<ngraph::op::Constant>(ngraph::element::i64,
|
||||
ngraph::Shape{4},
|
||||
reshape_in_dims);
|
||||
auto reshape_in = std::make_shared<ngraph::op::v1::Reshape>(input_parameter[0], reshape_in_pattern, false);
|
||||
auto reshape_in_pattern = std::make_shared<ov::op::v0::Constant>(ov::element::i64,
|
||||
ov::Shape{4},
|
||||
reshape_in_dims);
|
||||
auto reshape_in = std::make_shared<ov::op::v1::Reshape>(input_parameter[0], reshape_in_pattern, false);
|
||||
|
||||
auto permute_in_params = std::make_shared<ngraph::opset1::Constant>(ngraph::element::i64,
|
||||
ngraph::Shape{4},
|
||||
ngraph::Shape{permute_in_order});
|
||||
auto permute_in = std::make_shared<ngraph::opset1::Transpose>(reshape_in, permute_in_params);
|
||||
auto permute_in_params = std::make_shared<ov::op::v0::Constant>(ov::element::i64,
|
||||
ov::Shape{4},
|
||||
ov::Shape{permute_in_order});
|
||||
auto permute_in = std::make_shared<ov::op::v1::Transpose>(reshape_in, permute_in_params);
|
||||
|
||||
auto conv = ngraph::builder::makeConvolution(permute_in, ngPrc, {kernel_shape[0], kernel_shape[1]}, {1, 1}, {0, 0}, {0, 0}, {1, 1},
|
||||
ngraph::op::PadType::VALID, output_channels);
|
||||
auto conv = ngraph::builder::makeConvolution(permute_in, model_type, {kernel_shape[0], kernel_shape[1]}, {1, 1}, {0, 0}, {0, 0}, {1, 1},
|
||||
ov::op::PadType::VALID, output_channels);
|
||||
|
||||
auto permute_out_params = std::make_shared<ngraph::opset1::Constant>(ngraph::element::i64,
|
||||
ngraph::Shape{4},
|
||||
permute_out_order);
|
||||
auto permute_out = std::make_shared<ngraph::opset1::Transpose>(conv, permute_out_params);
|
||||
auto permute_out_params = std::make_shared<ov::op::v0::Constant>(ov::element::i64,
|
||||
ov::Shape{4},
|
||||
permute_out_order);
|
||||
auto permute_out = std::make_shared<ov::op::v1::Transpose>(conv, permute_out_params);
|
||||
|
||||
auto reshape_out_pattern = std::make_shared<ngraph::op::Constant>(ngraph::element::i64,
|
||||
ngraph::Shape{2},
|
||||
std::vector<size_t>{reshape_out_dims});
|
||||
auto reshape_out_pattern = std::make_shared<ov::op::v0::Constant>(ov::element::i64,
|
||||
ov::Shape{2},
|
||||
std::vector<size_t>{reshape_out_dims});
|
||||
|
||||
auto reshape_out = std::make_shared<ngraph::op::v1::Reshape>(permute_out, reshape_out_pattern, false);
|
||||
auto reshape_out = std::make_shared<ov::op::v1::Reshape>(permute_out, reshape_out_pattern, false);
|
||||
|
||||
auto tanh = std::make_shared<ngraph::op::Tanh>(reshape_out);
|
||||
auto tanh = std::make_shared<ov::op::v0::Tanh>(reshape_out);
|
||||
|
||||
function = std::make_shared<ngraph::Function>(tanh, input_parameter, "conv_reshape_act");
|
||||
}
|
||||
function = std::make_shared<ov::Model>(tanh, input_parameter, "conv_reshape_act");
|
||||
}
|
||||
|
||||
void ConvReshapeAct::Run() {
|
||||
SKIP_IF_CURRENT_TEST_IS_DISABLED()
|
||||
|
||||
LoadNetwork();
|
||||
|
||||
inferRequest = executableNetwork.CreateInferRequest();
|
||||
inputs.clear();
|
||||
|
||||
for (const auto &input : cnnNetwork.getInputsInfo()) {
|
||||
const auto &info = input.second;
|
||||
auto tensorDesc = info->getTensorDesc();
|
||||
|
||||
auto blob = FuncTestUtils::createAndFillBlobFloat(tensorDesc, 2, -1, 100, 111);
|
||||
|
||||
FuncTestUtils::fillInputsBySinValues(blob);
|
||||
inferRequest.SetBlob(info->name(), blob);
|
||||
inputs.push_back(blob);
|
||||
}
|
||||
inferRequest.Infer();
|
||||
|
||||
threshold = 0.1;
|
||||
Validate();
|
||||
}
|
||||
} // namespace SubgraphTestsDefinitions
|
||||
} // namespace test
|
||||
} // namespace ov
|
||||
|
Loading…
Reference in New Issue
Block a user