Skip to content

Commit a0afb8d

Browse files
committed
Revamp resize test
1 parent 058a1ad commit a0afb8d

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

tests/python/unit/test_utils.py

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2020-2024 Intel Corporation
2+
# Copyright (C) 2024-2025 Intel Corporation
33
# SPDX-License-Identifier: Apache-2.0
44
#
55
import numpy as np
@@ -9,27 +9,38 @@
99
resize_image_with_aspect_ocv,
1010
)
1111
from openvino.preprocess import PrePostProcessor
12+
import cv2 as cv
13+
import pytest
1214

1315

14-
def test_resize_image_with_aspect_ocv():
15-
param_node = ov.op.Parameter(ov.Type.f32, ov.Shape([1, 8, 8, 3]))
16+
@pytest.mark.parametrize(
17+
"img_shape",
18+
[(301, 999, 3), (999, 301, 3), (500, 500, 3), (1024, 768, 3), (768, 1024, 3)],
19+
)
20+
def test_resize_image_with_aspect_ocv(img_shape):
21+
model_h = 1024
22+
model_w = 1024
23+
pad_value = 0
24+
25+
param_node = ov.op.Parameter(ov.Type.f32, ov.Shape([1, model_h, model_w, 3]))
1626
model = ov.Model(param_node, [param_node])
1727
ppp = PrePostProcessor(model)
1828
ppp.input().tensor().set_element_type(ov.Type.u8)
1929
ppp.input().tensor().set_layout(ov.Layout("NHWC"))
2030
ppp.input().tensor().set_shape([1, -1, -1, 3])
2131
ppp.input().preprocess().custom(
2232
resize_image_with_aspect(
23-
(8, 8),
33+
(model_h, model_w),
2434
"linear",
25-
0,
35+
pad_value,
2636
)
2737
)
2838
ppp.input().preprocess().convert_element_type(ov.Type.f32)
2939
ov_resize_image_with_aspect = ov.Core().compile_model(ppp.build(), "CPU")
3040

31-
img = np.ones((2, 4, 3), dtype=np.uint8)
32-
ov_results = ov_resize_image_with_aspect(img[None])
33-
np_results = resize_image_with_aspect_ocv(img, (8, 8))
41+
img = np.random.randint(0, 255, size=img_shape, dtype=np.uint8)
42+
ov_results = list(ov_resize_image_with_aspect(img[None]).values())[0][0]
43+
44+
np_results = resize_image_with_aspect_ocv(img, (model_w, model_h))
3445

35-
assert np.sum(np.abs(list(ov_results.values())[0][0] - np_results)) < 1e-05
46+
assert cv.PSNR(np_results.astype(np.float32), ov_results) > 20.0

0 commit comments

Comments
 (0)