diff --git a/src/frontends/onnx/frontend/src/op/reduce.cpp b/src/frontends/onnx/frontend/src/op/reduce.cpp index 284b984ab4aa2c..d338463c54304d 100644 --- a/src/frontends/onnx/frontend/src/op/reduce.cpp +++ b/src/frontends/onnx/frontend/src/op/reduce.cpp @@ -201,12 +201,21 @@ ov::OutputVector reduce_sum(const ov::frontend::onnx::Node& node) { ov::OutputVector reduce_max(const ov::frontend::onnx::Node& node) { return {make_ov_reduction_op(node, node.get_ov_inputs().at(0), supported_types_v3)}; } + +ov::OutputVector reduce_min(const ov::frontend::onnx::Node& node) { + return {make_ov_reduction_op(node, node.get_ov_inputs().at(0), supported_types_v3)}; +} } // namespace set_13 namespace set_18 { ov::OutputVector reduce_max(const ov::frontend::onnx::Node& node) { return {make_ov_reduction_op(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(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 sum_node = make_ov_reduction_op(node, node.get_ov_inputs().at(0), supported_types_v2, false); @@ -229,6 +238,21 @@ ov::OutputVector reduce_max(const ov::frontend::onnx::Node& node) { element::boolean)}; } } + +ov::OutputVector reduce_min(const ov::frontend::onnx::Node& node) { + auto data = node.get_ov_inputs().at(0); + if (data.get_element_type() != element::boolean) { + return {make_ov_reduction_op(node, data, supported_types_v3, false)}; + } else { + // Handling boolean as a uint8 + return {std::make_shared( + make_ov_reduction_op(node, + std::make_shared(data, element::u8), + supported_types_v4, + false), + element::boolean)}; + } +} } // namespace set_20 } // namespace op } // namespace onnx diff --git a/src/frontends/onnx/frontend/src/op/reduce.hpp b/src/frontends/onnx/frontend/src/op/reduce.hpp index a30f1ec86b7d2d..d79475f71ea07a 100644 --- a/src/frontends/onnx/frontend/src/op/reduce.hpp +++ b/src/frontends/onnx/frontend/src/op/reduce.hpp @@ -49,6 +49,15 @@ ov::OutputVector reduce_mean(const ov::frontend::onnx::Node& node); namespace set_1 { ov::OutputVector reduce_min(const ov::frontend::onnx::Node& node); } // namespace set_1 +namespace set_13 { +ov::OutputVector reduce_min(const ov::frontend::onnx::Node& node); +} // namespace set_13 +namespace set_18 { +ov::OutputVector reduce_min(const ov::frontend::onnx::Node& node); +} // namespace set_18 +namespace set_20 { +ov::OutputVector reduce_min(const ov::frontend::onnx::Node& node); +} // namespace set_20 namespace set_1 { ov::OutputVector reduce_prod(const ov::frontend::onnx::Node& node); diff --git a/src/frontends/onnx/frontend/src/ops_bridge.cpp b/src/frontends/onnx/frontend/src/ops_bridge.cpp index 02255b673ca576..4ec721a236cbfd 100644 --- a/src/frontends/onnx/frontend/src/ops_bridge.cpp +++ b/src/frontends/onnx/frontend/src/ops_bridge.cpp @@ -492,6 +492,9 @@ OperatorsBridge::OperatorsBridge() { REGISTER_OPERATOR("ReduceMax", 20, reduce_max); REGISTER_OPERATOR("ReduceMean", 1, reduce_mean); REGISTER_OPERATOR("ReduceMin", 1, reduce_min); + REGISTER_OPERATOR("ReduceMin", 13, reduce_min); + REGISTER_OPERATOR("ReduceMin", 18, reduce_min); + REGISTER_OPERATOR("ReduceMin", 20, reduce_min); REGISTER_OPERATOR("ReduceProd", 1, reduce_prod); REGISTER_OPERATOR("ReduceSum", 1, reduce_sum); REGISTER_OPERATOR("ReduceSum", 13, reduce_sum); diff --git a/src/frontends/onnx/tests/__init__.py b/src/frontends/onnx/tests/__init__.py index 2768f08d031804..a50f11c49f8405 100644 --- a/src/frontends/onnx/tests/__init__.py +++ b/src/frontends/onnx/tests/__init__.py @@ -169,7 +169,6 @@ def xfail_test(reason="Mark the test as expected to fail", strict=True): xfail_issue_125491 = xfail_test(reason="AveragePool mismatch with differences in shapes") xfail_issue_125492 = xfail_test(reason="DFT mismatch") xfail_issue_125493 = xfail_test(reason="Reduce* mismatch") -xfail_issue_125495 = xfail_test(reason="ReduceMin/Max doesn't support boolean") xfail_issue_122776 = xfail_test(reason="test_mish_expanded_cpu - " "Not equal to tolerance") xfail_issue_122775 = xfail_test(reason="test_resize_downsample_scales_linear_cpu - " diff --git a/src/frontends/onnx/tests/models/reduce_min_18.prototxt b/src/frontends/onnx/tests/models/reduce_min_18.prototxt new file mode 100644 index 00000000000000..8ad49403b2ed1c --- /dev/null +++ b/src/frontends/onnx/tests/models/reduce_min_18.prototxt @@ -0,0 +1,70 @@ +ir_version: 3 +producer_name: "OpenVINO ONNX Frontend" +graph { + node { + input: "A" + input: "axes" + output: "B" + op_type: "ReduceMin" + } + name: "compute_graph" + 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 +} + +# Acknowledgement: this model is a modified version of reduce_max_18.prototxt \ No newline at end of file diff --git a/src/frontends/onnx/tests/models/reduce_min_20.prototxt b/src/frontends/onnx/tests/models/reduce_min_20.prototxt new file mode 100644 index 00000000000000..ff986647af9ede --- /dev/null +++ b/src/frontends/onnx/tests/models/reduce_min_20.prototxt @@ -0,0 +1,70 @@ +ir_version: 3 +producer_name: "OpenVINO ONNX Frontend" +graph { + node { + input: "A" + input: "axes" + output: "B" + op_type: "ReduceMin" + } + name: "compute_graph" + 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: 20 +} + +# Acknowledgement: this model is a modified version of reduce_max_18.prototxt \ No newline at end of file diff --git a/src/frontends/onnx/tests/onnx_import.in.cpp b/src/frontends/onnx/tests/onnx_import.in.cpp index 7b3e39e71399aa..3332f7e5ab74ec 100644 --- a/src/frontends/onnx/tests/onnx_import.in.cpp +++ b/src/frontends/onnx/tests/onnx_import.in.cpp @@ -6557,3 +6557,51 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_mish_activation) { test_case.run_with_tolerance_as_fp(0.000001f); } + +OPENVINO_TEST(${BACKEND_NAME}, onnx_model_reduce_min_18) { + // Credit: This function is a modified version of PR 23475's test function. + // TEMPLATE plugin has an issue with evaluation for u8 type + if (std::string("${BACKEND_NAME}") == std::string("INTERPRETER")) { + GTEST_SKIP(); + } + + auto model = convert_model("reduce_min_18.onnx"); + + // input data shape (1, 1, 4, 4) + std::vector> inputs{ + ov::test::NDArray({{{{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({1, 2, 3, 4}).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_20_boolean) { + // Credit: This function is a modified version of PR 23475's test function. + // TEMPLATE plugin has an issue with evaluation for u8 type + if (std::string("${BACKEND_NAME}") == std::string("INTERPRETER")) { + GTEST_SKIP(); + } + + auto model = convert_model("reduce_min_20.onnx"); + + // input data shape (1, 1, 4, 4) + std::vector> inputs{ov::test::NDArray({{{{true, true, false, false}, + {true, false, false, false}, + {true, false, false, false}, + {true, true, false, false}}}}) + .get_vector()}; + + // output data shape (1,) + auto expected_output = ov::test::NDArray({1, 0, 0, 0}).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(); +} \ No newline at end of file diff --git a/src/frontends/onnx/tests/tests_python/test_backend.py b/src/frontends/onnx/tests/tests_python/test_backend.py index a3df52ef064779..1dc42812c200df 100644 --- a/src/frontends/onnx/tests/tests_python/test_backend.py +++ b/src/frontends/onnx/tests/tests_python/test_backend.py @@ -74,7 +74,6 @@ xfail_issue_125491, xfail_issue_125492, xfail_issue_125493, - xfail_issue_125495, xfail_issue_122775, xfail_issue_122776, skip_misalignment, @@ -489,12 +488,6 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None "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_min_do_not_keepdims_example_cpu", - "OnnxBackendNodeModelTest.test_reduce_min_do_not_keepdims_random_cpu", - "OnnxBackendNodeModelTest.test_reduce_min_keepdims_example_cpu", - "OnnxBackendNodeModelTest.test_reduce_min_keepdims_random_cpu", - "OnnxBackendNodeModelTest.test_reduce_min_negative_axes_keepdims_example_cpu", - "OnnxBackendNodeModelTest.test_reduce_min_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", @@ -698,14 +691,9 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None "OnnxBackendNodeModelTest.test_reduce_l1_empty_set_cpu", "OnnxBackendNodeModelTest.test_reduce_l2_empty_set_cpu", "OnnxBackendNodeModelTest.test_reduce_log_sum_exp_empty_set_cpu", - "OnnxBackendNodeModelTest.test_reduce_min_empty_set_cpu", "OnnxBackendNodeModelTest.test_reduce_prod_empty_set_cpu", "OnnxBackendNodeModelTest.test_reduce_sum_square_empty_set_cpu", ), - ( - xfail_issue_125495, - "OnnxBackendNodeModelTest.test_reduce_min_bool_inputs_cpu", - ), ( skip_misalignment, "OnnxBackendNodeModelTest.test_gelu_default_2_expanded_cpu",