Skip to content

Commit

Permalink
Added onnx test.
Browse files Browse the repository at this point in the history
  • Loading branch information
popovaan committed Jun 20, 2024
1 parent cea0cdc commit a659a7b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
44 changes: 44 additions & 0 deletions tests/layer_tests/ovc_python_api_tests/test_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import openvino.runtime as ov
import pytest
from openvino.runtime import Model
import tempfile
import unittest

from openvino.test_utils import compare_functions
from common.mo_convert_test_class import CommonMOConvertTest


Expand Down Expand Up @@ -47,6 +50,7 @@ def make_graph_proto_model():

return onnx_net


def create_ref_model(shape):
param1 = ov.opset8.parameter(shape, dtype=np.float32)
slope_const = ov.opset8.constant([0.1], dtype=np.float16)
Expand All @@ -56,6 +60,16 @@ def create_ref_model(shape):
parameter_list = [param1]
return Model([relu], parameter_list, "test")


def create_ref_model_fp32(shape):
param1 = ov.opset8.parameter(shape, dtype=np.float32)
slope_const = ov.opset8.constant([0.1], dtype=np.float32)
prelu = ov.opset8.prelu(param1, slope=slope_const)
relu = ov.opset8.elu(prelu, alpha=np.float32(0.1))
parameter_list = [param1]
return Model([relu], parameter_list, "test")


def create_bytes_io():
import onnx
onnx_model = make_graph_proto_model()
Expand All @@ -81,3 +95,33 @@ def test_mo_convert_onnx(self, create_model, ie_device, precision, ir_version,
test_params.update(mo_params)
self._test_by_ref_graph(temp_dir, test_params, graph_ref, compare_tensor_names=False)


class TestUnicodePathsONNX(unittest.TestCase):
@pytest.mark.nightly
@pytest.mark.precommit
def test_unicode_paths(self):
import os
import onnx
test_directory = os.path.dirname(os.path.realpath(__file__))
with tempfile.TemporaryDirectory(dir=test_directory, prefix=r"晚安_путь_к_файлу") as temp_dir:
model = make_graph_proto_model()
model_path = temp_dir + os.sep +'test_model.onnx'
model_ref = create_ref_model_fp32([2, 3, 4])

try:
onnx.save(model, model_path)
except:
return

assert os.path.exists(model_path), "Could not create a directory with unicode path."

from openvino import convert_model
res_model = convert_model(model_path)
flag, msg = compare_functions(res_model, model_ref, False)
assert flag, msg

from openvino.frontend import FrontEndManager
fm = FrontEndManager()
fe = fm.load_by_framework("onnx")

assert fe.supported(model_path)
10 changes: 8 additions & 2 deletions tests/layer_tests/ovc_python_api_tests/test_tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,14 +1290,20 @@ def test_tf1_input_with_identity(self):
assert ov_model.inputs[1].get_names() == {"y:0"}


class TestUnicodePaths(unittest.TestCase):
class TestUnicodePathsTF(unittest.TestCase):
@pytest.mark.nightly
@pytest.mark.precommit
def test_unicode_paths(self):
test_directory = os.path.dirname(os.path.realpath(__file__))
with tempfile.TemporaryDirectory(dir=test_directory, prefix=r"晚安_путь_к_файлу") as temp_dir:
model, model_ref, _ = create_tf_graph_def(None)
model_path = save_to_pb(model, temp_dir)

try:
model_path = save_to_pb(model, temp_dir)
except:
return

assert os.path.exists(model_path), "Could not create a directory with unicode path."

from openvino import convert_model
res_model = convert_model(model_path)
Expand Down

0 comments on commit a659a7b

Please sign in to comment.