ONNX Unique op support (#15076)
This commit is contained in:
1 parent
14a7e443d0
commit
f4dda48795
11 files changed
+522
-5
No files matched your search
@@ -183,11 +183,8 @@ tests_expected_to_fail = [
|
||||
),
|
||||
(
|
||||
xfail_issue_33595,
|
||||
"OnnxBackendNodeModelTest.test_unique_not_sorted_without_axis_cpu",
|
||||
"OnnxBackendNodeModelTest.test_unique_sorted_with_negative_axis_cpu",
|
||||
"OnnxBackendNodeModelTest.test_unique_sorted_with_axis_cpu",
|
||||
"OnnxBackendNodeModelTest.test_unique_sorted_with_axis_3d_cpu",
|
||||
"OnnxBackendNodeModelTest.test_unique_sorted_without_axis_cpu",
|
||||
),
|
||||
(
|
||||
xfail_issue_33651,
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "ngraph/opsets/opset8.hpp"
|
||||
#include "ngraph/opsets/opset10.hpp"
|
||||
|
||||
namespace ngraph {
|
||||
namespace onnx_import {
|
||||
namespace default_opset = ngraph::opset8;
|
||||
namespace default_opset = ngraph::opset10;
|
||||
}
|
||||
} // namespace ngraph
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "op/unique.hpp"
|
||||
|
||||
#include "default_opset.hpp"
|
||||
|
||||
namespace ngraph {
|
||||
namespace onnx_import {
|
||||
namespace op {
|
||||
namespace set_1 {
|
||||
OutputVector unique(const Node& node) {
|
||||
const auto data = node.get_ng_inputs().at(0);
|
||||
const bool sorted = node.get_attribute_value<int64_t>("sorted", 1);
|
||||
|
||||
if (node.has_attribute("axis")) {
|
||||
const auto axis = node.get_attribute_as_constant<int64_t>("axis");
|
||||
return std::make_shared<default_opset::Unique>(data, axis, sorted)->outputs();
|
||||
} else {
|
||||
return std::make_shared<default_opset::Unique>(data, sorted)->outputs();
|
||||
}
|
||||
}
|
||||
} // namespace set_1
|
||||
} // namespace op
|
||||
} // namespace onnx_import
|
||||
} // namespace ngraph
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ngraph/node.hpp"
|
||||
#include "onnx_import/core/node.hpp"
|
||||
|
||||
namespace ngraph {
|
||||
namespace onnx_import {
|
||||
namespace op {
|
||||
namespace set_1 {
|
||||
OutputVector unique(const Node& node);
|
||||
|
||||
} // namespace set_1
|
||||
} // namespace op
|
||||
|
||||
} // namespace onnx_import
|
||||
|
||||
} // namespace ngraph
|
||||
@@ -169,6 +169,7 @@
|
||||
#include "op/topk.hpp"
|
||||
#include "op/transpose.hpp"
|
||||
#include "op/trilu.hpp"
|
||||
#include "op/unique.hpp"
|
||||
#include "op/unsqueeze.hpp"
|
||||
#include "op/upsample.hpp"
|
||||
#include "op/where.hpp"
|
||||
@@ -468,6 +469,7 @@ OperatorsBridge::OperatorsBridge() {
|
||||
REGISTER_OPERATOR("TopK", 11, topk);
|
||||
REGISTER_OPERATOR("Transpose", 1, transpose);
|
||||
REGISTER_OPERATOR("Trilu", 1, trilu);
|
||||
REGISTER_OPERATOR("Unique", 1, unique);
|
||||
REGISTER_OPERATOR("Unsqueeze", 1, unsqueeze);
|
||||
REGISTER_OPERATOR("Unsqueeze", 13, unsqueeze);
|
||||
REGISTER_OPERATOR("Where", 1, where);
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
ir_version: 7
|
||||
graph {
|
||||
node {
|
||||
input: "data"
|
||||
output: "unique"
|
||||
output: "unique_idx"
|
||||
output: "unique_rev_idx"
|
||||
output: "unique_counts"
|
||||
op_type: "Unique"
|
||||
attribute {
|
||||
name: "sorted"
|
||||
i: 0
|
||||
type: INT
|
||||
}
|
||||
}
|
||||
input {
|
||||
name: "data"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 6
|
||||
shape {
|
||||
dim {
|
||||
dim_value: 5
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 6
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique_idx"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 7
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique_rev_idx"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 7
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique_counts"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 7
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
opset_import {
|
||||
domain: ""
|
||||
version: 13
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
ir_version: 7
|
||||
graph {
|
||||
node {
|
||||
input: "data"
|
||||
output: "unique"
|
||||
output: "unique_idx"
|
||||
output: "unique_rev_idx"
|
||||
output: "unique_counts"
|
||||
op_type: "Unique"
|
||||
attribute {
|
||||
name: "sorted"
|
||||
i: 1
|
||||
type: INT
|
||||
}
|
||||
}
|
||||
input {
|
||||
name: "data"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 6
|
||||
shape {
|
||||
dim {
|
||||
dim_value: 5
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 6
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique_idx"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 7
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique_rev_idx"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 7
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique_counts"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 7
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
opset_import {
|
||||
domain: ""
|
||||
version: 13
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
ir_version: 7
|
||||
graph {
|
||||
node {
|
||||
input: "data"
|
||||
output: "unique"
|
||||
output: "unique_idx"
|
||||
output: "unique_rev_idx"
|
||||
output: "unique_counts"
|
||||
op_type: "Unique"
|
||||
}
|
||||
input {
|
||||
name: "data"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 6
|
||||
shape {
|
||||
dim {
|
||||
dim_value: 2
|
||||
}
|
||||
dim {
|
||||
dim_value: 2
|
||||
}
|
||||
dim {
|
||||
dim_value: 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 6
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique_idx"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 7
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique_rev_idx"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 7
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique_counts"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 7
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
opset_import {
|
||||
domain: ""
|
||||
version: 13
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
ir_version: 7
|
||||
graph {
|
||||
node {
|
||||
input: "data"
|
||||
output: "unique"
|
||||
output: "unique_idx"
|
||||
output: "unique_rev_idx"
|
||||
output: "unique_counts"
|
||||
op_type: "Unique"
|
||||
attribute {
|
||||
name: "sorted"
|
||||
i: 1
|
||||
type: INT
|
||||
}
|
||||
attribute {
|
||||
name: "axis"
|
||||
i: 0
|
||||
type: INT
|
||||
}
|
||||
}
|
||||
input {
|
||||
name: "data"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 6
|
||||
shape {
|
||||
dim {
|
||||
dim_value: 2
|
||||
}
|
||||
dim {
|
||||
dim_value: 2
|
||||
}
|
||||
dim {
|
||||
dim_value: 3
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 6
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique_idx"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 7
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique_rev_idx"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 7
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique_counts"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 7
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
opset_import {
|
||||
domain: ""
|
||||
version: 13
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
ir_version: 7
|
||||
graph {
|
||||
node {
|
||||
input: "data"
|
||||
output: "unique"
|
||||
output: "unique_idx"
|
||||
output: "unique_rev_idx"
|
||||
output: "unique_counts"
|
||||
op_type: "Unique"
|
||||
attribute {
|
||||
name: "sorted"
|
||||
i: 0
|
||||
type: INT
|
||||
}
|
||||
attribute {
|
||||
name: "axis"
|
||||
i: 2
|
||||
type: INT
|
||||
}
|
||||
}
|
||||
input {
|
||||
name: "data"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 6
|
||||
shape {
|
||||
dim {
|
||||
dim_value: 2
|
||||
}
|
||||
dim {
|
||||
dim_value: 2
|
||||
}
|
||||
dim {
|
||||
dim_value: 3
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 6
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique_idx"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 7
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique_rev_idx"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 7
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "unique_counts"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 7
|
||||
shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
opset_import {
|
||||
domain: ""
|
||||
version: 13
|
||||
}
|
||||
@@ -6267,3 +6267,85 @@ NGRAPH_TEST(${BACKEND_NAME}, DISABLED_castlike_bfloat16_to_float32) {
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, onnx_model_unique_3d_default_attributes) {
|
||||
auto function = onnx_import::import_onnx_model(file_util::path_join(CommonTestUtils::getExecutableDirectory(),
|
||||
SERIALIZED_ZOO,
|
||||
"onnx/unique_3d_default_attributes.onnx"));
|
||||
|
||||
auto test_case = test::TestCase(function, s_device);
|
||||
|
||||
test_case.add_input<int32_t>({9, 12, 3, 121, 5, 4, 10, 9});
|
||||
test_case.add_expected_output<int32_t>(Shape{7}, {3, 4, 5, 9, 10, 12, 121});
|
||||
test_case.add_expected_output<int64_t>(Shape{7}, {2, 5, 4, 0, 6, 1, 3});
|
||||
test_case.add_expected_output<int64_t>(Shape{8}, {3, 5, 0, 6, 2, 1, 4, 3});
|
||||
test_case.add_expected_output<int64_t>(Shape{7}, {1, 1, 1, 2, 1, 1, 1});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, onnx_model_unique_1d_no_duplicates) {
|
||||
auto function = onnx_import::import_onnx_model(file_util::path_join(CommonTestUtils::getExecutableDirectory(),
|
||||
SERIALIZED_ZOO,
|
||||
"onnx/unique_1d_no_duplicates.onnx"));
|
||||
|
||||
auto test_case = test::TestCase(function, s_device);
|
||||
|
||||
test_case.add_input<int32_t>({5, 4, 3, 2, 1});
|
||||
test_case.add_expected_output<int32_t>(Shape{5}, {5, 4, 3, 2, 1});
|
||||
test_case.add_expected_output<int64_t>(Shape{5}, {0, 1, 2, 3, 4});
|
||||
test_case.add_expected_output<int64_t>(Shape{5}, {0, 1, 2, 3, 4});
|
||||
test_case.add_expected_output<int64_t>(Shape{5}, {1, 1, 1, 1, 1});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, onnx_model_unique_1d_no_duplicates_sorted) {
|
||||
auto function = onnx_import::import_onnx_model(file_util::path_join(CommonTestUtils::getExecutableDirectory(),
|
||||
SERIALIZED_ZOO,
|
||||
"onnx/unique_1d_no_duplicates_sorted.onnx"));
|
||||
|
||||
auto test_case = test::TestCase(function, s_device);
|
||||
|
||||
test_case.add_input<int32_t>({5, 4, 3, 2, 1});
|
||||
test_case.add_expected_output<int32_t>(Shape{5}, {1, 2, 3, 4, 5});
|
||||
test_case.add_expected_output<int64_t>(Shape{5}, {4, 3, 2, 1, 0});
|
||||
test_case.add_expected_output<int64_t>(Shape{5}, {4, 3, 2, 1, 0});
|
||||
test_case.add_expected_output<int64_t>(Shape{5}, {1, 1, 1, 1, 1});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, onnx_model_unique_3d_with_duplicates_and_axis) {
|
||||
auto function =
|
||||
onnx_import::import_onnx_model(file_util::path_join(CommonTestUtils::getExecutableDirectory(),
|
||||
SERIALIZED_ZOO,
|
||||
"onnx/unique_3d_with_duplicates_and_axis.onnx"));
|
||||
|
||||
auto test_case = test::TestCase(function, s_device);
|
||||
|
||||
test_case.add_input<int32_t>({1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6});
|
||||
test_case.add_expected_output<int32_t>(Shape{1, 2, 3}, {1, 2, 3, 4, 5, 6});
|
||||
test_case.add_expected_output<int64_t>(Shape{1}, {0});
|
||||
test_case.add_expected_output<int64_t>(Shape{2}, {0, 0});
|
||||
test_case.add_expected_output<int64_t>(Shape{1}, {2});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, onnx_model_unique_3d_with_duplicates_and_axis_2) {
|
||||
auto function =
|
||||
onnx_import::import_onnx_model(file_util::path_join(CommonTestUtils::getExecutableDirectory(),
|
||||
SERIALIZED_ZOO,
|
||||
"onnx/unique_3d_with_duplicates_and_axis_2.onnx"));
|
||||
|
||||
auto test_case = test::TestCase(function, s_device);
|
||||
|
||||
test_case.add_input<int32_t>({-1, 2, -1, 5, -3, 5, 7, -8, 7, 4, 4, 4});
|
||||
test_case.add_expected_output<int32_t>(Shape{2, 2, 2}, {-1, 2, 5, -3, 7, -8, 4, 4});
|
||||
test_case.add_expected_output<int64_t>(Shape{2}, {0, 1});
|
||||
test_case.add_expected_output<int64_t>(Shape{3}, {0, 1, 0});
|
||||
test_case.add_expected_output<int64_t>(Shape{2}, {2, 1});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
Reference in new issue
Block a user