diff --git a/docs/template_plugin/tests/functional/op_reference/mvn.cpp b/docs/template_plugin/tests/functional/op_reference/mvn.cpp new file mode 100644 index 00000000000000..5321164807b852 --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/mvn.cpp @@ -0,0 +1,254 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include +#include +#include +#include +#include + +#include "base_reference_test.hpp" + +using namespace ngraph; +using namespace InferenceEngine; +using namespace reference_tests; + +// ------------------------------ V0 ------------------------------ + +struct MVN1Params { + MVN1Params(const Tensor& paramInput, const ngraph::AxisSet& paramReductionAxes, const bool paramAcrossChannels, const bool paramNormalizeVariance, + const double paramEps, const Tensor& paramExpected) + : input(paramInput), + reductionAxes(paramReductionAxes), + acrossChannels(paramAcrossChannels), + normalizeVariance(paramNormalizeVariance), + eps(paramEps), + expected(paramExpected) {} + Tensor input; + ngraph::AxisSet reductionAxes; + bool acrossChannels; + bool normalizeVariance; + double eps; + Tensor expected; +}; + +class ReferenceMVN1LayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.input, params.reductionAxes, params.acrossChannels, params.normalizeVariance, params.eps); + inputData = {params.input.data}; + refOutData = {params.expected.data}; + } + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "shape=" << param.input.shape; + result << "_iType=" << param.input.type; + if (!param.reductionAxes.empty()) { + result << "_reductionAccess=" << CommonTestUtils::vec2str(param.reductionAxes.to_vector()); + } else { + result << "_acrossChannels=" << (param.acrossChannels ? "TRUE" : "FALSE"); + } + result << "_normalizeVariance=" << (param.normalizeVariance ? "TRUE" : "FALSE"); + result << "_eps=" << param.eps; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const Tensor& input, const ngraph::AxisSet& reductionAxes, const bool acrossChannels, + const bool normalizeVariance, const double eps) { + const auto in = std::make_shared(input.type, input.shape); + auto mvn = std::make_shared(in, acrossChannels, normalizeVariance, eps); + if (!reductionAxes.empty()) { + mvn = std::make_shared(in, reductionAxes, normalizeVariance, eps); + } + return std::make_shared(NodeVector {mvn}, ParameterVector {in}); + } +}; + +TEST_P(ReferenceMVN1LayerTest, CompareWithHardcodedRefs) { + Exec(); +} + +const ngraph::AxisSet emptyReductionAxes {}; + +INSTANTIATE_TEST_SUITE_P( + smoke_MVN1_With_Hardcoded_Refs, ReferenceMVN1LayerTest, + ::testing::Values( + // across_channels=false, variance=false + MVN1Params(Tensor {{1, 3, 3, 3}, ngraph::element::f32, std::vector {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9}}, + emptyReductionAxes, + false, + false, + 1e-9, + Tensor {{1, 3, 3, 3}, ngraph::element::f32, std::vector {-4, -3, -2, -1, 0, 1, 2, 3, 4, -4, -3, -2, -1, 0, + 1, 2, 3, 4, -4, -3, -2, -1, 0, 1, 2, 3, 4}}), + // across_channels=true, variance=false + MVN1Params( + Tensor {{1, 3, 2, 2}, ngraph::element::f32, std::vector {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3}}, + emptyReductionAxes, + true, + false, + 1e-9, + Tensor {{1, 3, 2, 2}, ngraph::element::f32, std::vector {-3.25, -2.25, -1.25, -0.25, 0.75, 1.75, 2.75, 3.75, 4.75, -3.25, -2.25, -1.25}}), + // across_channels=false, variance=true + MVN1Params(Tensor {{1, 3, 3, 3}, ngraph::element::f32, std::vector {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9}}, + emptyReductionAxes, + false, + true, + 1e-9, + Tensor {{1, 3, 3, 3}, + ngraph::element::f32, + std::vector {-1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934, + -1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934, + -1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934}}), + // across_channels=true, variance=true + MVN1Params(Tensor {{1, 3, 3, 3}, ngraph::element::f32, std::vector {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9}}, + emptyReductionAxes, + true, + true, + 1e-9, + Tensor {{1, 3, 3, 3}, + ngraph::element::f32, + std::vector {-1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934, + -1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934, + -1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934}}), + // reductionAxes, variance=false + MVN1Params( + Tensor {{1, 3, 2, 2}, ngraph::element::f32, std::vector {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3}}, + {1, 2, 3}, + false, + false, + 1e-9, + Tensor {{1, 3, 2, 2}, ngraph::element::f32, std::vector {-3.25, -2.25, -1.25, -0.25, 0.75, 1.75, 2.75, 3.75, 4.75, -3.25, -2.25, -1.25}}), + // reductionAxes, variance=true + MVN1Params(Tensor {{1, 3, 3, 3}, ngraph::element::f32, std::vector {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9}}, + {2, 3}, + false, + true, + 1e-9, + Tensor {{1, 3, 3, 3}, + ngraph::element::f32, + std::vector {-1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934, + -1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934, + -1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934}})), + ReferenceMVN1LayerTest::getTestCaseName); + +// ------------------------------ V6 ------------------------------ + +struct MVN6Params { + MVN6Params(const Tensor& paramInput, const Tensor& paramReductionAxes, const bool paramNormalizeVariance, const double paramEps, + const ngraph::op::MVNEpsMode mode, const Tensor& paramExpected) + : input(paramInput), + reductionAxes(paramReductionAxes), + normalizeVariance(paramNormalizeVariance), + eps(paramEps), + epsMode(mode), + expected(paramExpected) {} + Tensor input; + Tensor reductionAxes; + bool normalizeVariance; + double eps; + ngraph::op::MVNEpsMode epsMode; + Tensor expected; +}; + +class ReferenceMVN6LayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.input, params.reductionAxes, params.normalizeVariance, params.eps, params.epsMode); + inputData = {params.input.data}; + refOutData = {params.expected.data}; + } + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "shape=" << param.input.shape; + result << "_iType=" << param.input.type; + result << "_reductionAccess=" << CommonTestUtils::vec2str(param.reductionAxes.shape); + result << "_normalizeVariance=" << (param.normalizeVariance ? "TRUE" : "FALSE"); + result << "_eps=" << param.eps; + result << "_eps_mode=" << param.epsMode; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const Tensor& input, const Tensor& reductionAxes, const bool normalizeVariance, const double eps, + const ngraph::op::MVNEpsMode epsMode) { + std::vector dataVector(reductionAxes.shape[0]); + const auto in = std::make_shared(input.type, input.shape); + auto mRef = as(reductionAxes.data); + IE_ASSERT(mRef); + const auto refLockMemory = mRef->rmap(); + const auto refBuffer = refLockMemory.as(); + for (size_t i = 0; i < dataVector.size(); ++i) { + dataVector[i] = refBuffer[i]; + } + const auto axes = std::make_shared(reductionAxes.type, reductionAxes.shape, dataVector); + auto mvn = std::make_shared(in, axes, normalizeVariance, eps, epsMode); + return std::make_shared(NodeVector {mvn}, ParameterVector {in}); + } +}; + +TEST_P(ReferenceMVN6LayerTest, CompareWithHardcodedRefs) { + Exec(); +} + +INSTANTIATE_TEST_SUITE_P( + smoke_MVN6_With_Hardcoded_Refs, ReferenceMVN6LayerTest, + ::testing::Values( + // variance=false, OUTSIDE_SQRT + MVN6Params(Tensor {{1, 3, 3, 3}, ngraph::element::f32, std::vector {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9}}, + Tensor {Shape {2}, ngraph::element::i64, std::vector {2, 3}}, + false, + 1e-9, + ngraph::op::MVNEpsMode::OUTSIDE_SQRT, + Tensor {{1, 3, 3, 3}, ngraph::element::f32, std::vector {-4, -3, -2, -1, 0, 1, 2, 3, 4, -4, -3, -2, -1, 0, + 1, 2, 3, 4, -4, -3, -2, -1, 0, 1, 2, 3, 4}}), + // variance=true, OUTSIDE_SQRT + MVN6Params(Tensor {{1, 3, 3, 3}, ngraph::element::f32, std::vector {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9}}, + Tensor {Shape {2}, ngraph::element::i64, std::vector {2, 3}}, + true, + 1e-9, + ngraph::op::MVNEpsMode::OUTSIDE_SQRT, + Tensor {{1, 3, 3, 3}, + ngraph::element::f32, + std::vector {-1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934, + -1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934, + -1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934}}), + // variance=true, INSIDE_SQRT + MVN6Params(Tensor {{1, 3, 3, 3}, ngraph::element::f32, std::vector {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9}}, + Tensor {Shape {2}, ngraph::element::i64, std::vector {2, 3}}, + true, + 1e-9, + ngraph::op::MVNEpsMode::INSIDE_SQRT, + Tensor {{1, 3, 3, 3}, + ngraph::element::f32, + std::vector {-1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934, + -1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934, + -1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934}}), + // variance=true, another reductionAxes, OUTSIDE_SQRT + MVN6Params(Tensor {{1, 3, 3, 3}, ngraph::element::f32, std::vector({1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9})}, + Tensor {Shape {3}, ngraph::element::i64, std::vector({1, 2, 3})}, + true, + 1e-9, + ngraph::op::MVNEpsMode::OUTSIDE_SQRT, + Tensor {{1, 3, 3, 3}, + ngraph::element::f32, + std::vector {-1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934, + -1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934, + -1.5491934, -1.161895, -0.7745967, -0.38729835, 0., 0.38729835, 0.7745967, 1.161895, 1.5491934}})), + ReferenceMVN6LayerTest::getTestCaseName); diff --git a/inference-engine/tests/functional/inference_engine/serialization/single_layer/mvn.cpp b/inference-engine/tests/functional/inference_engine/serialization/single_layer/mvn.cpp index b5a3cf828c79b7..5af5339f4211d5 100644 --- a/inference-engine/tests/functional/inference_engine/serialization/single_layer/mvn.cpp +++ b/inference-engine/tests/functional/inference_engine/serialization/single_layer/mvn.cpp @@ -17,22 +17,34 @@ const std::vector normalizeVariance = {true, false}; const std::vector> inputShapes = {{1, 10, 5, 7, 8}, {1, 3, 8, 9, 49}}; +const std::vector axes = {{1, 2, 3}, {2, 3}}; const std::vector acrossChannels = {true, false}; +const std::vector emptyReductionAxes = {{}}; +const std::vector emptyAcrossChannels = {{}}; const std::vector epsilon = {0.000000001}; -const auto MvnCases = ::testing::Combine( +const auto MvnAcrossChannels = ::testing::Combine( ::testing::ValuesIn(inputShapes), ::testing::ValuesIn(dataPrecisions), - ::testing::ValuesIn(acrossChannels), ::testing::ValuesIn(normalizeVariance), - ::testing::ValuesIn(epsilon), + ::testing::ValuesIn(emptyReductionAxes), ::testing::ValuesIn(acrossChannels), + ::testing::ValuesIn(normalizeVariance), ::testing::ValuesIn(epsilon), ::testing::Values(CommonTestUtils::DEVICE_CPU)); -TEST_P(MvnLayerTest, Serialize) { +const auto MvnReductionAxes = ::testing::Combine( + ::testing::ValuesIn(inputShapes), ::testing::ValuesIn(dataPrecisions), + ::testing::ValuesIn(axes), ::testing::ValuesIn(emptyAcrossChannels), + ::testing::ValuesIn(normalizeVariance), ::testing::ValuesIn(epsilon), + ::testing::Values(CommonTestUtils::DEVICE_CPU)); + +TEST_P(Mvn1LayerTest, Serialize) { Serialize(); } -INSTANTIATE_TEST_SUITE_P(smoke_MKLDNN_TestsMVN, MvnLayerTest, MvnCases, - MvnLayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_MKLDNN_TestsMVN_across_channels, Mvn1LayerTest, MvnAcrossChannels, + Mvn1LayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_MKLDNN_TestsMVN_reduction_axes, Mvn1LayerTest, MvnReductionAxes, + Mvn1LayerTest::getTestCaseName); // ------------------- MVN-6 ------------------------------------------------- diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/mvn.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/mvn.cpp index 73fdce483efd20..41502bced85b53 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/mvn.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/mvn.cpp @@ -9,6 +9,9 @@ using namespace LayerTestsDefinitions; +const std::vector emptyAcrossChannels = {{}}; +const std::vector emptyReductionAxes = {{}}; + const std::vector> inputShapes = { {8}, {1, 16}, @@ -41,23 +44,35 @@ const std::vector epsilon = { 0.000000001 }; -const auto MvnCases = ::testing::Combine( +std::vector dataPrecisions = { + InferenceEngine::Precision::FP16, + InferenceEngine::Precision::FP32 +}; + +const auto MvnAcrossChannels = ::testing::Combine( ::testing::ValuesIn(inputShapes), - ::testing::Values(InferenceEngine::Precision::FP32), + ::testing::ValuesIn(dataPrecisions), + ::testing::ValuesIn(emptyReductionAxes), ::testing::ValuesIn(acrossChannels), ::testing::ValuesIn(normalizeVariance), ::testing::ValuesIn(epsilon), ::testing::Values(CommonTestUtils::DEVICE_CPU) ); -INSTANTIATE_TEST_SUITE_P(smoke_MKLDNN_TestsMVN, MvnLayerTest, MvnCases, MvnLayerTest::getTestCaseName); +const auto MvnReductionAxes = ::testing::Combine( + ::testing::ValuesIn(std::vector>{{1, 10, 5, 17}, {1, 3, 8, 9}}), + ::testing::Values(InferenceEngine::Precision::FP32), + ::testing::ValuesIn(std::vector{{1, 2, 3}, {2, 3}}), + ::testing::ValuesIn(emptyAcrossChannels), + ::testing::ValuesIn(normalizeVariance), + ::testing::ValuesIn(epsilon), + ::testing::Values(CommonTestUtils::DEVICE_CPU) +); +INSTANTIATE_TEST_SUITE_P(smoke_MKLDNN_TestsMVN_AcrossChannels, Mvn1LayerTest, MvnAcrossChannels, Mvn1LayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_MKLDNN_TestsMVN_ReductionAxes, Mvn1LayerTest, MvnReductionAxes, Mvn1LayerTest::getTestCaseName); -std::vector dataPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16 -}; std::vector idxPrecisions = { InferenceEngine::Precision::I32, diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/mvn.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/mvn.cpp index 6b877960e7f2f6..9a69164baaa169 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/mvn.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/mvn.cpp @@ -13,7 +13,7 @@ using namespace CPUTestUtils; namespace CPULayerTestsDefinitions { typedef std::tuple< - LayerTestsDefinitions::mvnParams, + LayerTestsDefinitions::mvn1Params, CPUSpecificParams, fusingSpecificParams, Precision, // CNNNetwork input precision @@ -24,14 +24,14 @@ class MvnLayerCPUTest : public testing::WithParamInterface obj) { - LayerTestsDefinitions::mvnParams basicParamsSet; + LayerTestsDefinitions::mvn1Params basicParamsSet; CPUSpecificParams cpuParams; fusingSpecificParams fusingParams; Precision inputPrecision, outputPrecision; std::tie(basicParamsSet, cpuParams, fusingParams, inputPrecision, outputPrecision) = obj.param; std::ostringstream result; - result << LayerTestsDefinitions::MvnLayerTest::getTestCaseName(testing::TestParamInfo( + result << LayerTestsDefinitions::Mvn1LayerTest::getTestCaseName(testing::TestParamInfo( basicParamsSet, 0)); result << "_" << "CNNInpPrc=" << inputPrecision.name(); @@ -45,7 +45,7 @@ class MvnLayerCPUTest : public testing::WithParamInterfaceGetParam(); @@ -55,13 +55,17 @@ class MvnLayerCPUTest : public testing::WithParamInterface(param)); auto mvn = ngraph::builder::makeMVN(paramOuts[0], acrossChanels, normalizeVariance, eps); + if (!axes.empty()) { + mvn = ngraph::builder::makeMVN(paramOuts[0], axes, normalizeVariance, eps); + } selectedType = getPrimitiveType() + "_" + inPrc.name(); @@ -128,6 +132,8 @@ const std::vector epsilon = { 0.000000001 }; +const std::vector emptyReductionAxes = {{}}; + std::vector inpPrc = {Precision::I8, Precision::BF16, Precision::FP32}; std::vector outPrc = {Precision::BF16, Precision::FP32}; @@ -162,6 +168,7 @@ const auto Mvn3D = ::testing::Combine( ::testing::Combine( ::testing::ValuesIn(inputShapes_3D), ::testing::Values(InferenceEngine::Precision::FP32), + ::testing::ValuesIn(emptyReductionAxes), ::testing::ValuesIn(acrossChannels), ::testing::ValuesIn(normalizeVariance), ::testing::ValuesIn(epsilon), @@ -177,6 +184,7 @@ const auto Mvn4D = ::testing::Combine( ::testing::Combine( ::testing::ValuesIn(inputShapes_4D), ::testing::Values(InferenceEngine::Precision::FP32), + ::testing::ValuesIn(emptyReductionAxes), ::testing::ValuesIn(acrossChannels), ::testing::ValuesIn(normalizeVariance), ::testing::ValuesIn(epsilon), @@ -192,6 +200,7 @@ const auto Mvn5D = ::testing::Combine( ::testing::Combine( ::testing::ValuesIn(inputShapes_5D), ::testing::Values(InferenceEngine::Precision::FP32), + ::testing::ValuesIn(emptyReductionAxes), ::testing::ValuesIn(acrossChannels), ::testing::ValuesIn(normalizeVariance), ::testing::ValuesIn(epsilon), @@ -216,6 +225,7 @@ const auto Mvn1D = ::testing::Combine( ::testing::Combine( ::testing::ValuesIn(inputShapes_1D), ::testing::Values(InferenceEngine::Precision::FP32), + ::testing::ValuesIn(emptyReductionAxes), ::testing::ValuesIn(acrossChannels), ::testing::ValuesIn(normalizeVariance), ::testing::ValuesIn(epsilon), @@ -232,6 +242,7 @@ const auto Mvn2D = ::testing::Combine( ::testing::Combine( ::testing::ValuesIn(inputShapes_2D), ::testing::Values(InferenceEngine::Precision::FP32), + ::testing::ValuesIn(emptyReductionAxes), ::testing::Values(false), ::testing::ValuesIn(normalizeVariance), ::testing::ValuesIn(epsilon), @@ -248,6 +259,7 @@ const auto Mvn2DTrans = ::testing::Combine( ::testing::Combine( ::testing::ValuesIn(inputShapes_2D), ::testing::Values(InferenceEngine::Precision::FP32), + ::testing::ValuesIn(emptyReductionAxes), ::testing::Values(true), ::testing::ValuesIn(normalizeVariance), ::testing::ValuesIn(epsilon), diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/mvn.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/mvn.cpp index a4e83dc98732c4..9c68172b014423 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/mvn.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/mvn.cpp @@ -9,6 +9,8 @@ using namespace LayerTestsDefinitions; +const std::vector emptyReductionAxes = {{}}; + const std::vector> inputShapes = { {1, 32, 17}, {1, 37, 9}, @@ -41,13 +43,14 @@ const std::vector epsilon = { const auto MvnCases = ::testing::Combine( ::testing::ValuesIn(inputShapes), ::testing::Values(InferenceEngine::Precision::FP32), + ::testing::ValuesIn(emptyReductionAxes), ::testing::ValuesIn(acrossChannels), ::testing::ValuesIn(normalizeVariance), ::testing::ValuesIn(epsilon), ::testing::Values(CommonTestUtils::DEVICE_GPU) ); -INSTANTIATE_TEST_SUITE_P(smoke_CLDNN_TestsMVN, MvnLayerTest, MvnCases, MvnLayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_CLDNN_TestsMVN, Mvn1LayerTest, MvnCases, Mvn1LayerTest::getTestCaseName); std::vector dataPrecisions = { InferenceEngine::Precision::FP32, diff --git a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/mvn.hpp b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/mvn.hpp index c0cc301e714cd3..d1a9ff52a108e0 100644 --- a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/mvn.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/mvn.hpp @@ -8,10 +8,15 @@ namespace LayerTestsDefinitions { +// DEPRECATED, remove MvnLayerTest when KMB and ARM plugin will switch to use Mvn1LayerTest (#60420) TEST_P(MvnLayerTest, CompareWithRefs) { Run(); }; +TEST_P(Mvn1LayerTest, CompareWithRefs) { + Run(); +}; + TEST_P(Mvn6LayerTest, CompareWithRefs) { Run(); }; diff --git a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/mvn.hpp b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/mvn.hpp index 1fac97f20d2372..747e0940da7fef 100644 --- a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/mvn.hpp +++ b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/mvn.hpp @@ -11,6 +11,7 @@ namespace LayerTestsDefinitions { +// DEPRECATED, remove MvnLayerTest when KMB and ARM plugin will switch to use Mvn1LayerTest (#60420) typedef std::tuple< InferenceEngine::SizeVector, // Input shapes InferenceEngine::Precision, // Input precision @@ -27,6 +28,24 @@ class MvnLayerTest : public testing::WithParamInterface, virtual publ void SetUp() override; }; +typedef std::tuple< + InferenceEngine::SizeVector, // Input shapes + InferenceEngine::Precision, // Input precision + ngraph::AxisSet, // Reduction axes + bool, // Across channels + bool, // Normalize variance + double, // Epsilon + std::string // Device name + > mvn1Params; + +class Mvn1LayerTest : public testing::WithParamInterface, virtual public LayerTestsUtils::LayerTestsCommon { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; + typedef std::tuple< InferenceEngine::SizeVector, // Input shapes InferenceEngine::Precision, // Data precision diff --git a/inference-engine/tests/functional/shared_test_classes/src/single_layer/mvn.cpp b/inference-engine/tests/functional/shared_test_classes/src/single_layer/mvn.cpp index 2ae7af4116b302..d4e2a0c0df8536 100644 --- a/inference-engine/tests/functional/shared_test_classes/src/single_layer/mvn.cpp +++ b/inference-engine/tests/functional/shared_test_classes/src/single_layer/mvn.cpp @@ -7,6 +7,7 @@ namespace LayerTestsDefinitions { +// DEPRECATED, remove MvnLayerTest when KMB and ARM plugin will switch to use Mvn1LayerTest (#60420) std::string MvnLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { InferenceEngine::SizeVector inputShapes; InferenceEngine::Precision inputPrecision; @@ -38,6 +39,46 @@ void MvnLayerTest::SetUp() { function = std::make_shared(results, param, "mvn"); } +std::string Mvn1LayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + InferenceEngine::SizeVector inputShapes; + InferenceEngine::Precision inputPrecision; + ngraph::AxisSet axes; + bool acrossChannels, normalizeVariance; + double eps; + std::string targetDevice; + std::tie(inputShapes, inputPrecision, axes, acrossChannels, normalizeVariance, eps, targetDevice) = obj.param; + std::ostringstream result; + result << "IS=" << CommonTestUtils::vec2str(inputShapes) << "_"; + result << "Precision=" << inputPrecision.name() << "_"; + if (!axes.empty()) { + result << "ReductionAccess=" << CommonTestUtils::vec2str(axes.to_vector()) << "_"; + } else { + result << "AcrossChannels=" << (acrossChannels ? "TRUE" : "FALSE") << "_"; + } + result << "NormalizeVariance=" << (normalizeVariance ? "TRUE" : "FALSE") << "_"; + result << "Epsilon=" << eps << "_"; + result << "TargetDevice=" << targetDevice; + return result.str(); +} + +void Mvn1LayerTest::SetUp() { + InferenceEngine::SizeVector inputShapes; + InferenceEngine::Precision inputPrecision; + ngraph::AxisSet axes; + bool acrossChanels, normalizeVariance; + double eps; + std::tie(inputShapes, inputPrecision, axes, acrossChanels, normalizeVariance, eps, targetDevice) = this->GetParam(); + auto inType = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inputPrecision); + auto param = ngraph::builder::makeParams(inType, {inputShapes}); + auto paramOuts = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(param)); + auto mvn = std::dynamic_pointer_cast(ngraph::builder::makeMVN(paramOuts[0], acrossChanels, normalizeVariance, eps)); + if (!axes.empty()) { + mvn = std::dynamic_pointer_cast(ngraph::builder::makeMVN(paramOuts[0], axes, normalizeVariance, eps)); + } + ngraph::ResultVector results{std::make_shared(mvn)}; + function = std::make_shared(results, param, "MVN1"); +} + std::string Mvn6LayerTest::getTestCaseName(const testing::TestParamInfo& obj) { InferenceEngine::SizeVector inputShapes; diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py index d383d0f95c278d..60d91f93b49a47 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py @@ -57,6 +57,7 @@ 'LSTMSequence-5', 'LogSoftmax-5', 'Loop-5', + 'MVN-1', 'MVN-6', 'Maximum-1', 'MaxPool-1', diff --git a/inference-engine/tests/ngraph_helpers/ngraph_functions/include/ngraph_functions/builders.hpp b/inference-engine/tests/ngraph_helpers/ngraph_functions/include/ngraph_functions/builders.hpp index d1e94b78f1eb06..55a8f48297823d 100644 --- a/inference-engine/tests/ngraph_helpers/ngraph_functions/include/ngraph_functions/builders.hpp +++ b/inference-engine/tests/ngraph_helpers/ngraph_functions/include/ngraph_functions/builders.hpp @@ -291,6 +291,11 @@ std::shared_ptr makeMVN(const ngraph::Output &in, bool normalizeVariance, double eps); +std::shared_ptr makeMVN(const ngraph::Output &in, + const ngraph::AxisSet &axes, + bool normalizeVariance, + double eps); + std::shared_ptr makeMVN6(const Output& in, const Output& axesNode, bool normalizeVariance, diff --git a/inference-engine/tests/ngraph_helpers/ngraph_functions/src/mvn.cpp b/inference-engine/tests/ngraph_helpers/ngraph_functions/src/mvn.cpp index ab65a06c179c34..f4f73e93852a24 100644 --- a/inference-engine/tests/ngraph_helpers/ngraph_functions/src/mvn.cpp +++ b/inference-engine/tests/ngraph_helpers/ngraph_functions/src/mvn.cpp @@ -24,6 +24,15 @@ std::shared_ptr makeMVN(const ngraph::Output &in, return mvnNode; } +std::shared_ptr makeMVN(const ngraph::Output &in, + const ngraph::AxisSet &axes, + bool normalizeVariance, + double eps) { + auto mvnNode = std::make_shared(in, axes, normalizeVariance, eps); + + return mvnNode; +} + std::shared_ptr makeMVN6(const Output& in, const Output& axesNode, bool normalizeVariance, diff --git a/ngraph/core/include/ngraph/op/mvn.hpp b/ngraph/core/include/ngraph/op/mvn.hpp index cc3ab0bb9d7024..49f9c3a71d82af 100644 --- a/ngraph/core/include/ngraph/op/mvn.hpp +++ b/ngraph/core/include/ngraph/op/mvn.hpp @@ -69,7 +69,7 @@ namespace ngraph void set_reduction_axes(AxisSet axes) { m_reduction_axes = axes; } private: - double m_eps = 1e-9; + double m_eps; bool m_across_channels; bool m_normalize_variance; AxisSet m_reduction_axes; @@ -128,9 +128,9 @@ namespace ngraph MVNEpsMode get_eps_mode() const { return m_eps_mode; } private: - bool m_normalize_variance = true; - float m_eps = (float)1e-6; - MVNEpsMode m_eps_mode = MVNEpsMode::INSIDE_SQRT; + bool m_normalize_variance; + float m_eps; + MVNEpsMode m_eps_mode; }; } // namespace v6 } // namespace op diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index 24d70dece93564..5cc1197307bd5a 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -451,7 +451,6 @@ set(MULTI_TEST_SRC backend/multiple_backends.in.cpp backend/multiple_result.in.cpp backend/multiply.in.cpp - backend/mvn.in.cpp backend/negative.in.cpp backend/node_name.in.cpp backend/normalize_l2.in.cpp diff --git a/ngraph/test/backend/mvn.in.cpp b/ngraph/test/backend/mvn.in.cpp deleted file mode 100644 index 2a0dd89b218897..00000000000000 --- a/ngraph/test/backend/mvn.in.cpp +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "util/engine/test_engines.hpp" -#include "util/test_case.hpp" -#include "util/test_control.hpp" - -NGRAPH_SUPPRESS_DEPRECATED_START - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; -using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); - -NGRAPH_TEST(${BACKEND_NAME}, evaluate_mvn_6_no_variance) -{ - auto data = make_shared(element::f32, PartialShape{1, 3, 3, 3}); - auto axes = make_shared(element::i64, Shape{2}, vector{2, 3}); - - auto mvn = - make_shared(data, axes, false, 1e-9, ngraph::op::MVNEpsMode::OUTSIDE_SQRT); - auto fun = make_shared(OutputVector{mvn}, ParameterVector{data}); - auto test_case = test::TestCase(fun); - - // clang-format off - test_case.add_input({1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9}); - - test_case.add_expected_output({-4, -3, -2, -1, 0, 1, 2, 3, 4, - -4, -3, -2, -1, 0, 1, 2, 3, 4, - -4, -3, -2, -1, 0, 1, 2, 3, 4}); - // clang-format on - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, evaluate_mvn_6) -{ - auto data = make_shared(element::f32, PartialShape{1, 3, 3, 3}); - auto axes = make_shared(element::i64, Shape{2}, vector{2, 3}); - - auto mvn = - make_shared(data, axes, true, 1e-9, ngraph::op::MVNEpsMode::OUTSIDE_SQRT); - auto fun = make_shared(OutputVector{mvn}, ParameterVector{data}); - auto test_case = test::TestCase(fun); - - // clang-format off - test_case.add_input({1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9}); - - test_case.add_expected_output({-1.5491934, -1.161895, -0.7745967, - -0.38729835, 0., 0.38729835, - 0.7745967, 1.161895, 1.5491934, - -1.5491934, -1.161895, -0.7745967, - -0.38729835, 0., 0.38729835, - 0.7745967, 1.161895, 1.5491934, - -1.5491934, -1.161895, -0.7745967, - -0.38729835, 0., 0.38729835, - 0.7745967, 1.161895, 1.5491934}); - // clang-format on - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, evaluate_mvn_6_inside_sqrt) -{ - auto data = make_shared(element::f32, PartialShape{1, 3, 3, 3}); - auto axes = make_shared(element::i64, Shape{2}, vector{2, 3}); - - auto mvn = - make_shared(data, axes, true, 1e-9, ngraph::op::MVNEpsMode::INSIDE_SQRT); - auto fun = make_shared(OutputVector{mvn}, ParameterVector{data}); - auto test_case = test::TestCase(fun); - - // clang-format off - test_case.add_input({1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9}); - - test_case.add_expected_output({-1.5491934, -1.161895, -0.7745967, - -0.38729835, 0., 0.38729835, - 0.7745967, 1.161895, 1.5491934, - -1.5491934, -1.161895, -0.7745967, - -0.38729835, 0., 0.38729835, - 0.7745967, 1.161895, 1.5491934, - -1.5491934, -1.161895, -0.7745967, - -0.38729835, 0., 0.38729835, - 0.7745967, 1.161895, 1.5491934}); - // clang-format on - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, evaluate_mvn_6_across_chanells) -{ - auto data = make_shared(element::f32, PartialShape{1, 3, 3, 3}); - auto axes = make_shared(element::i64, Shape{3}, vector{1, 2, 3}); - - auto mvn = - make_shared(data, axes, true, 1e-9, ngraph::op::MVNEpsMode::OUTSIDE_SQRT); - auto fun = make_shared(OutputVector{mvn}, ParameterVector{data}); - auto test_case = test::TestCase(fun); - - // clang-format off - test_case.add_input( - {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9}); - - test_case.add_expected_output({-1.5491934, -1.161895, -0.7745967, - -0.38729835, 0., 0.38729835, - 0.7745967, 1.161895, 1.5491934, - -1.5491934, -1.161895, -0.7745967, - -0.38729835, 0., 0.38729835, - 0.7745967, 1.161895, 1.5491934, - -1.5491934, -1.161895, -0.7745967, - -0.38729835, 0., 0.38729835, - 0.7745967, 1.161895, 1.5491934}); - // clang-format on - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, evaluate_mvn_6_across_batch) -{ - auto data = make_shared(element::f32, PartialShape{2, 3, 2, 2}); - auto axes = make_shared(element::i64, Shape{3}, vector{0, 2, 3}); - - auto mvn = - make_shared(data, axes, true, 1e-9, ngraph::op::MVNEpsMode::OUTSIDE_SQRT); - auto fun = make_shared(OutputVector{mvn}, ParameterVector{data}); - auto test_case = test::TestCase(fun); - - // clang-format off - test_case.add_input( - {1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8}); - - test_case.add_expected_output( - {-1.5275252, -1.0910894, -0.65465367, -0.21821788, 0.21821788, 0.65465367, - 1.0910894, 1.5275252, -1.5275252, -1.0910894, -0.65465367, -0.21821788, - 0.21821788, 0.65465367, 1.0910894, 1.5275252, -1.5275252, -1.0910894, - -0.65465367, -0.21821788, 0.21821788, 0.65465367, 1.0910894, 1.5275252}); - // clang-format on - test_case.run(); -} diff --git a/ngraph/test/visitors/op/mvn.cpp b/ngraph/test/visitors/op/mvn.cpp index 0f2bf38ecdce62..7773cca5abab15 100644 --- a/ngraph/test/visitors/op/mvn.cpp +++ b/ngraph/test/visitors/op/mvn.cpp @@ -10,6 +10,7 @@ #include "ngraph/opsets/opset3.hpp" #include "ngraph/opsets/opset4.hpp" #include "ngraph/opsets/opset5.hpp" +#include "ngraph/opsets/opset6.hpp" #include "util/visitor.hpp" @@ -18,7 +19,7 @@ using namespace ngraph; using ngraph::test::NodeBuilder; using ngraph::test::ValueMap; -TEST(attributes, mvn_op) +TEST(attributes, mvn_v1_op) { NodeBuilder::get_ops().register_factory(); const auto data = make_shared(element::i32, Shape{2, 3, 4, 5}); @@ -29,9 +30,33 @@ TEST(attributes, mvn_op) op->set_reduction_axes(axes); NodeBuilder builder(op); const auto g_op = as_type_ptr(builder.create()); + const auto expected_attr_count = 4; + EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); EXPECT_EQ(g_op->get_reduction_axes(), op->get_reduction_axes()); EXPECT_EQ(g_op->get_across_channels(), op->get_across_channels()); EXPECT_EQ(g_op->get_normalize_variance(), op->get_normalize_variance()); EXPECT_EQ(g_op->get_eps(), op->get_eps()); } + +TEST(attributes, mvn_v6_op) +{ + NodeBuilder::get_ops().register_factory(); + const auto data = make_shared(element::i32, Shape{2, 3, 4, 5}); + auto axes = ngraph::opset6::Constant::create(ngraph::element::i64, ngraph::Shape{ 2 }, { 2, 3 }); + + const auto op = make_shared(data, + axes, + false, + 0.1, + op::MVNEpsMode::INSIDE_SQRT); + + NodeBuilder builder(op); + const auto g_op = as_type_ptr(builder.create()); + const auto expected_attr_count = 3; + + EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); + EXPECT_EQ(g_op->get_eps_mode(), op->get_eps_mode()); + EXPECT_EQ(g_op->get_normalize_variance(), op->get_normalize_variance()); + EXPECT_EQ(g_op->get_eps(), op->get_eps()); +}