diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_one_hot_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_one_hot_node.cpp index 24c40f93329..fdc5d95e662 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_one_hot_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_one_hot_node.cpp @@ -2,16 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include #include #include #include "ie_parallel.hpp" -#include "utils/bfloat16.hpp" #include #include "mkldnn_one_hot_node.h" #include #include +#include +#include +#include #include "common/cpu_memcpy.h" using namespace MKLDNNPlugin; @@ -19,19 +20,11 @@ using namespace InferenceEngine; bool MKLDNNOneHotNode::isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept { try { - if (isDynamicNgraphNode(op)) { - errorMessage = "Doesn't support op with dynamic shapes"; - return false; - } const auto oneHot = std::dynamic_pointer_cast(op); if (!oneHot) { errorMessage = "Only opset1 OneHot operation is supported"; return false; } - if (std::dynamic_pointer_cast(oneHot->get_input_node_shared_ptr(DEPTH_ID)) == nullptr) { - errorMessage = "Only const 'depth' input is supported"; - return false; - } if (std::dynamic_pointer_cast(oneHot->get_input_node_shared_ptr(ON_VALUE_ID)) == nullptr) { errorMessage = "Only const 'on_value' input is supported"; return false; @@ -56,20 +49,21 @@ MKLDNNOneHotNode::MKLDNNOneHotNode(const std::shared_ptr& op, cons errorPrefix = "OneHot layer with name '" + op->get_friendly_name() + "'"; const auto oneHot = std::dynamic_pointer_cast(op); const auto depthNode = std::dynamic_pointer_cast(oneHot->get_input_node_shared_ptr(DEPTH_ID)); - const auto onValueNode = std::dynamic_pointer_cast(oneHot->get_input_node_shared_ptr(ON_VALUE_ID)); - const auto offValueNode = std::dynamic_pointer_cast(oneHot->get_input_node_shared_ptr(OFF_VALUEAXES_ID)); - depth = depthNode->cast_vector()[0]; - axis = oneHot->get_axis(); - src_dims = oneHot->get_input_shape(INDICES_ID); - if (ngraph::is_scalar(src_dims)) { - src_dims = SizeVector{1}; + if (depthNode) { + depth = depthNode->cast_vector()[0]; } - dst_dims = oneHot->get_output_shape(0); - if (ngraph::is_scalar(dst_dims)) { - dst_dims = SizeVector{1}; + axis = oneHot->get_axis(); + + VectorDims srcDims = getInputShapeAtPort(INDICES_ID).getDims(); + if (ngraph::is_scalar(srcDims)) { + srcDims = SizeVector{1}; + } + VectorDims dstDims = getOutputShapeAtPort(0).getDims(); + if (ngraph::is_scalar(dstDims)) { + dstDims = SizeVector{1}; } - int output_dims_size = dst_dims.size(); + int output_dims_size = dstDims.size(); if (axis < 0) { axis += output_dims_size; } @@ -77,11 +71,40 @@ MKLDNNOneHotNode::MKLDNNOneHotNode(const std::shared_ptr& op, cons IE_THROW() << errorPrefix << " has unsupported 'axis' attribute: " << oneHot->get_axis(); } - if (!( ((1 + src_dims.size()) == dst_dims.size()) || - (src_dims.size() == 1 && dst_dims.size() == 1 && dst_dims[0] == depth && src_dims[0] == 1))) + if (!(((1 + srcDims.size()) == dstDims.size()) || + (depthNode && (srcDims.size() == 1 && dstDims.size() == 1 && dstDims[0] == depth && srcDims[0] == 1)))) IE_THROW() << errorPrefix << " has incorrect number of input/output dimensions!"; } +bool MKLDNNOneHotNode::needShapeInfer() const { + const auto depthNodePtr = reinterpret_cast(getParentEdgesAtPort(1)[0]->getMemoryPtr()->GetPtr()); + if (depth != depthNodePtr[0]) + return true; + return MKLDNNNode::needShapeInfer(); +} + +std::vector MKLDNNOneHotNode::shapeInfer() const { + std::vector input_shapes = { + getParentEdgesAtPort(0)[0]->getMemory().GetShape().getStaticDims(), + getParentEdgesAtPort(1)[0]->getMemory().GetShape().getStaticDims(), + getParentEdgesAtPort(2)[0]->getMemory().GetShape().getStaticDims(), + getParentEdgesAtPort(3)[0]->getMemory().GetShape().getStaticDims() + }; + std::map> input_values = { + {1, std::make_shared(ngraph::element::Type_t::i32, VectorDims{ }, getParentEdgesAtPort(1)[0]->getMemory().GetPtr())}, + {2, std::make_shared(opToShapeInfer->get_input_node_shared_ptr(2))}, + {3, std::make_shared(opToShapeInfer->get_input_node_shared_ptr(3))} + }; + std::vector output_shapes = {{}}; + shape_inference(opToShapeInfer.get(), input_shapes, output_shapes, input_values); + + std::vector result(output_shapes.size()); + std::transform(output_shapes.begin(), output_shapes.end(), result.begin(), [](const ov::StaticShape& s){ return s.to_shape(); }); + + depth = reinterpret_cast(getParentEdgesAtPort(1)[0]->getMemoryPtr()->GetPtr())[0]; + return result; +} + void MKLDNNOneHotNode::initSupportedPrimitiveDescriptors() { if (!supportedPrimitiveDescriptors.empty()) return; @@ -131,7 +154,7 @@ void MKLDNNOneHotNode::execute(mkldnn::stream strm) { std::size_t prefix_size = 1; auto input_dims = getParentEdgeAt(0)->getMemory().getStaticDims(); - std::size_t actual_axis = (axis == -1) ? src_dims.size() : axis; + std::size_t actual_axis = (axis == -1) ? input_dims.size() : axis; for (size_t i = 0; i < actual_axis; ++i) prefix_size *= input_dims[i]; diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_one_hot_node.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_one_hot_node.h index 18367f21baf..52e44acf026 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_one_hot_node.h +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_one_hot_node.h @@ -23,6 +23,11 @@ public: void execute(mkldnn::stream strm) override; bool created() const override; + bool needShapeInfer() const override; + std::vector shapeInfer() const override; + bool needPrepareParams() const override { return false; }; + void executeDynamicImpl(mkldnn::stream strm) override { execute(strm); }; + static bool isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept; private: @@ -41,10 +46,8 @@ private: } }; - uint32_t depth; + mutable Dim depth = Shape::UNDEFINED_DIM; int32_t axis = -1; - InferenceEngine::SizeVector src_dims; - InferenceEngine::SizeVector dst_dims; InferenceEngine::Precision output_precision; diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/activation.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/activation.cpp index f767af4a310..5dd844586d6 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/activation.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/activation.cpp @@ -126,8 +126,7 @@ TEST_P(ActivationLayerCPUTest, CompareWithRefs) { SKIP_IF_CURRENT_TEST_IS_DISABLED() run(); - // TODO: Should be uncommented after updating the CheckPluginRelatedResults() method - // CheckPluginRelatedResults(executableNetwork, "Eltwise"); + CheckPluginRelatedResults(executableNetwork, "Eltwise"); } @@ -163,8 +162,7 @@ std::vector> basic4D = { }; std::vector netPrc = { - // TODO: Should be uncommented after PR #8339 merge - // Precision::BF16 + Precision::BF16, Precision::FP32 }; diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/batch_to_space.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/batch_to_space.cpp index 44f4a882e50..fd3b6d21700 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/batch_to_space.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/batch_to_space.cpp @@ -87,8 +87,7 @@ TEST_P(BatchToSpaceCPULayerTest, CompareWithRefs) { SKIP_IF_CURRENT_TEST_IS_DISABLED() run(); - // TODO: Should be uncommented after updating the CheckPluginRelatedResults() method - // CheckPluginRelatedResults(executableNetwork, "BatchToSpace"); + CheckPluginRelatedResults(executableNetwork, "BatchToSpace"); }; namespace { @@ -98,8 +97,7 @@ const std::vector netPrecision = { Precision::I8, Precision::I32, Precision::FP32, - // TODO: Should be uncommented after PR #8339 merge - // Precision::BF16 + Precision::BF16 }; const std::vector> blockShape4D1 = {{1, 1, 1, 2}, {1, 2, 2, 1}}; diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/log_softmax.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/log_softmax.cpp index b3248d5aa2b..1351bd92cf5 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/log_softmax.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/log_softmax.cpp @@ -76,8 +76,7 @@ TEST_P(LogSoftmaxLayerCPUTest, CompareWithRefs) { SKIP_IF_CURRENT_TEST_IS_DISABLED() run(); - // TODO: Should be uncommented after updating the CheckPluginRelatedResults() method - // CheckPluginRelatedResults(executableNetwork, "logSoftmax"); + CheckPluginRelatedResults(executableNetwork, "logSoftmax"); } namespace { diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/one_hot.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/one_hot.cpp index e3f083e7460..e42c6a8c44a 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/one_hot.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/one_hot.cpp @@ -3,165 +3,328 @@ // #include +#include #include "test_utils/cpu_test_utils.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" using namespace InferenceEngine; using namespace CPUTestUtils; +using namespace ov::test; namespace CPULayerTestsDefinitions { -typedef std::tuple< - std::vector, // Input shape - int, // axis to extend - size_t, // depth - float, // on_value - float, // off_value - InferenceEngine::Precision,// Net precision - InferenceEngine::Precision,// Input precision - InferenceEngine::Precision,// Output precision - std::string, // Target device name - CPUSpecificParams -> oneHotCPUTestParams; +using oneHotCPUTestParams = std::tuple< + InputShape, // Input shape + int, // axis to extend + std::pair, // secondary input type && need to generate depth + size_t, // depth + float, // on_value + float, // off_value + InferenceEngine::Precision, // Output precision + CPUSpecificParams>; class OneHotLayerCPUTest : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon, public CPUTestsBase { + virtual public SubgraphBaseTest, public CPUTestsBase { public: static std::string getTestCaseName(const testing::TestParamInfo& obj) { - InferenceEngine::SizeVector inputShape; + InputShape inputShape; int axis; + std::pair inputType; size_t depth; float onValue, offValue; - InferenceEngine::Precision netPrecision; - InferenceEngine::Precision inPrc, outPrc; - std::string targetDevice; + InferenceEngine::Precision outPrc; CPUSpecificParams cpuParams; - std::tie(inputShape, axis, depth, onValue, offValue, netPrecision, inPrc, outPrc, targetDevice, cpuParams) = obj.param; + std::tie(inputShape, axis, inputType, depth, onValue, offValue, outPrc, cpuParams) = obj.param; std::ostringstream result; - result << "IS=" << CommonTestUtils::vec2str(inputShape) << "_"; + if (inputShape.first.size() != 0) { + result << "IS=(" << CommonTestUtils::partialShape2str({inputShape.first}) << "_"; + } + result << "TS="; + for (const auto& shape : inputShape.second) { + result << CommonTestUtils::vec2str(shape) << "_"; + } result << "axis=" << axis << "_"; - result << "depth=" << depth << "_"; + if (inputType.first == ngraph::helpers::InputLayerType::CONSTANT && !inputType.second) { + result << "depth=" << depth << "_"; + } else if (inputType.first == ngraph::helpers::InputLayerType::CONSTANT && inputType.second) { + result << "depth=WillBeGenerated" << "_"; + } else { + result << "depth=PARAMETER" << "_"; + } result << "OnVal=" << onValue << "_"; result << "OffVal=" << offValue << "_"; - result << "netPRC=" << netPrecision.name() << "_"; - result << "inPRC=" << inPrc.name() << "_"; - result << "outPRC=" << outPrc.name() << "_"; - result << "trgDev=" << targetDevice; + result << "outPRC=" << outPrc.name(); result << CPUTestsBase::getTestCaseName(cpuParams); return result.str(); } + void generate_inputs(const std::vector& targetInputStaticShapes) override { + inputs.clear(); + const auto& funcInputs = function->inputs(); + for (int i = 0; i < funcInputs.size(); ++i) { + const auto& funcInput = funcInputs[i]; + ov::runtime::Tensor tensor; + + if (i == 1) { + tensor = ov::runtime::Tensor(funcInput.get_element_type(), targetInputStaticShapes[i]); + auto *dataPtr = tensor.data(); + dataPtr[0] = Depth; + } else { + tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i]); + } + + inputs.insert({funcInput.get_node_shared_ptr(), tensor}); + } + } protected: void SetUp() override { - ngraph::Shape inputShape; - int axis; - size_t depth; - float onValue, offValue; - InferenceEngine::Precision netPrecision; + targetDevice = CommonTestUtils::DEVICE_CPU; + + InputShape inputShape; + std::pair inputType; + InferenceEngine::Precision outPrc; CPUSpecificParams cpuParams; + std::tie(inputShape, Axis, inputType, Depth, OnValue, OffValue, outPrc, cpuParams) = this->GetParam(); + + if (inputType.second && inputType.first == ngraph::helpers::InputLayerType::CONSTANT) { + generateDepth(); + } - std::tie(inputShape, axis, depth, onValue, offValue, netPrecision, inPrc, outPrc, targetDevice, cpuParams) = this->GetParam(); std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; - selectedType = std::string("ref_any_") + inPrc.name(); + selectedType = std::string("ref_any_I32"); + outType = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(outPrc); - auto ngOutPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(outPrc); - auto depthConst = ngraph::builder::makeConstant(ngraph::element::i32, {}, {depth}); - auto onConst = ngraph::builder::makeConstant(ngOutPrc, {}, {onValue}); - auto offConst = ngraph::builder::makeConstant(ngOutPrc, {}, {offValue}); + init_input_shapes({inputShape}); + if (inputType.second) { + for (auto &target : targetStaticShapes) + target.push_back({}); + } - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - auto inputParams = ngraph::builder::makeParams(ngPrc, { inputShape }); - - auto oneHot = std::make_shared(inputParams.front(), depthConst, onConst, offConst, axis); - function = makeNgraphFunction(ngPrc, inputParams, oneHot, "OneHot"); + function = createFunction(inputType.first == ngraph::helpers::InputLayerType::CONSTANT); } + void init_ref_function(std::shared_ptr &funcRef, const std::vector& targetInputStaticShapes) override { + if (function->get_parameters().size() == 2) { + generateDepth(); + funcRef = createFunction(true); + } + ngraph::helpers::resize_function(funcRef, targetInputStaticShapes); + } + void validate() override { + if (function->get_parameters().size() == 2) { + auto pos = std::find_if(inputs.begin(), inputs.end(), + [](const std::pair, ov::runtime::Tensor> ¶ms) { + return params.first->get_friendly_name() == "ParamDepth"; + }); + IE_ASSERT(pos != inputs.end()); + inputs.erase(pos); + } + SubgraphBaseTest::validate(); + } + std::shared_ptr createFunction(bool depthConst) { + auto params = ngraph::builder::makeDynamicParams(ngraph::element::i32, {inputDynamicShapes.front()}); + params.front()->set_friendly_name("ParamsIndices"); + std::shared_ptr depth; + if (depthConst) { + depth = ngraph::op::Constant::create(ngraph::element::i32, ngraph::Shape{ }, {Depth}); + } else { + auto depthParam = std::make_shared(ngraph::element::i32, ngraph::Shape{ }); + depthParam->set_friendly_name("ParamDepth"); + params.push_back(depthParam); + depth = depthParam; + } + auto paramOuts = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(params)); + auto on_value_const = std::make_shared(outType, ngraph::Shape{ }, OnValue); + auto off_value_const = std::make_shared(outType, ngraph::Shape{ }, OffValue); + auto oneHot = std::make_shared(paramOuts[0], depth, on_value_const, off_value_const, Axis); + return makeNgraphFunction(ngraph::element::i32, params, oneHot, "OneHot"); + } + void generateDepth() { + testing::internal::Random random(time(nullptr)); + random.Generate(10); + Depth = static_cast(1 + static_cast(random.Generate(10))); + } + + int Axis; + size_t Depth; + float OnValue, OffValue; }; TEST_P(OneHotLayerCPUTest, CompareWithRefs) { SKIP_IF_CURRENT_TEST_IS_DISABLED() - Run(); + run(); CheckPluginRelatedResults(executableNetwork, "OneHot"); } namespace { -const std::vector inPrc = {Precision::I32}; -const std::vector outPrc = {Precision::FP32, Precision::BF16, Precision::I8, Precision::U8}; +const std::vector outPrc = { + Precision::FP32, + Precision::BF16, + Precision::I8, + Precision::U8 +}; + +std::vector> secondaryInputTypesStaticCase = { + {ngraph::helpers::InputLayerType::CONSTANT, true}, + {ngraph::helpers::InputLayerType::CONSTANT, false} +}; +std::vector> secondaryInputTypesDynamicCase = { + {ngraph::helpers::InputLayerType::CONSTANT, true}, + {ngraph::helpers::InputLayerType::CONSTANT, false}, + {ngraph::helpers::InputLayerType::PARAMETER, true} +}; + +const std::vector staticInputShapes0D = { + { } +}; // 0d -> 1d, depth const auto testCase_1d = ::testing::Combine( - ::testing::Values(std::vector{}), + ::testing::ValuesIn(static_shapes_to_test_representation(staticInputShapes0D)), ::testing::Values(-1, 0), - ::testing::Values(3, 4), + ::testing::ValuesIn(secondaryInputTypesStaticCase), + ::testing::Values(3), ::testing::Values(1.f), ::testing::Values(0.f), - ::testing::Values(Precision::I32), - ::testing::ValuesIn(inPrc), ::testing::ValuesIn(outPrc), - ::testing::Values(CommonTestUtils::DEVICE_CPU), ::testing::Values(emptyCPUSpec) ); INSTANTIATE_TEST_SUITE_P(smoke_OneHotCPU_1D, OneHotLayerCPUTest, testCase_1d, OneHotLayerCPUTest::getTestCaseName); - +const std::vector staticInputShapes1D = { + { 3 } +}; // 1d -> 2d, axis default -const auto testCase_2d = ::testing::Combine( - ::testing::Values(std::vector{3}), +const auto testCase_2d_static = ::testing::Combine( + ::testing::ValuesIn(static_shapes_to_test_representation(staticInputShapes1D)), ::testing::Values(-1, 0, 1), + ::testing::ValuesIn(secondaryInputTypesStaticCase), ::testing::Values(6), ::testing::Values(1.f), ::testing::Values(0.f), - ::testing::Values(Precision::I32), - ::testing::ValuesIn(inPrc), ::testing::ValuesIn(outPrc), - ::testing::Values(CommonTestUtils::DEVICE_CPU), ::testing::Values(emptyCPUSpec) ); -INSTANTIATE_TEST_SUITE_P(smoke_OneHotCPU_2D, OneHotLayerCPUTest, testCase_2d, OneHotLayerCPUTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_OneHotCPU_2D_Static, OneHotLayerCPUTest, testCase_2d_static, OneHotLayerCPUTest::getTestCaseName); -// 2d -> 3d, on_value, off_value -const auto testCase_3d = ::testing::Combine( - ::testing::Values(std::vector{3, 2}), +const std::vector dynamicInputShapes1D = { + {{-1}, {{3}, {4}, {5}}}, + {{{1, 5}}, {{1}, {3}, {5}}}, +}; +// 1d -> 2d, axis default +const auto testCase_2d_dynamic = ::testing::Combine( + ::testing::ValuesIn(dynamicInputShapes1D), ::testing::Values(-1, 0, 1), + ::testing::ValuesIn(secondaryInputTypesDynamicCase), + ::testing::Values(6), + ::testing::Values(1.f), + ::testing::Values(0.f), + ::testing::ValuesIn(outPrc), + ::testing::Values(emptyCPUSpec) +); +INSTANTIATE_TEST_SUITE_P(smoke_OneHotCPU_2D_Dynamic, OneHotLayerCPUTest, testCase_2d_dynamic, OneHotLayerCPUTest::getTestCaseName); + +const std::vector staticInputShapes2D = { + { 3, 2 } +}; +// 2d -> 3d, on_value, off_value +const auto testCase_3d_static = ::testing::Combine( + ::testing::ValuesIn(static_shapes_to_test_representation(staticInputShapes2D)), + ::testing::Values(-1, 0, 1), + ::testing::ValuesIn(secondaryInputTypesStaticCase), ::testing::Values(4), ::testing::Values(2.f), ::testing::Values(-1.f), - ::testing::Values(Precision::I32), - ::testing::ValuesIn(inPrc), ::testing::ValuesIn(outPrc), - ::testing::Values(CommonTestUtils::DEVICE_CPU), ::testing::Values(emptyCPUSpec) ); -INSTANTIATE_TEST_SUITE_P(smoke_OneHotCPU_3D, OneHotLayerCPUTest, testCase_3d, OneHotLayerCPUTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_OneHotCPU_3D_Static, OneHotLayerCPUTest, testCase_3d_static, OneHotLayerCPUTest::getTestCaseName); +const std::vector dynamicInputShapes2D = { + {{-1, -1}, {{3, 2}, {2, 3}, {4, 4}}}, + {{-1, 3}, {{2, 3}, {3, 3}, {4, 3}}}, + {{{1, 5}, {3, 4}}, {{2, 3}, {3, 4}, {4, 3}}} +}; +// 2d -> 3d, on_value, off_value +const auto testCase_3d_dynamic = ::testing::Combine( + ::testing::ValuesIn(dynamicInputShapes2D), + ::testing::Values(-1, 0, 1), + ::testing::ValuesIn(secondaryInputTypesDynamicCase), + ::testing::Values(4), + ::testing::Values(2.f), + ::testing::Values(-1.f), + ::testing::ValuesIn(outPrc), + ::testing::Values(emptyCPUSpec) +); +INSTANTIATE_TEST_SUITE_P(smoke_OneHotCPU_3D_Dynamic, OneHotLayerCPUTest, testCase_3d_dynamic, OneHotLayerCPUTest::getTestCaseName); + +const std::vector staticInputShapes3D = { + { 1, 3, 2 } +}; // 3d -> 4d -const auto testCase_4d = ::testing::Combine( - ::testing::Values(std::vector{1, 3, 2}), +const auto testCase_4d_static = ::testing::Combine( + ::testing::ValuesIn(static_shapes_to_test_representation(staticInputShapes3D)), ::testing::Values(-1, 0, 1, 2), + ::testing::ValuesIn(secondaryInputTypesStaticCase), ::testing::Values(4), ::testing::Values(1.f), ::testing::Values(0.f), - ::testing::Values(Precision::I32), - ::testing::ValuesIn(inPrc), ::testing::ValuesIn(outPrc), - ::testing::Values(CommonTestUtils::DEVICE_CPU), ::testing::Values(emptyCPUSpec) ); -INSTANTIATE_TEST_SUITE_P(smoke_OneHotCPU_4D, OneHotLayerCPUTest, testCase_4d, OneHotLayerCPUTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_OneHotCPU_4D_Static, OneHotLayerCPUTest, testCase_4d_static, OneHotLayerCPUTest::getTestCaseName); -// 4d -> 5d -const auto testCase_5d = ::testing::Combine( - ::testing::Values(std::vector{1, 3, 2, 3}), - ::testing::Values(-1, 0, 1, 2, 3), +const std::vector dynamicInputShapes3D = { + {{-1, -1, -1}, {{1, 3, 2}, {1, 2, 3}, {2, 4, 4}}}, + {{-1, 3, -1}, {{2, 3, 1}, {1, 3, 2}, {1, 3, 5}}}, + {{{1, 2}, 3, {1, 5}}, {{2, 3, 1}, {1, 3, 2}, {1, 3, 5}}} +}; +// 3d -> 4d +const auto testCase_4d_dynamic = ::testing::Combine( + ::testing::ValuesIn(dynamicInputShapes3D), + ::testing::Values(-1, 0, 1, 2), + ::testing::ValuesIn(secondaryInputTypesDynamicCase), ::testing::Values(4), ::testing::Values(1.f), ::testing::Values(0.f), - ::testing::Values(Precision::I32), - ::testing::ValuesIn(inPrc), ::testing::ValuesIn(outPrc), - ::testing::Values(CommonTestUtils::DEVICE_CPU), ::testing::Values(emptyCPUSpec) ); -INSTANTIATE_TEST_SUITE_P(smoke_OneHotCPU_5D, OneHotLayerCPUTest, testCase_5d, OneHotLayerCPUTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_OneHotCPU_4D_Dynamic, OneHotLayerCPUTest, testCase_4d_dynamic, OneHotLayerCPUTest::getTestCaseName); + +const std::vector staticInputShapes4D = { + { 1, 3, 2, 3 } +}; +// 4d -> 5d +const auto testCase_5d_static = ::testing::Combine( + ::testing::ValuesIn(static_shapes_to_test_representation(staticInputShapes4D)), + ::testing::Values(-1, 0, 1, 2, 3), + ::testing::ValuesIn(secondaryInputTypesStaticCase), + ::testing::Values(4), + ::testing::Values(1.f), + ::testing::Values(0.f), + ::testing::ValuesIn(outPrc), + ::testing::Values(emptyCPUSpec) +); +INSTANTIATE_TEST_SUITE_P(smoke_OneHotCPU_5D_Static, OneHotLayerCPUTest, testCase_5d_static, OneHotLayerCPUTest::getTestCaseName); + +const std::vector dynamicInputShapes4D = { + {{-1, -1, -1, -1}, {{1, 3, 2, 3}, {1, 2, 3, 2}, {2, 3, 4, 4}}}, + {{-1, 3, -1, {1, 3}}, {{1, 3, 3, 1}, {1, 3, 2, 2}, {1, 3, 5, 3}}}, + {{{1, 2}, 3, {2, 5}, {1, 3}}, {{1, 3, 3, 1}, {2, 3, 2, 2}, {1, 3, 5, 3}}} +}; +// 4d -> 5d +const auto testCase_5d_dynamic = ::testing::Combine( + ::testing::ValuesIn(dynamicInputShapes4D), + ::testing::Values(-1, 0, 1, 2, 3), + ::testing::ValuesIn(secondaryInputTypesDynamicCase), + ::testing::Values(4), + ::testing::Values(1.f), + ::testing::Values(0.f), + ::testing::ValuesIn(outPrc), + ::testing::Values(emptyCPUSpec) +); +INSTANTIATE_TEST_SUITE_P(smoke_OneHotCPU_5D_Dynamic, OneHotLayerCPUTest, testCase_5d_dynamic, OneHotLayerCPUTest::getTestCaseName); } // namespace -} // namespace CPULayerTestsDefinitions \ No newline at end of file +} // namespace CPULayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/proposal.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/proposal.cpp index 85099c1cdfe..52770dca8fb 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/proposal.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/proposal.cpp @@ -135,6 +135,7 @@ protected: framework, min_size, nms_thresh, normalize, post_nms_topn, pre_nms_topn, ratio, scale) = proposalParams; + selectedType = std::string("ref_any_") + netPrecision.name(); init_input_shapes(inputShapes); auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); @@ -193,8 +194,7 @@ TEST_P(ProposalLayerCPUTest, CompareWithRefs) { SKIP_IF_CURRENT_TEST_IS_DISABLED() run(); - // TODO: Should be uncommented after updating the CheckPluginRelatedResults() method - // CheckPluginRelatedResults(executableNetwork, "Proposal"); + CheckPluginRelatedResults(executableNetwork, "Proposal"); } namespace { diff --git a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/base/ov_subgraph.hpp b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/base/ov_subgraph.hpp index df0412f3a5d..dda96bb56fc 100644 --- a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/base/ov_subgraph.hpp +++ b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/base/ov_subgraph.hpp @@ -36,6 +36,7 @@ protected: virtual void configure_model(); virtual void compile_model(); + virtual void init_ref_function(std::shared_ptr &funcRef, const std::vector& targetInputStaticShapes); virtual void generate_inputs(const std::vector& targetInputStaticShapes); virtual void infer(); virtual void validate(); diff --git a/inference-engine/tests/functional/shared_test_classes/src/base/ov_subgraph.cpp b/inference-engine/tests/functional/shared_test_classes/src/base/ov_subgraph.cpp index 31315211cdb..4270fb56929 100644 --- a/inference-engine/tests/functional/shared_test_classes/src/base/ov_subgraph.cpp +++ b/inference-engine/tests/functional/shared_test_classes/src/base/ov_subgraph.cpp @@ -50,7 +50,7 @@ void SubgraphBaseTest::run() { try { if (!inputDynamicShapes.empty()) { // resize ngraph function according new target shape - ngraph::helpers::resize_function(functionRefs, targetStaticShapeVec); + init_ref_function(functionRefs, targetStaticShapeVec); } generate_inputs(targetStaticShapeVec); infer(); @@ -162,6 +162,10 @@ void SubgraphBaseTest::compile_model() { executableNetwork = core->compile_model(function, targetDevice, configuration); } +void SubgraphBaseTest::init_ref_function(std::shared_ptr &funcRef, const std::vector& targetInputStaticShapes) { + ngraph::helpers::resize_function(funcRef, targetInputStaticShapes); +} + void SubgraphBaseTest::generate_inputs(const std::vector& targetInputStaticShapes) { inputs.clear(); const auto& funcInputs = function->inputs(); diff --git a/ngraph/core/src/op/one_hot.cpp b/ngraph/core/src/op/one_hot.cpp index e256070dbdd..2af7a5a8a9d 100644 --- a/ngraph/core/src/op/one_hot.cpp +++ b/ngraph/core/src/op/one_hot.cpp @@ -66,7 +66,7 @@ void op::v1::OneHot::validate_and_infer_types() { ov::PartialShape result_shape{ov::PartialShape::dynamic()}; const auto& depth = input_value(1).get_node_shared_ptr(); const auto& depth_constant = get_constant_from_source(input_value(1)); - if (indices_shape.rank().is_static() && depth_constant) { + if (indices_shape.rank().is_static()) { std::vector out_dims{indices_shape}; const auto indices_rank = indices_shape.rank().get_length(); m_axis = ngraph::normalize_axis(this, m_axis, indices_rank + 1, -indices_rank - 1, indices_rank); @@ -84,15 +84,18 @@ void op::v1::OneHot::validate_and_infer_types() { " (got ", depth->get_shape(), " elements)."); - - int64_t depth_val = depth_constant->cast_vector()[0]; - NODE_VALIDATION_CHECK(this, - depth_val > 0, - "The value of 'depth' must be a positive number.", - " (got ", - depth_val, - ")."); - out_dims.insert(out_dims.begin() + m_axis, Dimension(depth_val)); + if (depth_constant) { + int64_t depth_val = depth_constant->cast_vector()[0]; + NODE_VALIDATION_CHECK(this, + depth_val > 0, + "The value of 'depth' must be a positive number.", + " (got ", + depth_val, + ")."); + out_dims.insert(out_dims.begin() + m_axis, Dimension(depth_val)); + } else { + out_dims.insert(out_dims.begin() + m_axis, Dimension::dynamic()); + } result_shape = out_dims; } @@ -155,7 +158,7 @@ bool op::v1::OneHot::evaluate(const HostTensorVector& output_values, const HostT const auto out_shape = out_Pshape.get_shape(); const size_t axis = get_axis(); NGRAPH_CHECK(axis >= 0 && axis < out_shape.size(), "Invalid axis value."); - const auto depth = get_constant_from_source(input_value(1))->cast_vector()[0]; + const auto depth = std::make_shared(input_values[1])->cast_vector()[0]; const auto ind_shape = ind_Pshape.get_shape(); NGRAPH_CHECK(shape_size(ind_shape) * depth == shape_size(out_shape), "Incompatible I/O shapes or wrong depth value."); diff --git a/runtime/bindings/python/tests/test_ngraph/test_sequence_processing.py b/runtime/bindings/python/tests/test_ngraph/test_sequence_processing.py index c394225230e..47edef2f198 100644 --- a/runtime/bindings/python/tests/test_ngraph/test_sequence_processing.py +++ b/runtime/bindings/python/tests/test_ngraph/test_sequence_processing.py @@ -6,7 +6,6 @@ import numpy as np import openvino.opset8 as ov from tests.runtime import get_runtime from tests.test_ngraph.util import run_op_node -from tests import (xfail_issue_47337) def test_onehot(): @@ -21,7 +20,6 @@ def test_onehot(): assert np.allclose(result, expected) -@xfail_issue_47337 def test_one_hot(): data = np.array([0, 1, 2], dtype=np.int32) depth = 2 diff --git a/runtime/bindings/python/tests/test_onnx/test_backend.py b/runtime/bindings/python/tests/test_onnx/test_backend.py index dbc6a24b7de..962ee68537a 100644 --- a/runtime/bindings/python/tests/test_onnx/test_backend.py +++ b/runtime/bindings/python/tests/test_onnx/test_backend.py @@ -243,9 +243,6 @@ tests_expected_to_fail = [ ), ( xfail_issue_47337, - "OnnxBackendNodeModelTest.test_onehot_without_axis_cpu", - "OnnxBackendNodeModelTest.test_onehot_with_negative_axis_cpu", - "OnnxBackendNodeModelTest.test_onehot_with_axis_cpu", "OnnxBackendNodeModelTest.test_onehot_negative_indices_cpu", ), ( diff --git a/runtime/bindings/python/tests_compatibility/test_ngraph/test_sequence_processing.py b/runtime/bindings/python/tests_compatibility/test_ngraph/test_sequence_processing.py index 7bd9b767622..14e4510cc76 100644 --- a/runtime/bindings/python/tests_compatibility/test_ngraph/test_sequence_processing.py +++ b/runtime/bindings/python/tests_compatibility/test_ngraph/test_sequence_processing.py @@ -6,7 +6,6 @@ import numpy as np import ngraph as ng from tests_compatibility.runtime import get_runtime from tests_compatibility.test_ngraph.util import run_op_node -from tests_compatibility import (xfail_issue_47337) def test_onehot(): @@ -21,7 +20,6 @@ def test_onehot(): assert np.allclose(result, expected) -@xfail_issue_47337 def test_one_hot(): data = np.array([0, 1, 2], dtype=np.int32) depth = 2 diff --git a/runtime/bindings/python/tests_compatibility/test_onnx/test_backend.py b/runtime/bindings/python/tests_compatibility/test_onnx/test_backend.py index d15cad8d27a..d052bb530c1 100644 --- a/runtime/bindings/python/tests_compatibility/test_onnx/test_backend.py +++ b/runtime/bindings/python/tests_compatibility/test_onnx/test_backend.py @@ -228,9 +228,6 @@ tests_expected_to_fail = [ ), ( xfail_issue_47337, - "OnnxBackendNodeModelTest.test_onehot_without_axis_cpu", - "OnnxBackendNodeModelTest.test_onehot_with_negative_axis_cpu", - "OnnxBackendNodeModelTest.test_onehot_with_axis_cpu", "OnnxBackendNodeModelTest.test_onehot_negative_indices_cpu", ), (