Skip to content

Commit

Permalink
Adding ( [ONNX] Extend ONNX Frontend with Function Mish-18 ) (#22833)
Browse files Browse the repository at this point in the history
### Details:
- *Expand the ONNX Frontend Capabilities by Incorporating the Mish-18
Function*

### Tickets:
 - *Closes #20550*
  • Loading branch information
PRATHAM-SPS authored Feb 19, 2024
1 parent 78f2529 commit dbc9111
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 6 deletions.
25 changes: 25 additions & 0 deletions src/frontends/onnx/frontend/src/op/mish.cpp
Original file line number Diff line number Diff line change
@@ -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<v4::Mish>(data)};
}
} // namespace set_1
} // namespace op
} // namespace onnx
} // namespace frontend
} // namespace ov
19 changes: 19 additions & 0 deletions src/frontends/onnx/frontend/src/op/mish.hpp
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/frontends/onnx/frontend/src/ops_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/frontends/onnx/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<Node(Reshape): Mean>'")
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")
Expand Down
50 changes: 50 additions & 0 deletions src/frontends/onnx/tests/models/mish.prototxt
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 16 additions & 0 deletions src/frontends/onnx/tests/onnx_import.in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6245,3 +6245,19 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gelu_float_tanh) {
test_case.add_input<float>(Shape{2}, {-0.5f, 24.33f});
test_case.add_expected_output<float>(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<float>({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<float>({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);
}
5 changes: 0 additions & 5 deletions src/frontends/onnx/tests/tests_python/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit dbc9111

Please sign in to comment.