From dbc911129a86dc9321ef5b2bb9feea43e81ddd41 Mon Sep 17 00:00:00 2001 From: Pratham Ingawale <94799826+PRATHAM-SPS@users.noreply.github.com> Date: Mon, 19 Feb 2024 17:34:05 +0530 Subject: [PATCH] Adding ( [ONNX] Extend ONNX Frontend with Function Mish-18 ) (#22833) ### Details: - *Expand the ONNX Frontend Capabilities by Incorporating the Mish-18 Function* ### Tickets: - *Closes #20550* --- src/frontends/onnx/frontend/src/op/mish.cpp | 25 ++++++++++ src/frontends/onnx/frontend/src/op/mish.hpp | 19 +++++++ .../onnx/frontend/src/ops_bridge.cpp | 2 + src/frontends/onnx/tests/__init__.py | 1 - src/frontends/onnx/tests/models/mish.prototxt | 50 +++++++++++++++++++ src/frontends/onnx/tests/onnx_import.in.cpp | 16 ++++++ .../onnx/tests/tests_python/test_backend.py | 5 -- 7 files changed, 112 insertions(+), 6 deletions(-) create mode 100644 src/frontends/onnx/frontend/src/op/mish.cpp create mode 100644 src/frontends/onnx/frontend/src/op/mish.hpp create mode 100644 src/frontends/onnx/tests/models/mish.prototxt diff --git a/src/frontends/onnx/frontend/src/op/mish.cpp b/src/frontends/onnx/frontend/src/op/mish.cpp new file mode 100644 index 00000000000000..f563415c101c7d --- /dev/null +++ b/src/frontends/onnx/frontend/src/op/mish.cpp @@ -0,0 +1,25 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "op/mish.hpp" + +#include "openvino/op/mish.hpp" + +using namespace ov::op; + +namespace ov { +namespace frontend { +namespace onnx { +namespace op { +namespace set_1 { +ov::OutputVector mish(const ov::frontend::onnx::Node& node) { + const auto data = node.get_ov_inputs().at(0); + + return {std::make_shared(data)}; +} +} // namespace set_1 +} // namespace op +} // namespace onnx +} // namespace frontend +} // namespace ov diff --git a/src/frontends/onnx/frontend/src/op/mish.hpp b/src/frontends/onnx/frontend/src/op/mish.hpp new file mode 100644 index 00000000000000..c37550a80af46b --- /dev/null +++ b/src/frontends/onnx/frontend/src/op/mish.hpp @@ -0,0 +1,19 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "core/node.hpp" + +namespace ov { +namespace frontend { +namespace onnx { +namespace op { +namespace set_1 { +ov::OutputVector mish(const ov::frontend::onnx::Node& node); +} // namespace set_1 +} // namespace op +} // namespace onnx +} // namespace frontend +} // namespace ov diff --git a/src/frontends/onnx/frontend/src/ops_bridge.cpp b/src/frontends/onnx/frontend/src/ops_bridge.cpp index 334eae33837371..f6d2bbbc03bf28 100644 --- a/src/frontends/onnx/frontend/src/ops_bridge.cpp +++ b/src/frontends/onnx/frontend/src/ops_bridge.cpp @@ -113,6 +113,7 @@ #include "op/mean.hpp" #include "op/mean_variance_normalization.hpp" #include "op/min.hpp" +#include "op/mish.hpp" #include "op/mod.hpp" #include "op/mul.hpp" #include "op/neg.hpp" @@ -452,6 +453,7 @@ OperatorsBridge::OperatorsBridge() { REGISTER_OPERATOR("MeanVarianceNormalization", 9, mean_variance_normalization); REGISTER_OPERATOR("Min", 1, min); REGISTER_OPERATOR("Min", 8, min); + REGISTER_OPERATOR("Mish", 1, mish); REGISTER_OPERATOR("Mod", 1, mod); REGISTER_OPERATOR("Mul", 1, mul); REGISTER_OPERATOR("Mul", 7, mul); diff --git a/src/frontends/onnx/tests/__init__.py b/src/frontends/onnx/tests/__init__.py index f2843e89ce33b2..01a7cec223436f 100644 --- a/src/frontends/onnx/tests/__init__.py +++ b/src/frontends/onnx/tests/__init__.py @@ -60,7 +60,6 @@ def xfail_test(reason="Mark the test as expected to fail", strict=True): xfail_issue_99955 = xfail_test(reason="GroupNorm is not supported") xfail_issue_99957 = xfail_test(reason="LayerNorm - RuntimeError: While validating node ''") xfail_issue_99958 = xfail_test(reason="LogSoftmax - Results mismatch") -xfail_issue_99959 = xfail_test(reason="Mish function is not supported") xfail_issue_99960 = xfail_test(reason="MVN - Results mismatch") xfail_issue_99961 = xfail_test(reason="Optional has/get element operators are not supported)'") xfail_issue_99962 = pytest.mark.skip(reason="ReduceL1/L2 - Unrecognized attribute: axes for operator ReduceL1/L2") diff --git a/src/frontends/onnx/tests/models/mish.prototxt b/src/frontends/onnx/tests/models/mish.prototxt new file mode 100644 index 00000000000000..a0b28b0654cc6a --- /dev/null +++ b/src/frontends/onnx/tests/models/mish.prototxt @@ -0,0 +1,50 @@ +ir_version: 7 +graph { + node { + input: "x" + output: "y" + op_type: "Mish" + } + name: "test_mish" + input { + name: "x" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 3 + } + dim { + dim_value: 4 + } + } + } + } + } + output { + name: "y" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 3 + } + dim { + dim_value: 4 + } + } + } + } + } +} +opset_import { + version: 1 +} diff --git a/src/frontends/onnx/tests/onnx_import.in.cpp b/src/frontends/onnx/tests/onnx_import.in.cpp index 3df40f8ecc38d5..f9f69583ccb696 100644 --- a/src/frontends/onnx/tests/onnx_import.in.cpp +++ b/src/frontends/onnx/tests/onnx_import.in.cpp @@ -6245,3 +6245,19 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gelu_float_tanh) { test_case.add_input(Shape{2}, {-0.5f, 24.33f}); test_case.add_expected_output(Shape{2}, {-0.15428598f, 24.f}); } + +OPENVINO_TEST(${BACKEND_NAME}, onnx_model_mish_activation) { + auto model = convert_model("mish.onnx"); + + auto test_case = ov::test::TestCase(model, s_device); + test_case.add_input({1.8079f, -0.2892f, 2.0915f, 12.5101f, -1.8837f, 0.2586f, 2.9528f, 0.001f, + 6.0296f, -1.0745f, -0.2703f, 1.319f, -3.3607f, 0.1434f, -8.4590f, 0.0f, + 2.7608f, 0.3126f, 0.3f, 3.0f, 7.6919f, 0.5859f, -11.992f, -37.8f}); + + test_case.add_expected_output({1.737521f, -0.146684f, 2.041557f, 12.5101f, -0.264820f, 0.176079f, + 2.938304f, 0.0006f, 6.029531f, -0.306873f, -0.138725f, 1.206575f, + -0.114629f, 0.092553f, -0.001792f, 0.0f, 2.741334f, 0.217909f, + 0.208001f, 2.986535f, 7.691896f, 0.453058f, -0.000074f, 0.0f}); + + test_case.run_with_tolerance_as_fp(0.000001f); +} diff --git a/src/frontends/onnx/tests/tests_python/test_backend.py b/src/frontends/onnx/tests/tests_python/test_backend.py index 3f59e94c3f3bd1..181c8c638684a6 100644 --- a/src/frontends/onnx/tests/tests_python/test_backend.py +++ b/src/frontends/onnx/tests/tests_python/test_backend.py @@ -53,7 +53,6 @@ xfail_issue_99955, xfail_issue_99957, xfail_issue_99958, - xfail_issue_99959, xfail_issue_99960, xfail_issue_99961, xfail_issue_99968, @@ -465,10 +464,6 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None xfail_issue_99958, "OnnxBackendNodeModelTest.test_logsoftmax_large_number_expanded_ver18_cpu", ), - ( - xfail_issue_99959, - "OnnxBackendNodeModelTest.test_mish_cpu", - ), ( xfail_issue_99960, "OnnxBackendNodeModelTest.test_mvn_expanded_ver18_cpu",