Fixed type check in convert_model(). (#14472)
* Fixed passing Path to convert_model(). * Update tools/mo/openvino/tools/mo/convert_impl.py Co-authored-by: Ekaterina Aidova <ekaterina.aidova@intel.com> Co-authored-by: Ekaterina Aidova <ekaterina.aidova@intel.com>
This commit is contained in:
parent
532000a0ce
commit
60bb9e7b7c
@ -9,6 +9,7 @@ import platform
|
||||
import sys
|
||||
from collections import OrderedDict
|
||||
from copy import deepcopy
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
|
||||
@ -831,7 +832,7 @@ def show_mo_convert_help():
|
||||
|
||||
|
||||
def input_model_is_object(argv):
|
||||
if isinstance(argv['input_model'], str):
|
||||
if isinstance(argv['input_model'], (str, Path)):
|
||||
return False
|
||||
if argv['input_model'] is None:
|
||||
return False
|
||||
|
@ -3,8 +3,8 @@
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
from generator import generator, generate
|
||||
from openvino.runtime import serialize
|
||||
|
||||
@ -19,25 +19,7 @@ from utils import create_onnx_model, save_to_onnx
|
||||
class ConvertImportMOTest(UnitTestWithMockedTelemetry):
|
||||
test_directory = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
@generate(*[
|
||||
({}),
|
||||
({'input': InputCutInfo(name='LeakyRelu_out', shape=None, type=None, value=None)}),
|
||||
({'layout': {'input': LayoutMap(source_layout='NCHW', target_layout='NHWC')}}),
|
||||
])
|
||||
# Checks convert import from openvino.tools.mo
|
||||
def test_import(self, params):
|
||||
from openvino.tools.mo import convert_model
|
||||
|
||||
with tempfile.TemporaryDirectory(dir=self.test_directory) as tmpdir:
|
||||
model = create_onnx_model()
|
||||
model_path = save_to_onnx(model, tmpdir)
|
||||
out_xml = os.path.join(tmpdir, "model.xml")
|
||||
|
||||
ov_model = convert_model(input_model=model_path, **params)
|
||||
serialize(ov_model, out_xml.encode('utf-8'), out_xml.replace('.xml', '.bin').encode('utf-8'))
|
||||
assert os.path.exists(out_xml)
|
||||
|
||||
def test_unnamed_input_model(self):
|
||||
@staticmethod
|
||||
def create_onnx_model():
|
||||
#
|
||||
# Create ONNX model
|
||||
@ -75,6 +57,8 @@ class ConvertImportMOTest(UnitTestWithMockedTelemetry):
|
||||
onnx_net = helper.make_model(graph_def, producer_name='test_model')
|
||||
return onnx_net
|
||||
|
||||
@staticmethod
|
||||
def create_model_ref():
|
||||
nodes_attributes = {
|
||||
'input': {'kind': 'op', 'type': 'Parameter'},
|
||||
'input_data': {'shape': [1, 2, 3], 'kind': 'data'},
|
||||
@ -93,16 +77,53 @@ class ConvertImportMOTest(UnitTestWithMockedTelemetry):
|
||||
('sigmoid', 'sigmoid_data'),
|
||||
('sigmoid_data', 'result'),
|
||||
])
|
||||
return ref_graph
|
||||
|
||||
@generate(*[
|
||||
({}),
|
||||
({'input': InputCutInfo(name='LeakyRelu_out', shape=None, type=None, value=None)}),
|
||||
({'layout': {'input': LayoutMap(source_layout='NCHW', target_layout='NHWC')}}),
|
||||
])
|
||||
# Checks convert import from openvino.tools.mo
|
||||
def test_import(self, params):
|
||||
from openvino.tools.mo import convert_model
|
||||
|
||||
with tempfile.TemporaryDirectory(dir=self.test_directory) as tmpdir:
|
||||
model = create_onnx_model()
|
||||
model_path = save_to_onnx(model, tmpdir)
|
||||
out_xml = os.path.join(tmpdir, "model.xml")
|
||||
|
||||
ov_model = convert_model(input_model=model_path, **params)
|
||||
serialize(ov_model, out_xml.encode('utf-8'), out_xml.replace('.xml', '.bin').encode('utf-8'))
|
||||
assert os.path.exists(out_xml)
|
||||
|
||||
def test_input_model_path(self):
|
||||
from openvino.tools.mo import convert_model
|
||||
|
||||
with tempfile.TemporaryDirectory(dir=self.test_directory) as tmpdir:
|
||||
model = self.create_onnx_model()
|
||||
model_path = save_to_onnx(model, tmpdir)
|
||||
out_xml = os.path.join(tmpdir, Path("model.xml"))
|
||||
|
||||
ov_model = convert_model(input_model=model_path)
|
||||
serialize(ov_model, out_xml.encode('utf-8'), out_xml.replace('.xml', '.bin').encode('utf-8'))
|
||||
|
||||
ir = IREngine(out_xml, out_xml.replace('.xml', '.bin'))
|
||||
ref_graph = self.create_model_ref()
|
||||
flag, resp = ir.compare(ref_graph)
|
||||
assert flag, '\n'.join(resp)
|
||||
|
||||
def test_unnamed_input_model(self):
|
||||
from openvino.tools.mo import convert_model
|
||||
with tempfile.TemporaryDirectory(dir=self.test_directory) as tmpdir:
|
||||
model = self.create_onnx_model()
|
||||
model_path = save_to_onnx(model, tmpdir)
|
||||
out_xml = os.path.join(tmpdir, "model.xml")
|
||||
|
||||
ov_model = convert_model(model_path)
|
||||
serialize(ov_model, out_xml.encode('utf-8'), out_xml.replace('.xml', '.bin').encode('utf-8'))
|
||||
|
||||
ir = IREngine(out_xml, out_xml.replace('.xml', '.bin'))
|
||||
ref_graph = self.create_model_ref()
|
||||
flag, resp = ir.compare(ref_graph)
|
||||
assert flag, '\n'.join(resp)
|
||||
|
Loading…
Reference in New Issue
Block a user