Skip to content

Commit

Permalink
[ONNX] Align behavior of ONNX Frontend operator ReduceMean-11, 13, 18…
Browse files Browse the repository at this point in the history
… with original framework (openvinotoolkit#23148)

### Details:
- Align behavior of ONNX Frontend operator ReduceMean-11, 13, 18 with
original framework

### Tickets:
 - Closes openvinotoolkit#20556

---------

Co-authored-by: Georgy Krivoruchko <georgy.krivoruchko@intel.com>
  • Loading branch information
2 people authored and alexandruenache1111 committed Jun 12, 2024
1 parent d478b76 commit e78ae06
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 37 deletions.
9 changes: 6 additions & 3 deletions src/frontends/onnx/frontend/src/op/reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ ov::OutputVector reduce_l2(const Node& node) {
ov::OutputVector reduce_max(const ov::frontend::onnx::Node& node) {
return {make_ov_reduction_op<v1::ReduceMax>(node, node.get_ov_inputs().at(0), supported_types_v3)};
}

ov::OutputVector reduce_mean(const ov::frontend::onnx::Node& node) {
return {make_ov_reduction_op<v1::ReduceMean>(node, node.get_ov_inputs().at(0), supported_types_v2)};
}
ov::OutputVector reduce_min(const ov::frontend::onnx::Node& node) {
return {make_ov_reduction_op<v1::ReduceMin>(node, node.get_ov_inputs().at(0), supported_types_v3)};
}
Expand All @@ -230,11 +232,12 @@ ov::OutputVector reduce_l2(const Node& node) {
ov::OutputVector reduce_max(const ov::frontend::onnx::Node& node) {
return {make_ov_reduction_op<v1::ReduceMax>(node, node.get_ov_inputs().at(0), supported_types_v3, false)};
}

ov::OutputVector reduce_mean(const ov::frontend::onnx::Node& node) {
return {make_ov_reduction_op<v1::ReduceMean>(node, node.get_ov_inputs().at(0), supported_types_v3, false)};
}
ov::OutputVector reduce_min(const ov::frontend::onnx::Node& node) {
return {make_ov_reduction_op<v1::ReduceMin>(node, node.get_ov_inputs().at(0), supported_types_v3, false)};
}

ov::OutputVector reduce_log_sum(const ov::frontend::onnx::Node& node) {
const ov::Output<ov::Node> sum_node =
make_ov_reduction_op<v1::ReduceSum>(node, node.get_ov_inputs().at(0), supported_types_v2, false);
Expand Down
6 changes: 6 additions & 0 deletions src/frontends/onnx/frontend/src/op/reduce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ ov::OutputVector reduce_max(const ov::frontend::onnx::Node& node);
namespace set_1 {
ov::OutputVector reduce_mean(const ov::frontend::onnx::Node& node);
} // namespace set_1
namespace set_13 {
ov::OutputVector reduce_mean(const ov::frontend::onnx::Node& node);
} // namespace set_13
namespace set_18 {
ov::OutputVector reduce_mean(const ov::frontend::onnx::Node& node);
} // namespace set_18

namespace set_1 {
ov::OutputVector reduce_min(const ov::frontend::onnx::Node& node);
Expand Down
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 @@ -497,6 +497,8 @@ OperatorsBridge::OperatorsBridge() {
REGISTER_OPERATOR("ReduceMax", 18, reduce_max);
REGISTER_OPERATOR("ReduceMax", 20, reduce_max);
REGISTER_OPERATOR("ReduceMean", 1, reduce_mean);
REGISTER_OPERATOR("ReduceMean", 13, reduce_mean);
REGISTER_OPERATOR("ReduceMean", 18, reduce_mean);
REGISTER_OPERATOR("ReduceMin", 1, reduce_min);
REGISTER_OPERATOR("ReduceMin", 13, reduce_min);
REGISTER_OPERATOR("ReduceMin", 18, reduce_min);
Expand Down
67 changes: 67 additions & 0 deletions src/frontends/onnx/tests/models/reduce_mean_18.prototxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
ir_version: 7
graph {
node {
input: "a"
input: "axes"
output: "b"
op_type: "ReduceMean"
}
name: "ReduceMeanGraph"
initializer {
data_type: 6
dims: 1
name: "axes"
raw_data: "\002\000\000\000"
}
input {
name: "a"
type {
tensor_type {
elem_type: 2
shape {
dim {
dim_value: 1
}
dim {
dim_value: 1
}
dim {
dim_value: 4
}
dim {
dim_value: 4
}
}
}
}
}
input {
name: "axes"
type {
tensor_type {
elem_type: 6
shape {
dim {
dim_value: 1
}
}
}
}
}
output {
name: "b"
type {
tensor_type {
elem_type: 2
shape {
dim {
dim_value: 1
}
}
}
}
}
}
opset_import {
version: 18
}
17 changes: 17 additions & 0 deletions src/frontends/onnx/tests/onnx_import.in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,23 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_reduce_mean) {
test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_model_reduce_mean_18) {
auto model = convert_model("reduce_mean_18.onnx");

// input data shape (1, 1, 4, 4)
std::vector<std::vector<uint8_t>> inputs{
ov::test::NDArray<uint8_t, 4>({{{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}}})
.get_vector()};

// output data shape (1,)
auto expected_output = ov::test::NDArray<uint8_t, 1>({7, 8, 9, 10}).get_vector();

auto test_case = ov::test::TestCase(model, s_device);
test_case.add_multiple_inputs(inputs);
test_case.add_expected_output(expected_output);
test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_model_reduce_min) {
auto model = convert_model("reduce_min.onnx");

Expand Down
34 changes: 0 additions & 34 deletions src/frontends/onnx/tests/tests_python/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
xfail_issue_99950,
xfail_issue_99952,
xfail_issue_99954,
xfail_issue_99955,
xfail_issue_99957,
xfail_issue_99960,
xfail_issue_99961,
xfail_issue_99968,
xfail_issue_99969,
Expand Down Expand Up @@ -419,31 +416,6 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None
xfail_issue_99954,
"OnnxBackendNodeModelTest.test_constant_pad_axes_cpu",
),
(
xfail_issue_99955,
"OnnxBackendNodeModelTest.test_group_normalization_epsilon_expanded_cpu",
"OnnxBackendNodeModelTest.test_group_normalization_example_expanded_cpu",
),
(
xfail_issue_99957,
"OnnxBackendNodeModelTest.test_layer_normalization_2d_axis1_expanded_ver18_cpu",
"OnnxBackendNodeModelTest.test_layer_normalization_2d_axis_negative_1_expanded_ver18_cpu",
"OnnxBackendNodeModelTest.test_layer_normalization_3d_axis1_epsilon_expanded_ver18_cpu",
"OnnxBackendNodeModelTest.test_layer_normalization_3d_axis2_epsilon_expanded_ver18_cpu",
"OnnxBackendNodeModelTest.test_layer_normalization_3d_axis_negative_1_epsilon_expanded_ver18_cpu",
"OnnxBackendNodeModelTest.test_layer_normalization_3d_axis_negative_2_epsilon_expanded_ver18_cpu",
"OnnxBackendNodeModelTest.test_layer_normalization_4d_axis1_expanded_ver18_cpu",
"OnnxBackendNodeModelTest.test_layer_normalization_4d_axis2_expanded_ver18_cpu",
"OnnxBackendNodeModelTest.test_layer_normalization_4d_axis3_expanded_ver18_cpu",
"OnnxBackendNodeModelTest.test_layer_normalization_4d_axis_negative_1_expanded_ver18_cpu",
"OnnxBackendNodeModelTest.test_layer_normalization_4d_axis_negative_2_expanded_ver18_cpu",
"OnnxBackendNodeModelTest.test_layer_normalization_4d_axis_negative_3_expanded_ver18_cpu",
"OnnxBackendNodeModelTest.test_layer_normalization_default_axis_expanded_ver18_cpu",
),
(
xfail_issue_99960,
"OnnxBackendNodeModelTest.test_mvn_expanded_ver18_cpu",
),
(
xfail_issue_99961,
"OnnxBackendNodeModelTest.test_optional_get_element_optional_sequence_cpu",
Expand Down Expand Up @@ -475,13 +447,7 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None
"OnnxBackendNodeModelTest.test_reduce_log_sum_exp_keepdims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_log_sum_exp_negative_axes_keepdims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_log_sum_exp_keepdims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_mean_do_not_keepdims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_log_sum_exp_negative_axes_keepdims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_mean_do_not_keepdims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_mean_keepdims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_mean_negative_axes_keepdims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_mean_keepdims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_mean_negative_axes_keepdims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_prod_do_not_keepdims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_prod_do_not_keepdims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_prod_keepdims_example_cpu",
Expand Down

0 comments on commit e78ae06

Please sign in to comment.