From 76e3f96b5cdca3003bb585d56bc8b0e96194bc2e Mon Sep 17 00:00:00 2001 From: siddhant-0707 Date: Thu, 9 Nov 2023 21:03:17 +0530 Subject: [PATCH] ONNX greater_or_equal enabled --- .../onnx/frontend/src/op/greater_or_equal.cpp | 42 ++++++++++++++ .../onnx/frontend/src/op/greater_or_equal.hpp | 28 +++++++++ .../onnx/frontend/src/ops_bridge.cpp | 3 + .../models/greater_or_equal_float.prototxt | 53 +++++++++++++++++ .../models/greater_or_equal_int.prototxt | 53 +++++++++++++++++ src/frontends/onnx/tests/onnx_import.in.cpp | 58 +++++++++++++++++++ 6 files changed, 237 insertions(+) create mode 100644 src/frontends/onnx/frontend/src/op/greater_or_equal.cpp create mode 100644 src/frontends/onnx/frontend/src/op/greater_or_equal.hpp create mode 100644 src/frontends/onnx/tests/models/greater_or_equal_float.prototxt create mode 100644 src/frontends/onnx/tests/models/greater_or_equal_int.prototxt diff --git a/src/frontends/onnx/frontend/src/op/greater_or_equal.cpp b/src/frontends/onnx/frontend/src/op/greater_or_equal.cpp new file mode 100644 index 00000000000000..1c62a09aaef21e --- /dev/null +++ b/src/frontends/onnx/frontend/src/op/greater_or_equal.cpp @@ -0,0 +1,42 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "op/greater_or_equal.hpp" + +#include + +#include "default_opset.hpp" +#include "utils/common.hpp" +#define _USE_MATH_DEFINES +#include + +OPENVINO_SUPPRESS_DEPRECATED_START +namespace ngraph { +namespace onnx_import { +namespace op { +namespace set_1 { +OutputVector greater_or_equal(const Node& node) { + const auto A = node.get_ng_inputs().at(0); + const auto B = node.get_ng_inputs().at(1); + + const auto C = std::make_shared(A, B); + + return {C}; +} +} // namespace set_1 + +namespace set_12 { +OutputVector greater_or_equal(const Node& node) { + const auto A = node.get_ng_inputs().at(0); + const auto B = node.get_ng_inputs().at(1); + + const auto C = std::make_shared(A, B); + + return {C}; +} +} // namespace set_12 +} // namespace op +} // namespace onnx_import +} // namespace ngraph +OPENVINO_SUPPRESS_DEPRECATED_END diff --git a/src/frontends/onnx/frontend/src/op/greater_or_equal.hpp b/src/frontends/onnx/frontend/src/op/greater_or_equal.hpp new file mode 100644 index 00000000000000..29b97c0aec85e7 --- /dev/null +++ b/src/frontends/onnx/frontend/src/op/greater_or_equal.hpp @@ -0,0 +1,28 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/core/deprecated.hpp" +OPENVINO_SUPPRESS_DEPRECATED_START + +#include "ngraph/node.hpp" +#include "onnx_import/core/node.hpp" + +namespace ngraph { +namespace onnx_import { +namespace op { +namespace set_1 { +OutputVector greater_or_equal(const Node& node); + +} // namespace set_1 + +namespace set_12 { +OutputVector greater_or_equal(const Node& node); + +} // namespace set_12 +} // namespace op +} // namespace onnx_import +} // namespace ngraph +OPENVINO_SUPPRESS_DEPRECATED_END diff --git a/src/frontends/onnx/frontend/src/ops_bridge.cpp b/src/frontends/onnx/frontend/src/ops_bridge.cpp index 31ca0b20836de5..d9eabc92b38775 100644 --- a/src/frontends/onnx/frontend/src/ops_bridge.cpp +++ b/src/frontends/onnx/frontend/src/ops_bridge.cpp @@ -74,6 +74,7 @@ #include "op/global_average_pool.hpp" #include "op/global_max_pool.hpp" #include "op/greater.hpp" +#include "op/greater_or_equal.hpp" #include "op/grid_sample.hpp" #include "op/group_normalization.hpp" #include "op/gru.hpp" @@ -395,6 +396,8 @@ OperatorsBridge::OperatorsBridge() { REGISTER_OPERATOR("GlobalLpPool", 1, global_lp_pool); REGISTER_OPERATOR("GlobalMaxPool", 1, global_max_pool); REGISTER_OPERATOR("Greater", 1, greater); + REGISTER_OPERATOR("Greater_Or_Equal", 1, greater_or_equal); + REGISTER_OPERATOR("Greater_Or_Equal", 12, greater_or_equal); REGISTER_OPERATOR("GridSample", 1, grid_sample); REGISTER_OPERATOR("GroupNormalization", 1, group_normalization); REGISTER_OPERATOR("GRU", 1, gru); diff --git a/src/frontends/onnx/tests/models/greater_or_equal_float.prototxt b/src/frontends/onnx/tests/models/greater_or_equal_float.prototxt new file mode 100644 index 00000000000000..d068b3f95bb18d --- /dev/null +++ b/src/frontends/onnx/tests/models/greater_or_equal_float.prototxt @@ -0,0 +1,53 @@ +ir_version: 7 +producer_name: "nGraph ONNX Importer" +graph { + node { + input: "A" + input: "B" + output: "C" + op_type: "Greater_Or_Equal" + } + name: "test_greater_or_equal_float" + input { + name: "A" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + } + } + } + } + input { + name: "B" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + } + } + } + } + output { + name: "C" + type { + tensor_type { + elem_type: 2 + shape { + dim { + dim_value: 2 + } + } + } + } + } +} +opset_import { + version: 16 +} diff --git a/src/frontends/onnx/tests/models/greater_or_equal_int.prototxt b/src/frontends/onnx/tests/models/greater_or_equal_int.prototxt new file mode 100644 index 00000000000000..c2dc0c55c9aa02 --- /dev/null +++ b/src/frontends/onnx/tests/models/greater_or_equal_int.prototxt @@ -0,0 +1,53 @@ +ir_version: 7 +producer_name: "nGraph ONNX Importer" +graph { + node { + input: "A" + input: "B" + output: "C" + op_type: "Greater_Or_Equal" + } + name: "test_greater_or_equal_int" + input { + name: "A" + type { + tensor_type { + elem_type: 7 + shape { + dim { + dim_value: 2 + } + } + } + } + } + input { + name: "B" + type { + tensor_type { + elem_type: 7 + shape { + dim { + dim_value: 2 + } + } + } + } + } + output { + name: "C" + type { + tensor_type { + elem_type: 2 + shape { + dim { + dim_value: 2 + } + } + } + } + } +} +opset_import { + version: 16 +} diff --git a/src/frontends/onnx/tests/onnx_import.in.cpp b/src/frontends/onnx/tests/onnx_import.in.cpp index 45e7bbf81eff28..58099e88a58d35 100644 --- a/src/frontends/onnx/tests/onnx_import.in.cpp +++ b/src/frontends/onnx/tests/onnx_import.in.cpp @@ -6976,3 +6976,61 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_mm_nms_rotated) { test_case.run(); } + +OPENVINO_TEST(${BACKEND_NAME}, onnx_model_greater_or_equal_float) { + auto function = onnx_import::import_onnx_model(file_util::path_join(ov::test::utils::getExecutableDirectory(), + SERIALIZED_ZOO, + "onnx/greater_or_equal_float.onnx")); + + auto test_case = ov::test::TestCase(function, s_device); + + test_case.add_input({10}); + test_case.add_expected_output(Shape{10}, + {-0.000000014901161f, + 0.040212844f, + 0.20077012f, + 0.50978714f, + 0.8492299f, + 0.99999994f, + 0.84922975f, + 0.5097869f, + 0.20077008f, + 0.040212862f}); + + // GPU has an accuracy drop, need to use different tolerance + if (std::string("${BACKEND_NAME}") != std::string("IE_GPU")) { + test_case.run_with_tolerance_as_fp(); + } else { + test_case.run_with_tolerance_as_fp(0.01f); + } +} + +OPENVINO_TEST(${BACKEND_NAME}, onnx_model_greater_or_equal_int) { + auto function = onnx_import::import_onnx_model( + file_util::path_join(ov::test::utils::getExecutableDirectory(), + SERIALIZED_ZOO, + "onnx/greater_or_equal_int.onnx")); + + auto test_case = ov::test::TestCase(function, s_device); + + test_case.add_input(Shape{2}, {10, 20}); + test_case.add_input(Shape{2}, {15, 15}); + test_case.add_expected_output(Shape{2}, {false, true}); + + test_case.run(); +} + +OPENVINO_TEST(${BACKEND_NAME}, onnx_model_greater_or_equal_float) { + auto function = onnx_import::import_onnx_model( + file_util::path_join(ov::test::utils::getExecutableDirectory(), + SERIALIZED_ZOO, + "onnx/greater_or_equal_float.onnx")); + + auto test_case = ov::test::TestCase(function, s_device); + + test_case.add_input(Shape{2}, {12.03513f, 22.03513f}); + test_case.add_input(Shape{2}, {5.84916f, 22.03513f}); + test_case.add_expected_output(Shape{2}, {true, true}); + + test_case.run(); +}