diff --git a/keras/src/backend/openvino/excluded_concrete_tests.txt b/keras/src/backend/openvino/excluded_concrete_tests.txt index c2ecf0371599..39b609affc6b 100644 --- a/keras/src/backend/openvino/excluded_concrete_tests.txt +++ b/keras/src/backend/openvino/excluded_concrete_tests.txt @@ -35,7 +35,7 @@ NumpyDtypeTest::test_max NumpyDtypeTest::test_mean NumpyDtypeTest::test_median NumpyDtypeTest::test_meshgrid -NumpyDtypeTest::test_min +NumpyDtypeTest::test_minimum_python_types NumpyDtypeTest::test_moveaxis NumpyDtypeTest::test_multiply NumpyDtypeTest::test_nan @@ -95,7 +95,6 @@ NumpyOneInputOpsCorrectnessTest::test_max NumpyOneInputOpsCorrectnessTest::test_mean NumpyOneInputOpsCorrectnessTest::test_median NumpyOneInputOpsCorrectnessTest::test_meshgrid -NumpyOneInputOpsCorrectnessTest::test_min NumpyOneInputOpsCorrectnessTest::test_moveaxis NumpyOneInputOpsCorrectnessTest::test_nan_to_num NumpyOneInputOpsCorrectnessTest::test_ndim diff --git a/keras/src/backend/openvino/numpy.py b/keras/src/backend/openvino/numpy.py index f1a998b8e939..9ed5ecd02a87 100644 --- a/keras/src/backend/openvino/numpy.py +++ b/keras/src/backend/openvino/numpy.py @@ -1006,7 +1006,46 @@ def meshgrid(*x, indexing="xy"): def min(x, axis=None, keepdims=False, initial=None): - raise NotImplementedError("`min` is not supported with openvino backend") + x = get_ov_output(x) + original_type = x.get_element_type() + x_type = original_type + x_shape = x.get_partial_shape().to_shape() + + is_bool = x_type == Type.boolean + if is_bool: + x = ov_opset.convert(x, Type.i32).output(0) + x_type = Type.i32 + + if isinstance(axis, tuple) and len(axis) == 0: + return OpenVINOKerasTensor(x) + + if axis is None: + flatten_shape = ov_opset.constant([-1], Type.i32).output(0) + x = ov_opset.reshape(x, flatten_shape, False).output(0) + axis = 0 + + if isinstance(axis, tuple): + axis = list(axis) + + axis_const = ov_opset.constant(axis, Type.i32).output(0) + min_result = ov_opset.reduce_min(x, axis_const, keepdims).output(0) + + if initial is not None: + initial_tensor = ov_opset.constant(initial, x_type).output(0) + min_result = ov_opset.minimum(min_result, initial_tensor).output(0) + + if keepdims: + result_shape = [1] * len(x_shape) + min_result = ov_opset.reshape( + min_result, + ov_opset.constant(result_shape, Type.i32).output(0), + False, + ).output(0) + + if is_bool: + min_result = ov_opset.convert(min_result, Type.boolean).output(0) + + return OpenVINOKerasTensor(min_result) def minimum(x1, x2):