Skip to content

Commit

Permalink
Merge pull request #18 from AlexeyLebedev1/alexeyl1/ov_pybind_poc/imp…
Browse files Browse the repository at this point in the history
…rove_test_coverage

Alexeyl1/ov pybind poc/improve test coverage
  • Loading branch information
akuporos authored Apr 8, 2021
2 parents 21c121d + 682cb0a commit 6595f11
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 147 deletions.
25 changes: 25 additions & 0 deletions ngraph/python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@
from pathlib import Path


def image_path():
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 model_path(is_myriad=False):
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')
else:
test_xml = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp16.xml')
test_bin = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp16.bin')
return (test_xml, test_bin)


def plugins_path():
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_win.xml')
plugins_osx_xml = os.path.join(path_to_repo, 'ie_class', 'plugins_apple.xml')
return (plugins_xml, plugins_win_xml, plugins_osx_xml)


def _get_default_model_zoo_dir():
return Path(os.getenv("ONNX_HOME", Path.home() / ".onnx/model_zoo"))

Expand Down
Empty file.
92 changes: 20 additions & 72 deletions ngraph/python/tests/test_inference_engine/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
import os

from openvino.inference_engine import TensorDesc, Blob
from ..conftest import image_path


def image_path():
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

path_to_image = image_path()


Expand Down Expand Up @@ -45,14 +41,29 @@ def test_get_buffer():
assert np.array_equal(blob.buffer, array)


def test_write_to_buffer_fp32():
tensor_desc = TensorDesc("FP32", [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 3, 127, 127), dtype=np.float32)
@pytest.mark.parametrize("precision, numpy_precision",[
("FP32", np.float32),
("FP64", np.float64),
("FP16", np.float16),
("I8", np.int8),
("U8", np.uint8),
("I32", np.int32),
("I16", np.int16),
("U16", np.uint16),
("I64", np.int64),
("BOOL", np.uint8),
("BIN", np.int8),
("BF16", np.float16),
])
def test_write_to_buffer(precision, numpy_precision):
tensor_desc = TensorDesc(precision, [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 3, 127, 127), dtype=numpy_precision)
blob = Blob(tensor_desc, array)
ones_arr = np.ones(shape=(1, 3, 127, 127), dtype=np.float32)
ones_arr = np.ones(shape=(1, 3, 127, 127), dtype=numpy_precision)
blob.buffer[:] = ones_arr
assert np.array_equal(blob.buffer, ones_arr)


tensor_desc_12 = TensorDesc("FP32", [1, 3, 127, 127], "NCHW")
array_12 = np.zeros(shape=(1, 3, 127, 127), dtype=np.float32)
blob_12 = Blob(tensor_desc_12, array_12)
Expand All @@ -70,69 +81,6 @@ def test_l():
f()
assert np.array_equal(blob_12.buffer, f())

@pytest.mark.skip(reason="Need to figure out how to implement right conversion")
def test_write_to_buffer_fp16():
tensor_desc = TensorDesc("FP16", [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 3, 127, 127), dtype=np.float16)
blob = Blob(tensor_desc, array)
ones_arr = np.ones(shape=(1, 3, 127, 127), dtype=np.float16)
blob.buffer[:] = ones_arr
assert np.array_equal(blob.buffer, ones_arr)


def test_write_to_buffer_int8():
tensor_desc = TensorDesc("I8", [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 3, 127, 127), dtype=np.int8)
blob = Blob(tensor_desc, array)
ones_arr = np.ones(shape=(1, 3, 127, 127), dtype=np.int8)
blob.buffer[:] = ones_arr
assert np.array_equal(blob.buffer, ones_arr)


def test_write_to_buffer_uint8():
tensor_desc = TensorDesc("U8", [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 3, 127, 127), dtype=np.uint8)
blob = Blob(tensor_desc, array)
ones_arr = np.ones(shape=(1, 3, 127, 127), dtype=np.uint8)
blob.buffer[:] = ones_arr
assert np.array_equal(blob.buffer, ones_arr)


def test_write_to_buffer_int32():
tensor_desc = TensorDesc("I32", [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 3, 127, 127), dtype=np.int32)
blob = Blob(tensor_desc, array)
ones_arr = np.ones(shape=(1, 3, 127, 127), dtype=np.int32)
blob.buffer[:] = ones_arr
assert np.array_equal(blob.buffer, ones_arr)


def test_write_to_buffer_int16():
tensor_desc = TensorDesc("I16", [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 3, 127, 127), dtype=np.int16)
blob = Blob(tensor_desc, array)
ones_arr = np.ones(shape=(1, 3, 127, 127), dtype=np.int16)
blob.buffer[:] = ones_arr
assert np.array_equal(blob.buffer, ones_arr)


def test_write_to_buffer_uint16():
tensor_desc = TensorDesc("U16", [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 3, 127, 127), dtype=np.uint16)
blob = Blob(tensor_desc, array)
ones_arr = np.ones(shape=(1, 3, 127, 127), dtype=np.uint16)
blob.buffer[:] = ones_arr
assert np.array_equal(blob.buffer, ones_arr)


def test_write_to_buffer_int64():
tensor_desc = TensorDesc("I64", [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 3, 127, 127), dtype=np.int64)
blob = Blob(tensor_desc, array)
ones_arr = np.ones(shape=(1, 3, 127, 127), dtype=np.int64)
blob.buffer[:] = ones_arr
assert np.array_equal(blob.buffer, ones_arr)


def test_write_numpy_scalar_int64():
tensor_desc = TensorDesc("I64", [], "SCALAR")
Expand Down
18 changes: 1 addition & 17 deletions ngraph/python/tests/test_inference_engine/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,12 @@
from ngraph.impl.op import Parameter
from ngraph.impl import Function, Shape, Type
from openvino.inference_engine import IECore, TensorDesc, Blob, IENetwork, ExecutableNetwork
from ..conftest import model_path, plugins_path
import os
import pytest
from sys import platform


def model_path(is_myriad=False):
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')
else:
test_xml = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp16.xml')
test_bin = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp16.bin')
return (test_xml, test_bin)

def plugins_path():
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_win.xml')
plugins_osx_xml = os.path.join(path_to_repo, 'ie_class', 'plugins_apple.xml')
return (plugins_xml, plugins_win_xml, plugins_osx_xml)

test_net_xml, test_net_bin = model_path()
plugins_xml, plugins_win_xml, plugins_osx_xml = plugins_path()

Expand Down
11 changes: 1 addition & 10 deletions ngraph/python/tests/test_inference_engine/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@
import os

from openvino.inference_engine import IECore, DataPtr

def model_path(is_myriad=False):
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')
else:
test_xml = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp16.xml')
test_bin = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp16.bin')
return (test_xml, test_bin)
from ..conftest import model_path

test_net_xml, test_net_bin = model_path()

Expand Down
18 changes: 1 addition & 17 deletions ngraph/python/tests/test_inference_engine/test_exec_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,7 @@
import warnings

from openvino.inference_engine import IECore, IENetwork, ExecutableNetwork, DataPtr, InputInfoPtr, InputInfoCPtr


def image_path():
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 model_path(is_myriad=False):
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')
else:
test_xml = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp16.xml')
test_bin = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp16.bin')
return (test_xml, test_bin)
from ..conftest import model_path, image_path


test_net_xml, test_net_bin = model_path()
Expand Down
10 changes: 1 addition & 9 deletions ngraph/python/tests/test_inference_engine/test_input_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@
# SPDX-License-Identifier: Apache-2.0

from openvino.inference_engine import IECore, IENetwork, ExecutableNetwork, InputInfoPtr, DataPtr, TensorDesc
from ..conftest import model_path

import os
import pytest

def model_path(is_myriad=False):
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')
else:
test_xml = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp16.xml')
test_bin = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp16.bin')
return (test_xml, test_bin)

test_net_xml, test_net_bin = model_path()

Expand Down
12 changes: 1 addition & 11 deletions ngraph/python/tests/test_inference_engine/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,7 @@

import os
import pytest


def model_path(is_myriad=False):
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')
else:
test_xml = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp16.xml')
test_bin = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp16.bin')
return (test_xml, test_bin)
from ..conftest import model_path

test_net_xml, test_net_bin = model_path()

Expand Down
12 changes: 1 addition & 11 deletions ngraph/python/tests/test_inference_engine/test_preprocessinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,7 @@

from openvino.inference_engine import PreProcessInfo, IECore, TensorDesc, Blob, \
MeanVariant, ResizeAlgorithm, ColorFormat, PreProcessChannel


def model_path(is_myriad=False):
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')
else:
test_xml = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp16.xml')
test_bin = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp16.bin')
return (test_xml, test_bin)
from ..conftest import model_path

test_net_xml, test_net_bin = model_path()

Expand Down

0 comments on commit 6595f11

Please sign in to comment.