Skip to content

Commit

Permalink
[Model Enablement] fix default onnx domain (openvinotoolkit#10106)
Browse files Browse the repository at this point in the history
  • Loading branch information
bszmelcz authored Feb 10, 2022
1 parent 87c6e09 commit 36de4e8
Show file tree
Hide file tree
Showing 6 changed files with 372 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/core/tests/models/onnx/unsqueeze_ai_onnx_domain.prototxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
ir_version: 3
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "X"
output: "Y"
op_type: "Unsqueeze"
attribute {
name: "axes"
ints: 0
type: INTS
}
}
name: "test-model-unsqueeze"
input {
name: "X"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
output {
name: "Y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
}
opset_import {
version: 7
domain: "ai.onnx"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
ir_version: 8
producer_name: "onnx-importer-test"
graph {
node {
output: "AXIS"
op_type: "Constant"
attribute {
name: "value"
t {
dims: 1
data_type: 6
int32_data: 0
name: "const_tensor"
}
type: TENSOR
}
}
node {
input: "X"
input: "AXIS"
output: "Y"
op_type: "Unsqueeze"
}
name: "test-model-unsqueeze"
input {
name: "X"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
input {
name: "AXIS"
type {
tensor_type {
elem_type: 6
shape {
dim {
dim_value: 1
}
}
}
}
}
output {
name: "Y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
}
opset_import {
domain: "ai.onnx"
version: 13
}

59 changes: 59 additions & 0 deletions src/core/tests/models/onnx/unsqueeze_default_domain.prototxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
ir_version: 3
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "X"
output: "Y"
op_type: "Unsqueeze"
attribute {
name: "axes"
ints: 0
type: INTS
}
}
name: "test-model-unsqueeze"
input {
name: "X"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
output {
name: "Y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
}
opset_import {
version: 7
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
ir_version: 8
producer_name: "onnx-importer-test"
graph {
node {
output: "AXIS"
op_type: "Constant"
attribute {
name: "value"
t {
dims: 1
data_type: 6
int32_data: 0
name: "const_tensor"
}
type: TENSOR
}
}
node {
input: "X"
input: "AXIS"
output: "Y"
op_type: "Unsqueeze"
}
name: "test-model-unsqueeze"
input {
name: "X"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
input {
name: "AXIS"
type {
tensor_type {
elem_type: 6
shape {
dim {
dim_value: 1
}
}
}
}
}
output {
name: "Y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
}
opset_import {
domain: ""
version: 13
}

82 changes: 82 additions & 0 deletions src/core/tests/onnx/onnx_import.in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4654,3 +4654,85 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_aten_unsupported_operator) {
FAIL() << "Other exception than expected was thrown.";
}
}

NGRAPH_TEST(${BACKEND_NAME}, onnx_model_unsqueeze_ai_onnx_domain) {
auto function =
onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/unsqueeze_ai_onnx_domain.onnx"));

auto input = test::NDArray<float, 3>({{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}})
.get_vector();

auto expected_output =
test::NDArray<float, 4>({{{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}}})
.get_vector();

auto test_case = test::TestCase(function, s_device);
test_case.add_input(input);
test_case.add_expected_output(expected_output);
test_case.run();
}

NGRAPH_TEST(${BACKEND_NAME}, onnx_model_unsqueeze_default_domain) {
auto function =
onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/unsqueeze_default_domain.onnx"));

auto input = test::NDArray<float, 3>({{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}})
.get_vector();

auto expected_output =
test::NDArray<float, 4>({{{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}}})
.get_vector();

auto test_case = test::TestCase(function, s_device);
test_case.add_input(input);
test_case.add_expected_output(expected_output);
test_case.run();
}

NGRAPH_TEST(${BACKEND_NAME}, onnx_model_unsqueeze_default_domain_opset13) {
auto function = onnx_import::import_onnx_model(
file_util::path_join(SERIALIZED_ZOO, "onnx/unsqueeze_default_domain_opset13.onnx"));

auto input = test::NDArray<float, 3>({{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}})
.get_vector();
auto expected_output =
test::NDArray<float, 4>({{{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}}})
.get_vector();

auto test_case = test::TestCase(function, s_device);
test_case.add_input(input);
test_case.add_expected_output(expected_output);
test_case.run();
}

NGRAPH_TEST(${BACKEND_NAME}, onnx_model_unsqueeze_ai_onnx_domain_opset13) {
auto function = onnx_import::import_onnx_model(
file_util::path_join(SERIALIZED_ZOO, "onnx/unsqueeze_ai_onnx_domain_opset13.onnx"));

auto input = test::NDArray<float, 3>({{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}})
.get_vector();
auto expected_output =
test::NDArray<float, 4>({{{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}}})
.get_vector();

auto test_case = test::TestCase(function, s_device);
test_case.add_input(input);
test_case.add_expected_output(expected_output);
test_case.run();
}
3 changes: 3 additions & 0 deletions src/frontends/onnx/frontend/src/core/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Model::Model(std::shared_ptr<ONNX_NAMESPACE::ModelProto> model_proto) : m_model_
// unknown or invalid.
for (const auto& id : m_model_proto->opset_import()) {
auto domain = id.has_domain() ? id.domain() : "";
if (domain == "ai.onnx") {
domain = "";
}
m_opset.emplace(domain, OperatorsBridge::get_operator_set(domain, id.version()));
}
// onnx.proto(.3): the empty string ("") for domain or absence of opset_import field
Expand Down

0 comments on commit 36de4e8

Please sign in to comment.