[CPU] OneHot dynamic done (#8488)
This commit is contained in:
parent
a1e95f4d69
commit
c4e49bb915
@ -2,16 +2,17 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <mkldnn_types.h>
|
||||
#include "ie_parallel.hpp"
|
||||
#include "utils/bfloat16.hpp"
|
||||
#include <mkldnn_selective_build.h>
|
||||
#include "mkldnn_one_hot_node.h"
|
||||
#include <nodes/common/blocked_desc_creator.h>
|
||||
#include <ngraph/opsets/opset1.hpp>
|
||||
#include <ie_ngraph_utils.hpp>
|
||||
#include <utils/shape_inference/static_shape.hpp>
|
||||
#include <utils/shape_inference/shape_inference.hpp>
|
||||
#include "common/cpu_memcpy.h"
|
||||
|
||||
using namespace MKLDNNPlugin;
|
||||
@ -19,19 +20,11 @@ using namespace InferenceEngine;
|
||||
|
||||
bool MKLDNNOneHotNode::isSupportedOperation(const std::shared_ptr<const ngraph::Node>& 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<const ngraph::opset1::OneHot>(op);
|
||||
if (!oneHot) {
|
||||
errorMessage = "Only opset1 OneHot operation is supported";
|
||||
return false;
|
||||
}
|
||||
if (std::dynamic_pointer_cast<const ngraph::opset1::Constant>(oneHot->get_input_node_shared_ptr(DEPTH_ID)) == nullptr) {
|
||||
errorMessage = "Only const 'depth' input is supported";
|
||||
return false;
|
||||
}
|
||||
if (std::dynamic_pointer_cast<const ngraph::opset1::Constant>(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<ngraph::Node>& op, cons
|
||||
errorPrefix = "OneHot layer with name '" + op->get_friendly_name() + "'";
|
||||
const auto oneHot = std::dynamic_pointer_cast<const ngraph::opset1::OneHot>(op);
|
||||
const auto depthNode = std::dynamic_pointer_cast<const ngraph::opset1::Constant>(oneHot->get_input_node_shared_ptr(DEPTH_ID));
|
||||
const auto onValueNode = std::dynamic_pointer_cast<const ngraph::opset1::Constant>(oneHot->get_input_node_shared_ptr(ON_VALUE_ID));
|
||||
const auto offValueNode = std::dynamic_pointer_cast<const ngraph::opset1::Constant>(oneHot->get_input_node_shared_ptr(OFF_VALUEAXES_ID));
|
||||
depth = depthNode->cast_vector<uint32_t>()[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<uint32_t>()[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<ngraph::Node>& 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<int32_t *>(getParentEdgesAtPort(1)[0]->getMemoryPtr()->GetPtr());
|
||||
if (depth != depthNodePtr[0])
|
||||
return true;
|
||||
return MKLDNNNode::needShapeInfer();
|
||||
}
|
||||
|
||||
std::vector<VectorDims> MKLDNNOneHotNode::shapeInfer() const {
|
||||
std::vector<ov::StaticShape> 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<size_t, std::shared_ptr<ngraph::runtime::HostTensor>> input_values = {
|
||||
{1, std::make_shared<ngraph::runtime::HostTensor>(ngraph::element::Type_t::i32, VectorDims{ }, getParentEdgesAtPort(1)[0]->getMemory().GetPtr())},
|
||||
{2, std::make_shared<ngraph::runtime::HostTensor>(opToShapeInfer->get_input_node_shared_ptr(2))},
|
||||
{3, std::make_shared<ngraph::runtime::HostTensor>(opToShapeInfer->get_input_node_shared_ptr(3))}
|
||||
};
|
||||
std::vector<ov::StaticShape> output_shapes = {{}};
|
||||
shape_inference(opToShapeInfer.get(), input_shapes, output_shapes, input_values);
|
||||
|
||||
std::vector<VectorDims> 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<int32_t *>(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];
|
||||
|
||||
|
@ -23,6 +23,11 @@ public:
|
||||
void execute(mkldnn::stream strm) override;
|
||||
bool created() const override;
|
||||
|
||||
bool needShapeInfer() const override;
|
||||
std::vector<VectorDims> shapeInfer() const override;
|
||||
bool needPrepareParams() const override { return false; };
|
||||
void executeDynamicImpl(mkldnn::stream strm) override { execute(strm); };
|
||||
|
||||
static bool isSupportedOperation(const std::shared_ptr<const ngraph::Node>& 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;
|
||||
|
||||
|
@ -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<std::vector<ov::Shape>> basic4D = {
|
||||
};
|
||||
|
||||
std::vector<Precision> netPrc = {
|
||||
// TODO: Should be uncommented after PR #8339 merge
|
||||
// Precision::BF16
|
||||
Precision::BF16,
|
||||
Precision::FP32
|
||||
};
|
||||
|
||||
|
@ -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<Precision> netPrecision = {
|
||||
Precision::I8,
|
||||
Precision::I32,
|
||||
Precision::FP32,
|
||||
// TODO: Should be uncommented after PR #8339 merge
|
||||
// Precision::BF16
|
||||
Precision::BF16
|
||||
};
|
||||
|
||||
const std::vector<std::vector<int64_t>> blockShape4D1 = {{1, 1, 1, 2}, {1, 2, 2, 1}};
|
||||
|
@ -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 {
|
||||
|
@ -3,165 +3,328 @@
|
||||
//
|
||||
|
||||
#include <ngraph_functions/builders.hpp>
|
||||
#include <functional_test_utils/ov_tensor_utils.hpp>
|
||||
#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<size_t>, // 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<ngraph::helpers::InputLayerType, bool>, // 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<oneHotCPUTestParams>,
|
||||
virtual public LayerTestsUtils::LayerTestsCommon, public CPUTestsBase {
|
||||
virtual public SubgraphBaseTest, public CPUTestsBase {
|
||||
public:
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<oneHotCPUTestParams>& obj) {
|
||||
InferenceEngine::SizeVector inputShape;
|
||||
InputShape inputShape;
|
||||
int axis;
|
||||
std::pair<ngraph::helpers::InputLayerType, bool> 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<ngraph::Shape>& 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<int32_t>();
|
||||
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<ngraph::helpers::InputLayerType, bool> 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<size_t>(ngraph::element::i32, {}, {depth});
|
||||
auto onConst = ngraph::builder::makeConstant<float>(ngOutPrc, {}, {onValue});
|
||||
auto offConst = ngraph::builder::makeConstant<float>(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<ngraph::opset5::OneHot>(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<ov::Function> &funcRef, const std::vector<ov::Shape>& 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<std::shared_ptr<ov::Node>, ov::runtime::Tensor> ¶ms) {
|
||||
return params.first->get_friendly_name() == "ParamDepth";
|
||||
});
|
||||
IE_ASSERT(pos != inputs.end());
|
||||
inputs.erase(pos);
|
||||
}
|
||||
SubgraphBaseTest::validate();
|
||||
}
|
||||
std::shared_ptr<ngraph::Function> createFunction(bool depthConst) {
|
||||
auto params = ngraph::builder::makeDynamicParams(ngraph::element::i32, {inputDynamicShapes.front()});
|
||||
params.front()->set_friendly_name("ParamsIndices");
|
||||
std::shared_ptr<ov::Node> depth;
|
||||
if (depthConst) {
|
||||
depth = ngraph::op::Constant::create(ngraph::element::i32, ngraph::Shape{ }, {Depth});
|
||||
} else {
|
||||
auto depthParam = std::make_shared<ngraph::op::Parameter>(ngraph::element::i32, ngraph::Shape{ });
|
||||
depthParam->set_friendly_name("ParamDepth");
|
||||
params.push_back(depthParam);
|
||||
depth = depthParam;
|
||||
}
|
||||
auto paramOuts = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes<ngraph::opset3::Parameter>(params));
|
||||
auto on_value_const = std::make_shared<ngraph::op::Constant>(outType, ngraph::Shape{ }, OnValue);
|
||||
auto off_value_const = std::make_shared<ngraph::op::Constant>(outType, ngraph::Shape{ }, OffValue);
|
||||
auto oneHot = std::make_shared<ngraph::opset5::OneHot>(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<int64_t>(1 + static_cast<int64_t>(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<Precision> inPrc = {Precision::I32};
|
||||
const std::vector<Precision> outPrc = {Precision::FP32, Precision::BF16, Precision::I8, Precision::U8};
|
||||
const std::vector<Precision> outPrc = {
|
||||
Precision::FP32,
|
||||
Precision::BF16,
|
||||
Precision::I8,
|
||||
Precision::U8
|
||||
};
|
||||
|
||||
std::vector<std::pair<ngraph::helpers::InputLayerType, bool>> secondaryInputTypesStaticCase = {
|
||||
{ngraph::helpers::InputLayerType::CONSTANT, true},
|
||||
{ngraph::helpers::InputLayerType::CONSTANT, false}
|
||||
};
|
||||
std::vector<std::pair<ngraph::helpers::InputLayerType, bool>> secondaryInputTypesDynamicCase = {
|
||||
{ngraph::helpers::InputLayerType::CONSTANT, true},
|
||||
{ngraph::helpers::InputLayerType::CONSTANT, false},
|
||||
{ngraph::helpers::InputLayerType::PARAMETER, true}
|
||||
};
|
||||
|
||||
const std::vector<ov::Shape> staticInputShapes0D = {
|
||||
{ }
|
||||
};
|
||||
|
||||
// 0d -> 1d, depth
|
||||
const auto testCase_1d = ::testing::Combine(
|
||||
::testing::Values(std::vector<size_t>{}),
|
||||
::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<ov::Shape> staticInputShapes1D = {
|
||||
{ 3 }
|
||||
};
|
||||
// 1d -> 2d, axis default
|
||||
const auto testCase_2d = ::testing::Combine(
|
||||
::testing::Values(std::vector<size_t>{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<size_t>{3, 2}),
|
||||
const std::vector<InputShape> 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<ov::Shape> 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<InputShape> 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<ov::Shape> staticInputShapes3D = {
|
||||
{ 1, 3, 2 }
|
||||
};
|
||||
// 3d -> 4d
|
||||
const auto testCase_4d = ::testing::Combine(
|
||||
::testing::Values(std::vector<size_t>{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<size_t>{1, 3, 2, 3}),
|
||||
::testing::Values(-1, 0, 1, 2, 3),
|
||||
const std::vector<InputShape> 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<ov::Shape> 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<InputShape> 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
|
@ -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 {
|
||||
|
@ -36,6 +36,7 @@ protected:
|
||||
|
||||
virtual void configure_model();
|
||||
virtual void compile_model();
|
||||
virtual void init_ref_function(std::shared_ptr<ov::Function> &funcRef, const std::vector<ov::Shape>& targetInputStaticShapes);
|
||||
virtual void generate_inputs(const std::vector<ngraph::Shape>& targetInputStaticShapes);
|
||||
virtual void infer();
|
||||
virtual void validate();
|
||||
|
@ -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<ov::Function> &funcRef, const std::vector<ov::Shape>& targetInputStaticShapes) {
|
||||
ngraph::helpers::resize_function(funcRef, targetInputStaticShapes);
|
||||
}
|
||||
|
||||
void SubgraphBaseTest::generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) {
|
||||
inputs.clear();
|
||||
const auto& funcInputs = function->inputs();
|
||||
|
@ -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<Dimension> 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<int64_t>()[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<int64_t>()[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<int64_t>()[0];
|
||||
const auto depth = std::make_shared<op::v0::Constant>(input_values[1])->cast_vector<int64_t>()[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.");
|
||||
|
@ -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
|
||||
|
@ -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",
|
||||
),
|
||||
(
|
||||
|
@ -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
|
||||
|
@ -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",
|
||||
),
|
||||
(
|
||||
|
Loading…
Reference in New Issue
Block a user