[IE][VPU][TESTS]: support different modes for Interpolate (#2963)

This commit is contained in:
Daria Mityagina 2020-11-12 13:51:48 +03:00 committed by GitHub
parent f1c8ecb40b
commit 121f75f49d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 96 additions and 3 deletions

View File

@ -19,7 +19,7 @@ set(VPU_SUPPORTED_FIRMWARES usb-ma2x8x pcie-ma248x)
# Default packages
#
set(FIRMWARE_PACKAGE_VERSION 1468)
set(FIRMWARE_PACKAGE_VERSION 1474)
set(VPU_CLC_MA2X8X_VERSION "movi-cltools-20.09.2")
#

View File

@ -271,6 +271,21 @@ VPU_DECLARE_ENUM(BroadcastMode,
// StageDataInfo
//
VPU_DECLARE_ENUM(InterpolateCoordTransMode,
HalfPixel = 0,
PytorchHalfPixel = 1,
Asymmetric = 2,
TfHalfPixelForNn = 3,
AlignCorners = 4
)
VPU_DECLARE_ENUM(InterpolateNearestMode,
RoundPreferFloor = 0,
RoundPreferCeil = 1,
Floor = 2,
Ceil = 3,
Simple = 4
)
template <typename Val>
class StageDataInfo final {
public:

View File

@ -335,6 +335,8 @@ public:
const std::string& name,
const ie::CNNLayerPtr& layer,
bool antialias,
InterpolateCoordTransMode coordinateTransformationMode,
InterpolateNearestMode nearestMode,
float factor,
const Data& input,
const Data& output);

View File

@ -51,24 +51,43 @@ void FrontEnd::parseInterpolate(const Model& model, const ie::CNNLayerPtr& _laye
if (cmp(interpolateMode, "nearest")) {
// current "Resample" supports the following "Interpolate" modes only:
// coordinate_transformation_mode = half_pixel; nearest_mode = round_prefer_ceil;
// coordinate_transformation_mode = asymmetric; nearest_mode = floor;
// other "Interpolate" modes are translated to the default ones
const auto antialias = _layer->GetParamAsBool("antialias", false);
const auto coordinateTransformation = _layer->GetParamAsString("coordinate_transformation_mode", "half_pixel");
const auto nearest = _layer->GetParamAsString("nearest_mode", "round_prefer_floor");
InterpolateCoordTransMode coordinateTransformationMode = InterpolateCoordTransMode::HalfPixel;
InterpolateNearestMode nearestMode = InterpolateNearestMode::RoundPreferCeil;
if (cmp(coordinateTransformation, "asymmetric")) {
coordinateTransformationMode = InterpolateCoordTransMode::Asymmetric;
}
if (cmp(nearest, "round_prefer_floor")) {
nearestMode = InterpolateNearestMode::RoundPreferFloor;
} else if (cmp(nearest, "round_prefer_ceil")) {
nearestMode = InterpolateNearestMode::RoundPreferCeil;
} else if (cmp(nearest, "floor")) {
nearestMode = InterpolateNearestMode::Floor;
}
_stageBuilder->addResampleNearestStage(model,
_layer->name,
_layer,
antialias,
coordinateTransformationMode,
nearestMode,
-1.0f,
input,
output);
} else if (cmp(interpolateMode, "linear")) {
// current "Interp" supports modes "align_corners" and "asymmetric" only
// other "Interpolate" modes are translated to the default ones
const auto coordinate_transformation_mode = _layer->GetParamAsString("coordinate_transformation_mode", "half_pixel");
const auto coordinateTransformationMode = _layer->GetParamAsString("coordinate_transformation_mode", "half_pixel");
_stageBuilder->addInterpStage(model,
_layer->name,
_layer,
cmp(coordinate_transformation_mode, "align_corners"),
cmp(coordinateTransformationMode, "align_corners"),
input,
output);
} else {

View File

@ -54,10 +54,14 @@ private:
auto antialias = attrs().get<bool>("antialias");
auto factor = attrs().get<float>("factor");
auto sampleType = attrs().get<ResampleType>("type");
auto coordinateTransformationMode = attrs().get<InterpolateCoordTransMode>("coordinate_transformation_mode");
auto nearestMode = attrs().get<InterpolateNearestMode>("nearest_mode");
serializer.append(static_cast<int32_t>(antialias));
serializer.append(static_cast<float>(factor));
serializer.append(static_cast<uint32_t>(sampleType));
serializer.append(static_cast<uint32_t>(coordinateTransformationMode));
serializer.append(static_cast<uint32_t>(nearestMode));
}
void serializeDataImpl(BlobSerializer& serializer) const override {
@ -76,12 +80,16 @@ Stage StageBuilder::addResampleNearestStage(
const std::string& name,
const ie::CNNLayerPtr& layer,
bool antialias,
InterpolateCoordTransMode coordinateTransformationMode,
InterpolateNearestMode nearestMode,
float factor,
const Data& input,
const Data& output) {
auto stage = model->addNewStage<ResampleStage>(layer->name, StageType::Resample, layer, {input}, {output});
stage->attrs().set<bool>("antialias", antialias);
stage->attrs().set<InterpolateCoordTransMode>("coordinate_transformation_mode", coordinateTransformationMode);
stage->attrs().set<InterpolateNearestMode>("nearest_mode", nearestMode);
stage->attrs().set<float>("factor", factor);
stage->attrs().set<ResampleType>("type", ResampleType::Nearest);
@ -98,11 +106,24 @@ void FrontEnd::parseResample(const Model& model, const ie::CNNLayerPtr& layer, c
ie::details::CaselessEq<std::string> cmp;
const auto method = layer->GetParamAsString("type", "caffe.ResampleParameter.NEAREST");
const auto coord = layer->GetParamAsString("coordinate_transformation_mode", "half_pixel");
const auto nearest = layer->GetParamAsString("nearest_mode", "round_prefer_ceil");
InterpolateCoordTransMode coordinateTransformationMode = InterpolateCoordTransMode::HalfPixel;
InterpolateNearestMode nearestMode = InterpolateNearestMode::RoundPreferCeil;
if (cmp(coord, "asymmetric")) {
coordinateTransformationMode = InterpolateCoordTransMode::Asymmetric;
}
if (cmp(nearest, "floor")) {
nearestMode = InterpolateNearestMode::Floor;
}
if (cmp(method, "caffe.ResampleParameter.NEAREST")) {
_stageBuilder->addResampleNearestStage(model,
layer->name,
layer,
layer->GetParamAsInt("antialias", 0),
coordinateTransformationMode, nearestMode,
layer->GetParamAsFloat("factor", -1),
inputs[0],
outputs[0]);

View File

@ -18,10 +18,14 @@ const std::vector<InferenceEngine::Precision> netPrecisions = {
const std::vector<std::vector<size_t>> inShapes = {
{1, 8, 38, 38},
{1, 8, 36, 36},
{1, 8, 35, 35},
};
const std::vector<std::vector<size_t>> targetShapes = {
{1, 8, 38 * 2, 38 * 2},
{1, 8, 70, 70}, // * 1.94
{1, 8, 46, 46}, // * 1.3
};
const std::vector<ngraph::op::v4::Interpolate::InterpolateMode> modesWithoutNearest = {
@ -36,6 +40,10 @@ const std::vector<ngraph::op::v4::Interpolate::CoordinateTransformMode> coordina
ngraph::op::v4::Interpolate::CoordinateTransformMode::half_pixel,
};
const std::vector<ngraph::op::v4::Interpolate::CoordinateTransformMode> coordinateTransformModesNearestMore = {
ngraph::op::v4::Interpolate::CoordinateTransformMode::asymmetric,
};
const std::vector<ngraph::op::v4::Interpolate::CoordinateTransformMode> coordinateTransformModesWithoutNearest = {
ngraph::op::v4::Interpolate::CoordinateTransformMode::asymmetric,
ngraph::op::v4::Interpolate::CoordinateTransformMode::align_corners,
@ -53,6 +61,10 @@ const std::vector<ngraph::op::v4::Interpolate::NearestMode> defaultNearestMode =
ngraph::op::v4::Interpolate::NearestMode::round_prefer_ceil,
};
const std::vector<ngraph::op::v4::Interpolate::NearestMode> defaultNearestModeMore = {
ngraph::op::v4::Interpolate::NearestMode::floor,
};
const std::vector<std::vector<size_t>> pads = {
{0, 0, 0, 0},
};
@ -90,6 +102,18 @@ const auto interpolateCasesNearestMode = ::testing::Combine(
::testing::ValuesIn(defaultAxes),
::testing::ValuesIn(defaultScales));
const auto interpolateCasesNearestModeMore = ::testing::Combine(
::testing::ValuesIn(nearestMode),
::testing::ValuesIn(shapeCalculationMode),
::testing::ValuesIn(coordinateTransformModesNearestMore),
::testing::ValuesIn(defaultNearestModeMore),
::testing::ValuesIn(antialias),
::testing::ValuesIn(pads),
::testing::ValuesIn(pads),
::testing::ValuesIn(cubeCoefs),
::testing::ValuesIn(defaultAxes),
::testing::ValuesIn(defaultScales));
const auto interpolateCasesWithoutNearestMode = ::testing::Combine(
::testing::ValuesIn(modesWithoutNearest),
::testing::ValuesIn(shapeCalculationMode),
@ -114,6 +138,18 @@ INSTANTIATE_TEST_CASE_P(smoke_Interpolate_nearest_mode, InterpolateLayerTest, ::
::testing::Values(CommonTestUtils::DEVICE_MYRIAD)),
InterpolateLayerTest::getTestCaseName);
INSTANTIATE_TEST_CASE_P(smoke_Interpolate_nearest_mode_more, InterpolateLayerTest, ::testing::Combine(
interpolateCasesNearestModeMore,
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::ValuesIn(inShapes),
::testing::ValuesIn(targetShapes),
::testing::Values(CommonTestUtils::DEVICE_MYRIAD)),
InterpolateLayerTest::getTestCaseName);
INSTANTIATE_TEST_CASE_P(smoke_Interpolate_without_nearest, InterpolateLayerTest, ::testing::Combine(
interpolateCasesWithoutNearestMode,
::testing::ValuesIn(netPrecisions),