Skip to content
Merged
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
29 changes: 20 additions & 9 deletions tests/python/unit/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2020-2024 Intel Corporation
# Copyright (C) 2024-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
import numpy as np
Expand All @@ -9,27 +9,38 @@
resize_image_with_aspect_ocv,
)
from openvino.preprocess import PrePostProcessor
import cv2 as cv
import pytest


def test_resize_image_with_aspect_ocv():
param_node = ov.op.Parameter(ov.Type.f32, ov.Shape([1, 8, 8, 3]))
@pytest.mark.parametrize(
"img_shape",
[(301, 999, 3), (999, 301, 3), (500, 500, 3), (1024, 768, 3), (768, 1024, 3)],
)
def test_resize_image_with_aspect_ocv(img_shape):
model_h = 1024
model_w = 1024
pad_value = 0

param_node = ov.op.Parameter(ov.Type.f32, ov.Shape([1, model_h, model_w, 3]))
model = ov.Model(param_node, [param_node])
ppp = PrePostProcessor(model)
ppp.input().tensor().set_element_type(ov.Type.u8)
ppp.input().tensor().set_layout(ov.Layout("NHWC"))
ppp.input().tensor().set_shape([1, -1, -1, 3])
ppp.input().preprocess().custom(
resize_image_with_aspect(
(8, 8),
(model_h, model_w),
"linear",
0,
pad_value,
)
)
ppp.input().preprocess().convert_element_type(ov.Type.f32)
ov_resize_image_with_aspect = ov.Core().compile_model(ppp.build(), "CPU")

img = np.ones((2, 4, 3), dtype=np.uint8)
ov_results = ov_resize_image_with_aspect(img[None])
np_results = resize_image_with_aspect_ocv(img, (8, 8))
img = np.random.randint(0, 255, size=img_shape, dtype=np.uint8)
ov_results = list(ov_resize_image_with_aspect(img[None]).values())[0][0]

np_results = resize_image_with_aspect_ocv(img, (model_w, model_h))

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