Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 69 additions & 1 deletion src/frontends/onnx/frontend/src/op/relu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,87 @@
#include "openvino/op/relu.hpp"

#include "core/operator_set.hpp"
#include "exceptions.hpp"
#include "openvino/frontend/exception.hpp"
#include "utils/common.hpp"

namespace ov {
namespace frontend {
namespace onnx {
namespace ai_onnx {
namespace opset_1 {
ov::OutputVector relu(const ov::frontend::onnx::Node& node) {
CHECK_VALID_NODE(node,
!node.has_attribute("consumed_inputs"),
"consumed_inputs legacy attribute of Relu op is not supported");

const auto A = node.get_ov_inputs().at(0);
std::vector<ov::element::Type> unsupported_types = {ov::element::bf16,
ov::element::i8,
ov::element::i16,
ov::element::i32,
ov::element::i64};
for (size_t i = 0; i < unsupported_types.size(); ++i) {
FRONT_END_GENERAL_CHECK(
A.get_element_type() != unsupported_types[i],
"The input data types bf16, int8, int16, int32, and int64 are not supported in opset 1");
}

ov::OutputVector ov_inputs{node.get_ov_inputs()};
return {std::make_shared<ov::op::v0::Relu>(ov_inputs.at(0))};
}

ONNX_OP("Relu", OPSET_SINCE(1), ai_onnx::opset_1::relu);
ONNX_OP("Relu", OPSET_RANGE(1, 5), ai_onnx::opset_1::relu);
} // namespace opset_1

namespace opset_6 {
ov::OutputVector relu(const ov::frontend::onnx::Node& node) {
const auto A = node.get_ov_inputs().at(0);
std::vector<ov::element::Type> unsupported_types = {ov::element::bf16,
ov::element::i8,
ov::element::i16,
ov::element::i32,
ov::element::i64};
for (size_t i = 0; i < unsupported_types.size(); ++i) {
FRONT_END_GENERAL_CHECK(
A.get_element_type() != unsupported_types[i],
"The input data types bf16, int8, int16, int32, and int64 are not supported in opset 6");
}

ov::OutputVector ov_inputs{node.get_ov_inputs()};
return {std::make_shared<ov::op::v0::Relu>(ov_inputs.at(0))};
}

ONNX_OP("Relu", OPSET_RANGE(6, 12), ai_onnx::opset_6::relu);
} // namespace opset_6

namespace opset_13 {
ov::OutputVector relu(const ov::frontend::onnx::Node& node) {
const auto A = node.get_ov_inputs().at(0);
std::vector<ov::element::Type> unsupported_types = {ov::element::i8,
ov::element::i16,
ov::element::i32,
ov::element::i64};
for (size_t i = 0; i < unsupported_types.size(); ++i) {
FRONT_END_GENERAL_CHECK(A.get_element_type() != unsupported_types[i],
"The input data types int8, int16, int32, and int64 are not supported in opset 13");
}

ov::OutputVector ov_inputs{node.get_ov_inputs()};
return {std::make_shared<ov::op::v0::Relu>(ov_inputs.at(0))};
}

ONNX_OP("Relu", OPSET_RANGE(13, 13), ai_onnx::opset_13::relu);
} // namespace opset_13

namespace opset_14 {
ov::OutputVector relu(const ov::frontend::onnx::Node& node) {
ov::OutputVector ov_inputs{node.get_ov_inputs()};
return {std::make_shared<ov::op::v0::Relu>(ov_inputs.at(0))};
}

ONNX_OP("Relu", OPSET_SINCE(14), ai_onnx::opset_14::relu);
} // namespace opset_14
} // namespace ai_onnx
} // namespace onnx
} // namespace frontend
Expand Down
2 changes: 1 addition & 1 deletion src/frontends/onnx/tests/library_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static FrontendLibraryExtensionTestParams getTestData() {
FrontendLibraryExtensionTestParams params;
params.m_frontEndName = ONNX_FE;
params.m_modelsPath = std::string(TEST_ONNX_MODELS_DIRNAME);
params.m_modelName = "relu.onnx";
params.m_modelName = "relu_default.onnx";
return params;
}

Expand Down
39 changes: 39 additions & 0 deletions src/frontends/onnx/tests/models/relu_opset1.prototxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ir_version: 3
producer_name: "OpenVINO ONNX Frontend"
graph {
node {
input: "x"
output: "y"
op_type: "Relu"
}
name: "test_relu"
input {
name: "x"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 6
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 6
}
}
}
}
}
}
opset_import {
version: 1
}
39 changes: 39 additions & 0 deletions src/frontends/onnx/tests/models/relu_opset13.prototxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ir_version: 3
producer_name: "OpenVINO ONNX Frontend"
graph {
node {
input: "x"
output: "y"
op_type: "Relu"
}
name: "test_relu"
input {
name: "x"
type {
tensor_type {
elem_type: 10
shape {
dim {
dim_value: 6
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 10
shape {
dim {
dim_value: 6
}
}
}
}
}
}
opset_import {
version: 13
}
39 changes: 39 additions & 0 deletions src/frontends/onnx/tests/models/relu_opset14.prototxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ir_version: 3
producer_name: "OpenVINO ONNX Frontend"
graph {
node {
input: "x"
output: "y"
op_type: "Relu"
}
name: "test_relu"
input {
name: "x"
type {
tensor_type {
elem_type: 5
shape {
dim {
dim_value: 6
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 5
shape {
dim {
dim_value: 6
}
}
}
}
}
}
opset_import {
version: 14
}
39 changes: 39 additions & 0 deletions src/frontends/onnx/tests/models/relu_opset6.prototxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ir_version: 3
producer_name: "OpenVINO ONNX Frontend"
graph {
node {
input: "x"
output: "y"
op_type: "Relu"
}
name: "test_relu"
input {
name: "x"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 6
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 6
}
}
}
}
}
}
opset_import {
version: 6
}
53 changes: 47 additions & 6 deletions src/frontends/onnx/tests/onnx_import.in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,16 +445,56 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_batch_norm_opset15) {
test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_model_relu) {
OPENVINO_TEST(${BACKEND_NAME}, onnx_model_relu_default) {
// Simple ReLU test
auto model = convert_model("relu.onnx");
auto model = convert_model("relu_default.onnx");

auto test_case = ov::test::TestCase(model, s_device);
test_case.add_input<float>({-1, -2, 0, 1, 2, 3});
test_case.add_expected_output<float>({0, 0, 0, 1, 2, 3});
test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_model_relu_opset1) {
// Simple ReLU test
auto model = convert_model("relu_opset1.onnx");

auto test_case = ov::test::TestCase(model, s_device);
test_case.add_input<float>({-1, -2, 0, 1, 2, 3});
test_case.add_expected_output<float>({0, 0, 0, 1, 2, 3});
test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_model_relu_opset6) {
// Simple ReLU test
auto model = convert_model("relu_opset6.onnx");

auto test_case = ov::test::TestCase(model, s_device);
test_case.add_input<float>({-1, -2, 0, 1, 2, 3});
test_case.add_expected_output<float>({0, 0, 0, 1, 2, 3});
test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_model_relu_opset13) {
// Simple ReLU test
auto model = convert_model("relu_opset13.onnx");

auto test_case = ov::test::TestCase(model, s_device);
test_case.add_input<bfloat16>({-1.3f, -2, 0, 1, 2, 3});
test_case.add_expected_output<bfloat16>({0, 0, 0, 1, 2, 3});
test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_model_relu_opset14) {
// Simple ReLU test
auto model = convert_model("relu_opset14.onnx");

auto test_case = ov::test::TestCase(model, s_device);
test_case.add_input<int16_t>({-1, -2, 0, 1, 2, 3});
test_case.add_expected_output<int16_t>({0, 0, 0, 1, 2, 3});
test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_model_sum_opset1) {
// Simple Sum test for opset1.
auto model = convert_model("sum_opset1.onnx");
Expand Down Expand Up @@ -3018,10 +3058,11 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_erf) {
const auto model = convert_model("erf.onnx");

Inputs inputs;
inputs.emplace_back(ov::test::NDArray<float, 2>{
{-std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()},
{-3.141592f, 0.0f},
{0.5f, 1.0f}}.get_vector());
inputs.emplace_back(
ov::test::NDArray<float, 2>{{-std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()},
{-3.141592f, 0.0f},
{0.5f, 1.0f}}
.get_vector());

const std::vector<float> expected_output =
ov::test::NDArray<float, 2>{{-1.0f, 1.0f}, {-0.99999112f, 0.0f}, {0.52049988f, 0.84270079f}}.get_vector();
Expand Down
Loading