diff --git a/src/core/tests/models/onnx/unsqueeze_ai_onnx_domain.prototxt b/src/core/tests/models/onnx/unsqueeze_ai_onnx_domain.prototxt new file mode 100644 index 00000000000..b8693e7f30e --- /dev/null +++ b/src/core/tests/models/onnx/unsqueeze_ai_onnx_domain.prototxt @@ -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" +} diff --git a/src/core/tests/models/onnx/unsqueeze_ai_onnx_domain_opset13.prototxt b/src/core/tests/models/onnx/unsqueeze_ai_onnx_domain_opset13.prototxt new file mode 100644 index 00000000000..44cc45907ad --- /dev/null +++ b/src/core/tests/models/onnx/unsqueeze_ai_onnx_domain_opset13.prototxt @@ -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 +} + diff --git a/src/core/tests/models/onnx/unsqueeze_default_domain.prototxt b/src/core/tests/models/onnx/unsqueeze_default_domain.prototxt new file mode 100644 index 00000000000..448c2056247 --- /dev/null +++ b/src/core/tests/models/onnx/unsqueeze_default_domain.prototxt @@ -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 +} diff --git a/src/core/tests/models/onnx/unsqueeze_default_domain_opset13.prototxt b/src/core/tests/models/onnx/unsqueeze_default_domain_opset13.prototxt new file mode 100644 index 00000000000..461fcd13f14 --- /dev/null +++ b/src/core/tests/models/onnx/unsqueeze_default_domain_opset13.prototxt @@ -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 +} + diff --git a/src/core/tests/onnx/onnx_import.in.cpp b/src/core/tests/onnx/onnx_import.in.cpp index 6367eea0636..fd5f04c36d7 100644 --- a/src/core/tests/onnx/onnx_import.in.cpp +++ b/src/core/tests/onnx/onnx_import.in.cpp @@ -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({{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}, + {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 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({{{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}, + {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 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({{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}, + {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 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({{{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}, + {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 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({{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}, + {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 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({{{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}, + {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 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({{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}, + {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 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({{{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}, + {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 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(); +} diff --git a/src/frontends/onnx/frontend/src/core/model.cpp b/src/frontends/onnx/frontend/src/core/model.cpp index 23342a2733d..ba6e3d8a8f3 100644 --- a/src/frontends/onnx/frontend/src/core/model.cpp +++ b/src/frontends/onnx/frontend/src/core/model.cpp @@ -32,6 +32,9 @@ Model::Model(std::shared_ptr 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