diff --git a/modules/dnn/src/layers/mvn_layer.cpp b/modules/dnn/src/layers/mvn_layer.cpp index 386446e18f..8f06216df1 100644 --- a/modules/dnn/src/layers/mvn_layer.cpp +++ b/modules/dnn/src/layers/mvn_layer.cpp @@ -394,7 +394,15 @@ public: const std::vector >& nodes) CV_OVERRIDE { auto& ieInpNode = nodes[0].dynamicCast()->node; +#if INF_ENGINE_VER_MAJOR_LE(INF_ENGINE_RELEASE_2021_2) auto mvn = std::make_shared(ieInpNode, acrossChannels, normVariance, eps); +#else + int64_t start_axis = acrossChannels ? 1 : 2; + std::vector axes_v(ieInpNode->get_shape().size() - start_axis); + std::iota(axes_v.begin(), axes_v.end(), start_axis); + auto axes = std::make_shared(ngraph::element::i64, ngraph::Shape{axes_v.size()}, axes_v.data()); + auto mvn = std::make_shared(ieInpNode, axes, normVariance, eps, ngraph::op::MVNEpsMode::INSIDE_SQRT); +#endif return Ptr(new InfEngineNgraphNode(mvn)); } #endif // HAVE_DNN_NGRAPH diff --git a/modules/dnn/src/layers/resize_layer.cpp b/modules/dnn/src/layers/resize_layer.cpp index a41e20a666..40c7351984 100644 --- a/modules/dnn/src/layers/resize_layer.cpp +++ b/modules/dnn/src/layers/resize_layer.cpp @@ -257,6 +257,7 @@ public: { auto& ieInpNode = nodes[0].dynamicCast()->node; +#if INF_ENGINE_VER_MAJOR_LE(INF_ENGINE_RELEASE_2021_2) ngraph::op::InterpolateAttrs attrs; attrs.pads_begin.push_back(0); attrs.pads_end.push_back(0); @@ -275,6 +276,37 @@ public: std::vector shape = {outHeight, outWidth}; auto out_shape = std::make_shared(ngraph::element::i64, ngraph::Shape{2}, shape.data()); auto interp = std::make_shared(ieInpNode, out_shape, attrs); +#else + ngraph::op::v4::Interpolate::InterpolateAttrs attrs; + + if (interpolation == "nearest") { + attrs.mode = ngraph::op::v4::Interpolate::InterpolateMode::nearest; + attrs.coordinate_transformation_mode = ngraph::op::v4::Interpolate::CoordinateTransformMode::half_pixel; + } else if (interpolation == "bilinear") { + attrs.mode = ngraph::op::v4::Interpolate::InterpolateMode::linear_onnx; + attrs.coordinate_transformation_mode = ngraph::op::v4::Interpolate::CoordinateTransformMode::asymmetric; + } else { + CV_Error(Error::StsNotImplemented, format("Unsupported interpolation: %s", interpolation.c_str())); + } + attrs.shape_calculation_mode = ngraph::op::v4::Interpolate::ShapeCalcMode::sizes; + + if (alignCorners) { + attrs.coordinate_transformation_mode = ngraph::op::v4::Interpolate::CoordinateTransformMode::align_corners; + } + + attrs.nearest_mode = ngraph::op::v4::Interpolate::NearestMode::round_prefer_floor; + + std::vector shape = {outHeight, outWidth}; + auto out_shape = std::make_shared(ngraph::element::i64, ngraph::Shape{2}, shape.data()); + + auto& input_shape = ieInpNode->get_shape(); + CV_Assert_N(input_shape[2] != 0, input_shape[3] != 0); + std::vector scales = {static_cast(outHeight) / input_shape[2], static_cast(outWidth) / input_shape[3]}; + auto scales_shape = std::make_shared(ngraph::element::f32, ngraph::Shape{2}, scales.data()); + + auto axes = std::make_shared(ngraph::element::i64, ngraph::Shape{2}, std::vector{2, 3}); + auto interp = std::make_shared(ieInpNode, out_shape, scales_shape, axes, attrs); +#endif return Ptr(new InfEngineNgraphNode(interp)); } #endif // HAVE_DNN_NGRAPH