From 0560b61cbde37ee6a001dc19cbed6c1b7184b786 Mon Sep 17 00:00:00 2001 From: Irina Efode Date: Mon, 27 Jul 2020 11:45:19 +0300 Subject: [PATCH] [IE TESTS] Add Interpolate single layer test (#1456) --- .../single_layer_tests/interpolate.cpp | 88 ++++++++++++++++++++++ .../shared_tests_instances/skip_tests_config.cpp | 2 + .../include/single_layer_tests/interpolate.hpp | 47 ++++++++++++ .../shared/src/single_layer_tests/interpolate.cpp | 87 +++++++++++++++++++++ .../common_test_utils/common_utils.hpp | 13 ++++ .../ngraph_functions/utils/ngraph_helpers.hpp | 6 ++ .../ngraph_functions/src/utils/ngraph_helpers.cpp | 69 +++++++++++++++++ ngraph/src/ngraph/op/interpolate.hpp | 44 +++++++++-- 8 files changed, 348 insertions(+), 8 deletions(-) create mode 100644 inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/interpolate.cpp create mode 100644 inference-engine/tests/functional/plugin/shared/include/single_layer_tests/interpolate.hpp create mode 100644 inference-engine/tests/functional/plugin/shared/src/single_layer_tests/interpolate.cpp diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/interpolate.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/interpolate.cpp new file mode 100644 index 0000000..a6c391a --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/interpolate.cpp @@ -0,0 +1,88 @@ +// Copyright (C) 2019 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "single_layer_tests/interpolate.hpp" +#include "common_test_utils/test_constants.hpp" + +using namespace LayerTestsDefinitions; + +namespace { + +const std::vector prc = { + InferenceEngine::Precision::FP16, + InferenceEngine::Precision::FP32, +}; + +const std::vector> inShapes = { + {1, 4, 30, 30}, +}; + +const std::vector> targetShapes = { + {40, 40}, +}; + +const std::vector> axes = { + {2, 3}, +}; + +const std::vector modes = { + ngraph::op::v3::Interpolate::InterpolateMode::nearest, + ngraph::op::v3::Interpolate::InterpolateMode::linear, + ngraph::op::v3::Interpolate::InterpolateMode::linear_onnx, + ngraph::op::v3::Interpolate::InterpolateMode::cubic, + ngraph::op::v3::Interpolate::InterpolateMode::area, +}; + +const std::vector coordinateTransformModes = { + ngraph::op::v3::Interpolate::CoordinateTransformMode::tf_half_pixel_for_nn, + ngraph::op::v3::Interpolate::CoordinateTransformMode::pytorch_half_pixel, + ngraph::op::v3::Interpolate::CoordinateTransformMode::half_pixel, + ngraph::op::v3::Interpolate::CoordinateTransformMode::asymmetric, + ngraph::op::v3::Interpolate::CoordinateTransformMode::align_corners, +}; + +const std::vector nearestModes = { + ngraph::op::v3::Interpolate::NearestMode::simple, + ngraph::op::v3::Interpolate::NearestMode::round_prefer_floor, + ngraph::op::v3::Interpolate::NearestMode::floor, + ngraph::op::v3::Interpolate::NearestMode::ceil, + ngraph::op::v3::Interpolate::NearestMode::round_prefer_ceil, +}; + +const std::vector> pads = { + {1, 1}, + {0, 0}, +}; + +const std::vector antialias = { +// Not enabled in Inference Engine +// true, + false, +}; + +const std::vector cubeCoefs = { + 0.75f, +}; + +const auto interpolateCases = ::testing::Combine( + ::testing::ValuesIn(axes), + ::testing::ValuesIn(modes), + ::testing::ValuesIn(coordinateTransformModes), + ::testing::ValuesIn(nearestModes), + ::testing::ValuesIn(antialias), + ::testing::ValuesIn(pads), + ::testing::ValuesIn(pads), + ::testing::ValuesIn(cubeCoefs)); + +INSTANTIATE_TEST_CASE_P(Interpolate_Basic, InterpolateLayerTest, ::testing::Combine( + interpolateCases, + ::testing::ValuesIn(prc), + ::testing::ValuesIn(inShapes), + ::testing::ValuesIn(targetShapes), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + InterpolateLayerTest::getTestCaseName); + +} // namespace \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp index d470888..b59596c 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp @@ -53,5 +53,7 @@ std::vector disabledTestPatterns() { R"(.*ActivationParamLayerTest.*)", // TODO: Issue: 32959 R"(.*ActivationLayerTest.*Mish.*)", + // TODO: Issue: 30999 (Implement Interpolate reference in NGraph) + R"(.*InterpolateLayerTest.*)" }; } \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/interpolate.hpp b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/interpolate.hpp new file mode 100644 index 0000000..b6b7ad8 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/interpolate.hpp @@ -0,0 +1,47 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include + +#include "functional_test_utils/layer_test_utils.hpp" + +#include "ngraph_functions/builders.hpp" +#include "ngraph_functions/utils/ngraph_helpers.hpp" + +namespace LayerTestsDefinitions { + +typedef std::tuple< + std::set, // Axes + ngraph::op::v3::Interpolate::InterpolateMode, // InterpolateMode + ngraph::op::v3::Interpolate::CoordinateTransformMode, // CoordinateTransformMode + ngraph::op::v3::Interpolate::NearestMode, // NearestMode + bool, // AntiAlias + std::vector, // PadBegin + std::vector, // PadEnd + double // Cube coef +> InterpolateSpecificParams; + +typedef std::tuple< + InterpolateSpecificParams, + InferenceEngine::Precision, // Net precision + InferenceEngine::SizeVector, // Input shapes + InferenceEngine::SizeVector, // Target shapes + LayerTestsUtils::TargetDevice // Device name +> InterpolateLayerTestParams; + +class InterpolateLayerTest : public testing::WithParamInterface, + public LayerTestsUtils::LayerTestsCommon { +public: + static std::string getTestCaseName(testing::TestParamInfo obj); + +protected: + void SetUp() override; +}; + +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/interpolate.cpp b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/interpolate.cpp new file mode 100644 index 0000000..c2990a5 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/interpolate.cpp @@ -0,0 +1,87 @@ +// Copyright (C) 2019 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include +#include +#include +#include + +#include "common_test_utils/common_utils.hpp" +#include "functional_test_utils/layer_test_utils.hpp" + +#include "single_layer_tests/interpolate.hpp" +#include "ngraph_functions/builders.hpp" +#include "ngraph_functions/utils/ngraph_helpers.hpp" + +using ngraph::helpers::operator<<; + +namespace LayerTestsDefinitions { + +std::string InterpolateLayerTest::getTestCaseName(testing::TestParamInfo obj) { + InterpolateSpecificParams interpolateParams; + InferenceEngine::Precision netPrecision; + InferenceEngine::SizeVector inputShapes, targetShapes; + std::string targetDevice; + std::tie(interpolateParams, netPrecision, inputShapes, targetShapes, targetDevice) = obj.param; + std::set axes; + std::vector padBegin, padEnd; + bool antialias; + ngraph::op::v3::Interpolate::InterpolateMode mode; + ngraph::op::v3::Interpolate::CoordinateTransformMode coordinateTransformMode; + ngraph::op::v3::Interpolate::NearestMode nearestMode; + double cubeCoef; + std:tie(axes, mode, coordinateTransformMode, nearestMode, antialias, padBegin, padEnd, cubeCoef) = interpolateParams; + std::ostringstream result; + result << "IS=" << CommonTestUtils::vec2str(inputShapes) << "_"; + result << "TS=" << CommonTestUtils::vec2str(targetShapes) << "_"; + result << "Axe=" << CommonTestUtils::set2str(axes)<< "_"; + result << "InterpolateMode=" << mode << "_"; + result << "CoordinateTransformMode=" << coordinateTransformMode << "_"; + result << "NearestMode=" << nearestMode << "_"; + result << "CubeCoef=" << cubeCoef << "_"; + result << "Antialias=" << antialias << "_"; + result << "PB=" << CommonTestUtils::vec2str(padBegin) << "_"; + result << "PE=" << CommonTestUtils::vec2str(padEnd) << "_"; + result << "netPRC=" << netPrecision.name() << "_"; + result << "targetDevice=" << targetDevice; + return result.str(); +} + +void InterpolateLayerTest::SetUp() { + InterpolateSpecificParams interpolateParams; + std::vector inputShape, targetShape; + auto netPrecision = InferenceEngine::Precision::UNSPECIFIED; + + std::tie(interpolateParams, netPrecision, inputShape, targetShape, targetDevice) = this->GetParam(); + std::set axes; + std::vector padBegin, padEnd; + bool antialias; + ngraph::op::v3::Interpolate::InterpolateMode mode; + ngraph::op::v3::Interpolate::CoordinateTransformMode coordinateTransformMode; + ngraph::op::v3::Interpolate::NearestMode nearestMode; + double cubeCoef; + std:tie(axes, mode, coordinateTransformMode, nearestMode, antialias, padBegin, padEnd, cubeCoef) = interpolateParams; + + if (targetShape.size() != axes.size()) { + THROW_IE_EXCEPTION << "Target shape size: " << targetShape.size() << " is not equal Axes shapes: " << axes.size(); + } + + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto params = ngraph::builder::makeParams(ngPrc, {inputShape}); + + auto constant = ngraph::opset3::Constant(ngraph::element::Type_t::i64, {axes.size()}, targetShape); + auto secondaryInput = std::make_shared(constant); + + ngraph::op::v3::Interpolate::InterpolateAttrs interpolateAttributes{ + axes, mode, padBegin, padEnd, coordinateTransformMode, nearestMode, antialias, cubeCoef}; + auto interpolate = std::make_shared(params[0], secondaryInput, interpolateAttributes); + const ngraph::ResultVector results{std::make_shared(interpolate)}; + function = std::make_shared(results, params, "interpolate"); +} + +TEST_P(InterpolateLayerTest, CompareWithRefs) { + Run(); +} +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/ie_test_utils/common_test_utils/common_utils.hpp b/inference-engine/tests/ie_test_utils/common_test_utils/common_utils.hpp index dcdc0f5..38b6218 100644 --- a/inference-engine/tests/ie_test_utils/common_test_utils/common_utils.hpp +++ b/inference-engine/tests/ie_test_utils/common_test_utils/common_utils.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include
@@ -34,6 +35,18 @@ inline std::string vec2str(const std::vector> &vec) return result.str(); } +template +inline std::string set2str(const std::set &set) { + if (!set.empty()) { + std::ostringstream result; + result << "("; + std::copy(set.begin(), std::prev(set.end()), std::ostream_iterator(result, ".")); + result << *set.rbegin() << ")"; + return result.str(); + } + return std::string("()"); +} + inline InferenceEngine::CNNLayerPtr getLayerByName(const InferenceEngine::ICNNNetwork * icnnnetwork, const std::string & layerName) { IE_SUPPRESS_DEPRECATED_START diff --git a/inference-engine/tests/ngraph_functions/include/ngraph_functions/utils/ngraph_helpers.hpp b/inference-engine/tests/ngraph_functions/include/ngraph_functions/utils/ngraph_helpers.hpp index 5f37988..f63aefe 100644 --- a/inference-engine/tests/ngraph_functions/include/ngraph_functions/utils/ngraph_helpers.hpp +++ b/inference-engine/tests/ngraph_functions/include/ngraph_functions/utils/ngraph_helpers.hpp @@ -231,5 +231,11 @@ std::ostream& operator<<(std::ostream & os, ngraph::helpers::ComparisonTypes typ std::ostream& operator<<(std::ostream & os, ngraph::helpers::LogicalTypes type); +std::ostream& operator<<(std::ostream & os, ngraph::op::v3::Interpolate::InterpolateMode type); + +std::ostream& operator<<(std::ostream & os, ngraph::op::v3::Interpolate::CoordinateTransformMode type); + +std::ostream& operator<<(std::ostream & os, ngraph::op::v3::Interpolate::NearestMode type); + } // namespace helpers } // namespace ngraph diff --git a/inference-engine/tests/ngraph_functions/src/utils/ngraph_helpers.cpp b/inference-engine/tests/ngraph_functions/src/utils/ngraph_helpers.cpp index be0f237..1ecb011 100644 --- a/inference-engine/tests/ngraph_functions/src/utils/ngraph_helpers.cpp +++ b/inference-engine/tests/ngraph_functions/src/utils/ngraph_helpers.cpp @@ -607,5 +607,74 @@ std::ostream& operator<<(std::ostream & os, ngraph::helpers::LogicalTypes type) return os; } +std::ostream& operator<<(std::ostream & os, ngraph::op::v3::Interpolate::InterpolateMode type) { + switch (type) { + case ngraph::op::v3::Interpolate::InterpolateMode::area: + os << "area"; + break; + case ngraph::op::v3::Interpolate::InterpolateMode::cubic: + os << "cubic"; + break; + case ngraph::op::v3::Interpolate::InterpolateMode::linear: + os << "linear"; + break; + case ngraph::op::v3::Interpolate::InterpolateMode::linear_onnx: + os << "linear_onnx"; + break; + case ngraph::op::v3::Interpolate::InterpolateMode::nearest: + os << "nearest"; + break; + default: + throw std::runtime_error("NOT_SUPPORTED_OP_TYPE"); + } + return os; +} + +std::ostream& operator<<(std::ostream & os, ngraph::op::v3::Interpolate::CoordinateTransformMode type) { + switch (type) { + case ngraph::op::v3::Interpolate::CoordinateTransformMode::align_corners: + os << "align_corners"; + break; + case ngraph::op::v3::Interpolate::CoordinateTransformMode::asymmetric: + os << "asymmetric"; + break; + case ngraph::op::v3::Interpolate::CoordinateTransformMode::half_pixel: + os << "half_pixel"; + break; + case ngraph::op::v3::Interpolate::CoordinateTransformMode::pytorch_half_pixel: + os << "pytorch_half_pixel"; + break; + case ngraph::op::v3::Interpolate::CoordinateTransformMode::tf_half_pixel_for_nn: + os << "tf_half_pixel_for_nn"; + break; + default: + throw std::runtime_error("NOT_SUPPORTED_OP_TYPE"); + } + return os; +} + +std::ostream& operator<<(std::ostream & os, ngraph::op::v3::Interpolate::NearestMode type) { + switch (type) { + case ngraph::op::v3::Interpolate::NearestMode::ceil: + os << "ceil"; + break; + case ngraph::op::v3::Interpolate::NearestMode::round_prefer_ceil: + os << "round_prefer_ceil"; + break; + case ngraph::op::v3::Interpolate::NearestMode::floor: + os << "floor"; + break; + case ngraph::op::v3::Interpolate::NearestMode::round_prefer_floor: + os << "round_prefer_floor"; + break; + case ngraph::op::v3::Interpolate::NearestMode::simple: + os << "simple"; + break; + default: + throw std::runtime_error("NOT_SUPPORTED_OP_TYPE"); + } + return os; +} + } // namespace helpers } // namespace ngraph diff --git a/ngraph/src/ngraph/op/interpolate.hpp b/ngraph/src/ngraph/op/interpolate.hpp index f83740f..1aed61b 100644 --- a/ngraph/src/ngraph/op/interpolate.hpp +++ b/ngraph/src/ngraph/op/interpolate.hpp @@ -125,6 +125,14 @@ namespace ngraph // specifies type of interpolation // one of `nearest`, `linear`, `linear_onnx`, `cubic`, `area`. Required. InterpolateMode mode; + // specify the number of pixels to add to the beginning of the image being + // interpolated. This addition of pixels is done before interpolation + // calculation. + std::vector pads_begin; + // specify the number of pixels to add to the end of the image being + // interpolated. This addition of pixels is done before interpolation + // calculation. + std::vector pads_end; // specifies how to transform the coordinate in the resized tensor to the // coordinate in the original tensor. one of `half_pixel`, `pytorch_half_pixel`, // `asymmetric`, `tf_half_pixel_for_nn`, `align_corners` @@ -136,18 +144,38 @@ namespace ngraph NearestMode nearest_mode = NearestMode::round_prefer_floor; // a flag that specifies whether to perform anti-aliasing. default is `false` bool antialias = false; - // specify the number of pixels to add to the beginning of the image being - // interpolated. This addition of pixels is done before interpolation - // calculation. - std::vector pads_begin; - // specify the number of pixels to add to the end of the image being - // interpolated. This addition of pixels is done before interpolation - // calculation. - std::vector pads_end; // specifies the parameter *a* for cubic interpolation (see, e.g. // [article](https://ieeexplore.ieee.org/document/1163711/)). *cube_coeff* is // used only when `mode == cubic` double cube_coeff = -0.75; + + InterpolateAttrs() + : coordinate_transformation_mode(CoordinateTransformMode::half_pixel) + , nearest_mode(NearestMode::round_prefer_floor) + , antialias(false) + , cube_coeff(-0.75f) + { + } + + InterpolateAttrs(AxisSet axes, + InterpolateMode mode, + std::vector pads_begin, + std::vector pads_end, + CoordinateTransformMode coordinate_transformation_mode = + CoordinateTransformMode::half_pixel, + NearestMode nearest_mode = NearestMode::round_prefer_floor, + bool antialias = false, + double cube_coeff = -0.75) + : axes(axes) + , mode(mode) + , pads_begin(pads_begin) + , pads_end(pads_end) + , coordinate_transformation_mode(coordinate_transformation_mode) + , nearest_mode(nearest_mode) + , antialias(antialias) + , cube_coeff(cube_coeff) + { + } }; static constexpr NodeTypeInfo type_info{"Interpolate", 3}; -- 2.7.4