[IE TESTS] Add Interpolate single layer test (#1456)

This commit is contained in:
Irina Efode 2020-07-27 11:45:19 +03:00 committed by GitHub
parent 3bbdda6b48
commit 0560b61cbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 348 additions and 8 deletions

View File

@ -0,0 +1,88 @@
// Copyright (C) 2019 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <vector>
#include "single_layer_tests/interpolate.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
namespace {
const std::vector<InferenceEngine::Precision> prc = {
InferenceEngine::Precision::FP16,
InferenceEngine::Precision::FP32,
};
const std::vector<std::vector<size_t>> inShapes = {
{1, 4, 30, 30},
};
const std::vector<std::vector<size_t>> targetShapes = {
{40, 40},
};
const std::vector<std::set<size_t>> axes = {
{2, 3},
};
const std::vector<ngraph::op::v3::Interpolate::InterpolateMode> 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<ngraph::op::v3::Interpolate::CoordinateTransformMode> 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<ngraph::op::v3::Interpolate::NearestMode> 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<std::vector<size_t>> pads = {
{1, 1},
{0, 0},
};
const std::vector<bool> antialias = {
// Not enabled in Inference Engine
// true,
false,
};
const std::vector<double> 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

View File

@ -53,5 +53,7 @@ std::vector<std::string> disabledTestPatterns() {
R"(.*ActivationParamLayerTest.*)", R"(.*ActivationParamLayerTest.*)",
// TODO: Issue: 32959 // TODO: Issue: 32959
R"(.*ActivationLayerTest.*Mish.*)", R"(.*ActivationLayerTest.*Mish.*)",
// TODO: Issue: 30999 (Implement Interpolate reference in NGraph)
R"(.*InterpolateLayerTest.*)"
}; };
} }

View File

@ -0,0 +1,47 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <tuple>
#include <vector>
#include <string>
#include <memory>
#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<size_t>, // Axes
ngraph::op::v3::Interpolate::InterpolateMode, // InterpolateMode
ngraph::op::v3::Interpolate::CoordinateTransformMode, // CoordinateTransformMode
ngraph::op::v3::Interpolate::NearestMode, // NearestMode
bool, // AntiAlias
std::vector<size_t>, // PadBegin
std::vector<size_t>, // 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<InterpolateLayerTestParams>,
public LayerTestsUtils::LayerTestsCommon {
public:
static std::string getTestCaseName(testing::TestParamInfo<InterpolateLayerTestParams> obj);
protected:
void SetUp() override;
};
} // namespace LayerTestsDefinitions

View File

@ -0,0 +1,87 @@
// Copyright (C) 2019 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <tuple>
#include <vector>
#include <string>
#include <memory>
#include <functional_test_utils/skip_tests_config.hpp>
#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<InterpolateLayerTestParams> obj) {
InterpolateSpecificParams interpolateParams;
InferenceEngine::Precision netPrecision;
InferenceEngine::SizeVector inputShapes, targetShapes;
std::string targetDevice;
std::tie(interpolateParams, netPrecision, inputShapes, targetShapes, targetDevice) = obj.param;
std::set<size_t> axes;
std::vector<size_t> 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<size_t> inputShape, targetShape;
auto netPrecision = InferenceEngine::Precision::UNSPECIFIED;
std::tie(interpolateParams, netPrecision, inputShape, targetShape, targetDevice) = this->GetParam();
std::set<size_t> axes;
std::vector<size_t> 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<ngraph::opset3::Constant>(constant);
ngraph::op::v3::Interpolate::InterpolateAttrs interpolateAttributes{
axes, mode, padBegin, padEnd, coordinateTransformMode, nearestMode, antialias, cubeCoef};
auto interpolate = std::make_shared<ngraph::op::v3::Interpolate>(params[0], secondaryInput, interpolateAttributes);
const ngraph::ResultVector results{std::make_shared<ngraph::opset3::Result>(interpolate)};
function = std::make_shared<ngraph::Function>(results, params, "interpolate");
}
TEST_P(InterpolateLayerTest, CompareWithRefs) {
Run();
}
} // namespace LayerTestsDefinitions

View File

@ -8,6 +8,7 @@
#include <sstream> #include <sstream>
#include <iterator> #include <iterator>
#include <vector> #include <vector>
#include <set>
#include <cpp/ie_cnn_network.h> #include <cpp/ie_cnn_network.h>
#include <details/ie_cnn_network_iterator.hpp> #include <details/ie_cnn_network_iterator.hpp>
@ -34,6 +35,18 @@ inline std::string vec2str(const std::vector<std::vector<vecElementType>> &vec)
return result.str(); return result.str();
} }
template<typename vecElementType>
inline std::string set2str(const std::set<vecElementType> &set) {
if (!set.empty()) {
std::ostringstream result;
result << "(";
std::copy(set.begin(), std::prev(set.end()), std::ostream_iterator<vecElementType>(result, "."));
result << *set.rbegin() << ")";
return result.str();
}
return std::string("()");
}
inline InferenceEngine::CNNLayerPtr getLayerByName(const InferenceEngine::ICNNNetwork * icnnnetwork, inline InferenceEngine::CNNLayerPtr getLayerByName(const InferenceEngine::ICNNNetwork * icnnnetwork,
const std::string & layerName) { const std::string & layerName) {
IE_SUPPRESS_DEPRECATED_START IE_SUPPRESS_DEPRECATED_START

View File

@ -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::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 helpers
} // namespace ngraph } // namespace ngraph

View File

@ -607,5 +607,74 @@ std::ostream& operator<<(std::ostream & os, ngraph::helpers::LogicalTypes type)
return os; 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 helpers
} // namespace ngraph } // namespace ngraph

View File

@ -125,6 +125,14 @@ namespace ngraph
// specifies type of interpolation // specifies type of interpolation
// one of `nearest`, `linear`, `linear_onnx`, `cubic`, `area`. Required. // one of `nearest`, `linear`, `linear_onnx`, `cubic`, `area`. Required.
InterpolateMode mode; 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<size_t> 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<size_t> pads_end;
// specifies how to transform the coordinate in the resized tensor to the // specifies how to transform the coordinate in the resized tensor to the
// coordinate in the original tensor. one of `half_pixel`, `pytorch_half_pixel`, // coordinate in the original tensor. one of `half_pixel`, `pytorch_half_pixel`,
// `asymmetric`, `tf_half_pixel_for_nn`, `align_corners` // `asymmetric`, `tf_half_pixel_for_nn`, `align_corners`
@ -136,18 +144,38 @@ namespace ngraph
NearestMode nearest_mode = NearestMode::round_prefer_floor; NearestMode nearest_mode = NearestMode::round_prefer_floor;
// a flag that specifies whether to perform anti-aliasing. default is `false` // a flag that specifies whether to perform anti-aliasing. default is `false`
bool antialias = 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<size_t> 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<size_t> pads_end;
// specifies the parameter *a* for cubic interpolation (see, e.g. // specifies the parameter *a* for cubic interpolation (see, e.g.
// [article](https://ieeexplore.ieee.org/document/1163711/)). *cube_coeff* is // [article](https://ieeexplore.ieee.org/document/1163711/)). *cube_coeff* is
// used only when `mode == cubic` // used only when `mode == cubic`
double cube_coeff = -0.75; 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<size_t> pads_begin,
std::vector<size_t> 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}; static constexpr NodeTypeInfo type_info{"Interpolate", 3};