Added ONNX reader for the OpenVINO (#532)

* Added ONNX reader for the OpenVINO

* Fixed comments

* Fixed comments

* Fixed message

* Fixed memory consumption

* Revert IReaderPtr

* Fixed Myriad tests

* Fixed comment

* Renamed inference_engine_ir_readers to inference_engine_ir_reader
This commit is contained in:
Ilya Churaev
2020-05-27 18:37:19 +03:00
committed by GitHub
parent d5434a036e
commit 3c718809d3
54 changed files with 1146 additions and 481 deletions

View File

@@ -11,6 +11,7 @@ from libc.stdint cimport int64_t, uint8_t, int8_t, int32_t, uint16_t, int16_t
from libc.string cimport memcpy
import os
from fnmatch import fnmatch
from pathlib import Path
import threading
import warnings
@@ -268,20 +269,23 @@ cdef class IECore:
net.impl = self.impl.readNetwork(xml_buffer, bin_buffer, len(weights))
free(xml_buffer)
else:
weights_ = "".encode()
if isinstance(model, Path) and isinstance(weights, Path):
if not model.is_file():
raise Exception("Path to the model {} doesn't exist or it's a directory".format(model))
if not weights.is_file():
raise Exception("Path to the weights {} doesn't exist or it's a directory".format(weights))
if model.suffix != ".onnx":
if not weights.is_file():
raise Exception("Path to the weights {} doesn't exist or it's a directory".format(weights))
weights_ = bytes(weights)
model_ = bytes(model)
weights_ = bytes(weights)
else:
if not os.path.isfile(model):
raise Exception("Path to the model {} doesn't exist or it's a directory".format(model))
if not os.path.isfile(weights):
raise Exception("Path to the weights {} doesn't exist or it's a directory".format(weights))
if not fnmatch(model, "*.onnx"):
if not os.path.isfile(weights):
raise Exception("Path to the weights {} doesn't exist or it's a directory".format(weights))
weights_ = weights.encode()
model_ = model.encode()
weights_ = weights.encode()
net.impl = self.impl.readNetwork(model_, weights_)
return net

View File

@@ -3,10 +3,7 @@ import pytest
def model_path(is_myriad=False):
if os.environ.get("MODELS_PATH"):
path_to_repo = os.environ.get("MODELS_PATH")
else:
raise EnvironmentError("MODELS_PATH variable isn't set")
path_to_repo = os.environ["MODELS_PATH"]
if not is_myriad:
test_xml = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp32.xml')
test_bin = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp32.bin')
@@ -15,24 +12,27 @@ def model_path(is_myriad=False):
test_bin = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp16.bin')
return (test_xml, test_bin)
def model_onnx_path():
path_to_repo = os.environ["MODELS_PATH"]
test_onnx = os.path.join(path_to_repo, "models", "test_model", 'test_model.onnx')
return test_onnx
def image_path():
if os.environ.get("DATA_PATH"):
path_to_repo = os.environ.get("DATA_PATH")
else:
raise EnvironmentError("DATA_PATH variable isn't set")
path_to_repo = os.environ["DATA_PATH"]
path_to_img = os.path.join(path_to_repo, 'validation_set', '224x224', 'dog.bmp')
return path_to_img
def plugins_path():
if os.environ.get("DATA_PATH"):
path_to_repo = os.environ.get("DATA_PATH")
else:
raise EnvironmentError("DATA_PATH variable isn't set")
path_to_repo = os.environ["DATA_PATH"]
plugins_xml = os.path.join(path_to_repo, 'ie_class', 'plugins.xml')
plugins_win_xml = os.path.join(path_to_repo, 'ie_class', 'plugins_mingw.xml')
plugins_osx_xml = os.path.join(path_to_repo, 'ie_class', 'plugins_apple.xml')
return (plugins_xml, plugins_win_xml, plugins_osx_xml)
@pytest.fixture(scope='session')
def device():
return os.environ.get("TEST_DEVICE") if os.environ.get("TEST_DEVICE") else "CPU"

View File

@@ -5,7 +5,7 @@ import numpy as np
from pathlib import Path
from openvino.inference_engine import IENetwork, IECore, ExecutableNetwork
from conftest import model_path, plugins_path
from conftest import model_path, plugins_path, model_onnx_path
test_net_xml, test_net_bin = model_path()
@@ -143,28 +143,39 @@ def test_get_metric_str():
assert isinstance(param, str), "Parameter value for 'FULL_DEVICE_NAME' " \
"metric must be string but {} is returned".format(type(param))
def test_read_network_from_xml():
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
assert isinstance(net, IENetwork)
def test_read_network_as_path():
ie = IECore()
net = ie.read_network(model=Path(model_path()[0]), weights=Path(test_net_bin))
assert isinstance(net, IENetwork)
def test_read_network_from_onnx():
ie = IECore()
net = ie.read_network(model=model_onnx_path())
assert isinstance(net, IENetwork)
def test_incorrect_xml():
ie = IECore()
with pytest.raises(Exception) as e:
ie.read_network(model="./model.xml", weights=Path(test_net_bin))
assert "Path to the model ./model.xml doesn't exist or it's a directory" in str(e.value)
def test_incorrect_bin():
ie = IECore()
with pytest.raises(Exception) as e:
ie.read_network(model=test_net_xml, weights="./model.bin")
assert "Path to the weights ./model.bin doesn't exist or it's a directory" in str(e.value)
def test_read_net_from_buffer():
ie = IECore()
with open(test_net_bin, 'rb') as f:
@@ -174,6 +185,7 @@ def test_read_net_from_buffer():
net = ie.read_network(model=xml, weights=bin, init_from_buffer=True)
assert isinstance(net, IENetwork)
def test_net_from_buffer_valid():
ie = IECore()
with open(test_net_bin, 'rb') as f: