[PyOV][Tests] Fix some tests for M1 (#14555)
This commit is contained in:
parent
40627c99f5
commit
9388560aec
@ -85,14 +85,6 @@ def model_onnx_path():
|
||||
return test_onnx
|
||||
|
||||
|
||||
def plugins_path():
|
||||
base_path = os.path.dirname(__file__)
|
||||
plugins_xml = os.path.join(base_path, "test_utils", "utils", "plugins.xml")
|
||||
plugins_win_xml = os.path.join(base_path, "test_utils", "utils", "plugins_win.xml")
|
||||
plugins_osx_xml = os.path.join(base_path, "test_utils", "utils", "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"))
|
||||
|
||||
|
@ -7,34 +7,21 @@ import pytest
|
||||
import numpy as np
|
||||
|
||||
from tests.conftest import model_path
|
||||
from tests.test_utils.test_utils import generate_image
|
||||
from openvino.runtime import Model, ConstOutput, Shape
|
||||
|
||||
from openvino.runtime import Core, Tensor
|
||||
from tests.test_utils.test_utils import get_relu_model, generate_image, generate_model_and_image, generate_relu_compiled_model
|
||||
from openvino.runtime import Model, ConstOutput, Shape, Core, Tensor
|
||||
|
||||
is_myriad = os.environ.get("TEST_DEVICE") == "MYRIAD"
|
||||
test_net_xml, test_net_bin = model_path(is_myriad)
|
||||
|
||||
|
||||
def test_get_property_model_name(device):
|
||||
def test_get_property(device):
|
||||
model = get_relu_model([1, 3, 32, 32])
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
compiled_model = core.compile_model(model, device, {})
|
||||
network_name = compiled_model.get_property("NETWORK_NAME")
|
||||
assert network_name == "test_model"
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason="Device dependent test")
|
||||
def test_get_property(device):
|
||||
core = Core()
|
||||
if core.get_property(device, "FULL_DEVICE_NAME") == "arm_compute::NEON":
|
||||
pytest.skip("Can't run on ARM plugin due-to CPU dependent test")
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
profiling_enabled = compiled_model.get_property("PERF_COUNT")
|
||||
assert not profiling_enabled
|
||||
|
||||
|
||||
def test_get_runtime_model(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
@ -43,14 +30,18 @@ def test_get_runtime_model(device):
|
||||
assert isinstance(runtime_model, Model)
|
||||
|
||||
|
||||
def test_export_import():
|
||||
def test_export_import(device):
|
||||
core = Core()
|
||||
|
||||
if "EXPORT_IMPORT" not in core.get_property(device, "OPTIMIZATION_CAPABILITIES"):
|
||||
pytest.skip(f"{core.get_property(device, 'FULL_DEVICE_NAME')} plugin due-to export, import model API isn't implemented.")
|
||||
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, "CPU")
|
||||
compiled_model = core.compile_model(model, device)
|
||||
|
||||
user_stream = compiled_model.export_model()
|
||||
|
||||
new_compiled = core.import_model(user_stream, "CPU")
|
||||
new_compiled = core.import_model(user_stream, device)
|
||||
|
||||
img = generate_image()
|
||||
res = new_compiled.infer_new_request({"data": img})
|
||||
@ -58,18 +49,22 @@ def test_export_import():
|
||||
assert np.argmax(res[new_compiled.outputs[0]]) == 9
|
||||
|
||||
|
||||
def test_export_import_advanced():
|
||||
def test_export_import_advanced(device):
|
||||
import io
|
||||
|
||||
core = Core()
|
||||
|
||||
if "EXPORT_IMPORT" not in core.get_property(device, "OPTIMIZATION_CAPABILITIES"):
|
||||
pytest.skip(f"{core.get_property(device, 'FULL_DEVICE_NAME')} plugin due-to export, import model API isn't implemented.")
|
||||
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, "CPU")
|
||||
compiled_model = core.compile_model(model, device)
|
||||
|
||||
user_stream = io.BytesIO()
|
||||
|
||||
compiled_model.export_model(user_stream)
|
||||
|
||||
new_compiled = core.import_model(user_stream, "CPU")
|
||||
new_compiled = core.import_model(user_stream, device)
|
||||
|
||||
img = generate_image()
|
||||
res = new_compiled.infer_new_request({"data": img})
|
||||
@ -77,59 +72,23 @@ def test_export_import_advanced():
|
||||
assert np.argmax(res[new_compiled.outputs[0]]) == 9
|
||||
|
||||
|
||||
def test_get_input_i(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
net_input = compiled_model.input(0)
|
||||
input_node = net_input.get_node()
|
||||
name = input_node.friendly_name
|
||||
@pytest.mark.parametrize("input_arguments", [[0], ["data"], []])
|
||||
def test_get_input(device, input_arguments):
|
||||
compiled_model = generate_relu_compiled_model(device)
|
||||
net_input = compiled_model.input(*input_arguments)
|
||||
assert isinstance(net_input, ConstOutput)
|
||||
assert name == "data"
|
||||
assert net_input.get_node().friendly_name == "data"
|
||||
|
||||
|
||||
def test_get_input_tensor_name(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
net_input = compiled_model.input("data")
|
||||
input_node = net_input.get_node()
|
||||
name = input_node.friendly_name
|
||||
assert isinstance(net_input, ConstOutput)
|
||||
assert name == "data"
|
||||
|
||||
|
||||
def test_get_input(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
net_input = compiled_model.input()
|
||||
input_node = net_input.get_node()
|
||||
name = input_node.friendly_name
|
||||
assert isinstance(net_input, ConstOutput)
|
||||
assert name == "data"
|
||||
|
||||
|
||||
def test_get_output_i(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
output = compiled_model.output(0)
|
||||
assert isinstance(output, ConstOutput)
|
||||
|
||||
|
||||
def test_get_output(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
output = compiled_model.output()
|
||||
@pytest.mark.parametrize("output_arguments", [[0], []])
|
||||
def test_get_output(device, output_arguments):
|
||||
compiled_model = generate_relu_compiled_model(device)
|
||||
output = compiled_model.output(*output_arguments)
|
||||
assert isinstance(output, ConstOutput)
|
||||
|
||||
|
||||
def test_input_set_friendly_name(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
compiled_model = generate_relu_compiled_model(device)
|
||||
net_input = compiled_model.input("data")
|
||||
input_node = net_input.get_node()
|
||||
input_node.set_friendly_name("input_1")
|
||||
@ -139,9 +98,7 @@ def test_input_set_friendly_name(device):
|
||||
|
||||
|
||||
def test_output_set_friendly_name(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
compiled_model = generate_relu_compiled_model(device)
|
||||
output = compiled_model.output(0)
|
||||
output_node = output.get_node()
|
||||
output_node.set_friendly_name("output_1")
|
||||
@ -151,200 +108,119 @@ def test_output_set_friendly_name(device):
|
||||
|
||||
|
||||
def test_outputs(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
compiled_model = generate_relu_compiled_model(device)
|
||||
outputs = compiled_model.outputs
|
||||
assert isinstance(outputs, list)
|
||||
assert len(outputs) == 1
|
||||
|
||||
|
||||
def test_outputs_items(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
outputs = compiled_model.outputs
|
||||
assert isinstance(outputs[0], ConstOutput)
|
||||
|
||||
|
||||
def test_output_type(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
compiled_model = generate_relu_compiled_model(device)
|
||||
output = compiled_model.output(0)
|
||||
output_type = output.get_element_type().get_type_name()
|
||||
assert output_type == "f32"
|
||||
|
||||
|
||||
def test_output_shape(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
compiled_model = generate_relu_compiled_model(device)
|
||||
output = compiled_model.output(0)
|
||||
expected_shape = Shape([1, 10])
|
||||
expected_shape = Shape([1, 3, 32, 32])
|
||||
assert str(output.get_shape()) == str(expected_shape)
|
||||
|
||||
|
||||
def test_input_get_index(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
compiled_model = generate_relu_compiled_model(device)
|
||||
net_input = compiled_model.input(0)
|
||||
expected_idx = 0
|
||||
assert net_input.get_index() == expected_idx
|
||||
assert net_input.get_index() == 0
|
||||
|
||||
|
||||
def test_inputs(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
compiled_model = generate_relu_compiled_model(device)
|
||||
inputs = compiled_model.inputs
|
||||
assert isinstance(inputs, list)
|
||||
assert len(inputs) == 1
|
||||
|
||||
|
||||
def test_inputs_items(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
inputs = compiled_model.inputs
|
||||
assert isinstance(inputs[0], ConstOutput)
|
||||
|
||||
|
||||
def test_inputs_get_friendly_name(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
inputs = compiled_model.inputs
|
||||
input_0 = inputs[0]
|
||||
node = input_0.get_node()
|
||||
compiled_model = generate_relu_compiled_model(device)
|
||||
node = compiled_model.inputs[0].get_node()
|
||||
name = node.friendly_name
|
||||
assert name == "data"
|
||||
|
||||
|
||||
def test_inputs_set_friendly_name(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
inputs = compiled_model.inputs
|
||||
input_0 = inputs[0]
|
||||
node = input_0.get_node()
|
||||
compiled_model = generate_relu_compiled_model(device)
|
||||
node = compiled_model.inputs[0].get_node()
|
||||
node.set_friendly_name("input_0")
|
||||
name = node.friendly_name
|
||||
assert name == "input_0"
|
||||
|
||||
|
||||
def test_inputs_docs(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
inputs = compiled_model.inputs
|
||||
input_0 = inputs[0]
|
||||
expected_string = "openvino.runtime.ConstOutput represents port/node output."
|
||||
assert input_0.__doc__ == expected_string
|
||||
compiled_model = generate_relu_compiled_model(device)
|
||||
|
||||
input_0 = compiled_model.inputs[0]
|
||||
assert input_0.__doc__ == "openvino.runtime.ConstOutput represents port/node output."
|
||||
|
||||
|
||||
def test_infer_new_request_numpy(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
img = generate_image()
|
||||
compiled_model = core.compile_model(model, device)
|
||||
compiled_model, img = generate_model_and_image(device)
|
||||
res = compiled_model.infer_new_request({"data": img})
|
||||
assert np.argmax(res[list(res)[0]]) == 9
|
||||
assert np.argmax(res[list(res)[0]]) == 531
|
||||
|
||||
|
||||
def test_infer_new_request_tensor_numpy_copy(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
img = generate_image()
|
||||
compiled_model, img = generate_model_and_image(device)
|
||||
|
||||
tensor = Tensor(img)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
res_tensor = compiled_model.infer_new_request({"data": tensor})
|
||||
res_img = compiled_model.infer_new_request({"data": img})
|
||||
assert np.argmax(res_tensor[list(res_tensor)[0]]) == 9
|
||||
assert np.argmax(res_tensor[list(res_tensor)[0]]) == 531
|
||||
assert np.argmax(res_tensor[list(res_tensor)[0]]) == np.argmax(res_img[list(res_img)[0]])
|
||||
|
||||
|
||||
def test_infer_tensor_numpy_shared_memory(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
img = generate_image()
|
||||
compiled_model, img = generate_model_and_image(device)
|
||||
|
||||
img = np.ascontiguousarray(img)
|
||||
tensor = Tensor(img, shared_memory=True)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
res_tensor = compiled_model.infer_new_request({"data": tensor})
|
||||
res_img = compiled_model.infer_new_request({"data": img})
|
||||
assert np.argmax(res_tensor[list(res_tensor)[0]]) == 9
|
||||
assert np.argmax(res_tensor[list(res_tensor)[0]]) == 531
|
||||
assert np.argmax(res_tensor[list(res_tensor)[0]]) == np.argmax(res_img[list(res_img)[0]])
|
||||
|
||||
|
||||
def test_infer_new_request_wrong_port_name(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
img = generate_image()
|
||||
compiled_model, img = generate_model_and_image(device)
|
||||
|
||||
tensor = Tensor(img)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
compiled_model.infer_new_request({"_data_": tensor})
|
||||
assert "Check" in str(e.value)
|
||||
|
||||
|
||||
def test_infer_tensor_wrong_input_data(device):
|
||||
core = Core()
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
img = generate_image()
|
||||
compiled_model, img = generate_model_and_image(device)
|
||||
|
||||
img = np.ascontiguousarray(img)
|
||||
tensor = Tensor(img, shared_memory=True)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
with pytest.raises(TypeError) as e:
|
||||
compiled_model.infer_new_request({0.: tensor})
|
||||
assert "Incompatible key type for input: 0.0" in str(e.value)
|
||||
|
||||
|
||||
def test_infer_numpy_model_from_buffer(device):
|
||||
core = Core()
|
||||
with open(test_net_bin, "rb") as f:
|
||||
weights = f.read()
|
||||
with open(test_net_xml, "rb") as f:
|
||||
xml = f.read()
|
||||
model = core.read_model(model=xml, weights=weights)
|
||||
img = generate_image()
|
||||
compiled_model = core.compile_model(model, device)
|
||||
res = compiled_model.infer_new_request({"data": img})
|
||||
assert np.argmax(res[list(res)[0]]) == 9
|
||||
|
||||
|
||||
def test_infer_tensor_model_from_buffer(device):
|
||||
core = Core()
|
||||
with open(test_net_bin, "rb") as f:
|
||||
weights = f.read()
|
||||
with open(test_net_xml, "rb") as f:
|
||||
xml = f.read()
|
||||
model = core.read_model(model=xml, weights=weights)
|
||||
img = generate_image()
|
||||
tensor = Tensor(img)
|
||||
compiled_model = core.compile_model(model, device)
|
||||
res = compiled_model.infer_new_request({"data": tensor})
|
||||
assert np.argmax(res[list(res)[0]]) == 9
|
||||
|
||||
|
||||
def test_direct_infer(device):
|
||||
core = Core()
|
||||
with open(test_net_bin, "rb") as f:
|
||||
weights = f.read()
|
||||
with open(test_net_xml, "rb") as f:
|
||||
xml = f.read()
|
||||
model = core.read_model(model=xml, weights=weights)
|
||||
img = generate_image()
|
||||
compiled_model, img = generate_model_and_image(device)
|
||||
|
||||
tensor = Tensor(img)
|
||||
comp_model = core.compile_model(model, device)
|
||||
res = comp_model({"data": tensor})
|
||||
assert np.argmax(res[comp_model.outputs[0]]) == 9
|
||||
ref = comp_model.infer_new_request({"data": tensor})
|
||||
assert np.array_equal(ref[comp_model.outputs[0]], res[comp_model.outputs[0]])
|
||||
res = compiled_model({"data": tensor})
|
||||
assert np.argmax(res[compiled_model.outputs[0]]) == 531
|
||||
ref = compiled_model.infer_new_request({"data": tensor})
|
||||
assert np.array_equal(ref[compiled_model.outputs[0]], res[compiled_model.outputs[0]])
|
||||
|
||||
|
||||
@pytest.mark.template_plugin()
|
||||
def test_compiled_model_after_core_destroyed(device):
|
||||
core = Core()
|
||||
with open(test_net_bin, "rb") as f:
|
||||
|
@ -5,10 +5,8 @@
|
||||
import pytest
|
||||
import numpy as np
|
||||
import os
|
||||
from sys import platform
|
||||
from pathlib import Path
|
||||
|
||||
import openvino.runtime.opset8 as ov
|
||||
from openvino.runtime import (
|
||||
Model,
|
||||
Core,
|
||||
@ -23,17 +21,18 @@ from openvino.runtime import (
|
||||
from tests.conftest import (
|
||||
model_path,
|
||||
model_onnx_path,
|
||||
plugins_path,
|
||||
get_model_with_template_extension,
|
||||
)
|
||||
|
||||
from tests.test_utils.test_utils import (
|
||||
generate_image,
|
||||
generate_relu_model,
|
||||
generate_relu_compiled_model,
|
||||
get_relu_model,
|
||||
generate_lib_name,
|
||||
plugins_path,
|
||||
)
|
||||
|
||||
|
||||
plugins_xml, plugins_win_xml, plugins_osx_xml = plugins_path()
|
||||
test_net_xml, test_net_bin = model_path()
|
||||
test_net_onnx = model_onnx_path()
|
||||
|
||||
@ -41,19 +40,15 @@ test_net_onnx = model_onnx_path()
|
||||
def test_compact_api_xml():
|
||||
img = generate_image()
|
||||
|
||||
model = compile_model(test_net_xml)
|
||||
assert isinstance(model, CompiledModel)
|
||||
results = model.infer_new_request({"data": img})
|
||||
assert np.argmax(results[list(results)[0]]) == 9
|
||||
compiled_model = compile_model(get_relu_model())
|
||||
assert isinstance(compiled_model, CompiledModel)
|
||||
results = compiled_model.infer_new_request({"data": img})
|
||||
assert np.argmax(results[list(results)[0]]) == 531
|
||||
|
||||
|
||||
def test_compact_api_xml_posix_path():
|
||||
img = generate_image()
|
||||
|
||||
model = compile_model(Path(test_net_xml))
|
||||
assert isinstance(model, CompiledModel)
|
||||
results = model.infer_new_request({"data": img})
|
||||
assert np.argmax(results[list(results)[0]]) == 9
|
||||
compiled_model = compile_model(Path(test_net_xml))
|
||||
assert isinstance(compiled_model, CompiledModel)
|
||||
|
||||
|
||||
def test_compact_api_wrong_path():
|
||||
@ -69,35 +64,17 @@ def test_compact_api_wrong_path():
|
||||
assert "Path: 'test class' does not exist. Please provide valid model's path either as a string, bytes or pathlib.Path" in str(e.value)
|
||||
|
||||
|
||||
def test_compact_api_onnx():
|
||||
img = generate_image()
|
||||
|
||||
model = compile_model(test_net_onnx)
|
||||
assert isinstance(model, CompiledModel)
|
||||
results = model.infer_new_request({"data": img})
|
||||
assert np.argmax(results[list(results)[0]]) == 9
|
||||
|
||||
|
||||
def test_compact_api_onnx_posix_path():
|
||||
img = generate_image()
|
||||
|
||||
model = compile_model(Path(test_net_onnx))
|
||||
assert isinstance(model, CompiledModel)
|
||||
results = model.infer_new_request({"data": img})
|
||||
assert np.argmax(results[list(results)[0]]) == 9
|
||||
|
||||
|
||||
def test_core_class():
|
||||
def test_core_class(device):
|
||||
input_shape = [1, 3, 4, 4]
|
||||
model = generate_relu_model(input_shape)
|
||||
compiled_model = generate_relu_compiled_model(device, input_shape=input_shape)
|
||||
|
||||
request = model.create_infer_request()
|
||||
request = compiled_model.create_infer_request()
|
||||
input_data = np.random.rand(*input_shape).astype(np.float32) - 0.5
|
||||
|
||||
expected_output = np.maximum(0.0, input_data)
|
||||
|
||||
input_tensor = Tensor(input_data)
|
||||
results = request.infer({"parameter": input_tensor})
|
||||
results = request.infer({"data": input_tensor})
|
||||
assert np.allclose(results[list(results)[0]], expected_output)
|
||||
|
||||
|
||||
@ -276,33 +253,30 @@ def test_query_model(device):
|
||||
assert [
|
||||
key for key in query_model.keys() if key not in ops_func_names
|
||||
] == [], "Not all network layers present in query_model results"
|
||||
assert next(iter(set(query_model.values()))) == device, "Wrong device for some layers"
|
||||
assert device in next(iter(set(query_model.values()))), "Wrong device for some layers"
|
||||
|
||||
|
||||
@pytest.mark.dynamic_library()
|
||||
@pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason="Device independent test")
|
||||
def test_register_plugin():
|
||||
def test_register_plugin(device):
|
||||
core = Core()
|
||||
core.register_plugin("openvino_intel_cpu_plugin", "BLA")
|
||||
full_device_name = core.get_property(device, "FULL_DEVICE_NAME")
|
||||
lib_name = generate_lib_name(device, full_device_name)
|
||||
core.register_plugin(lib_name, "BLA")
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
exec_net = core.compile_model(model, "BLA")
|
||||
assert isinstance(exec_net, CompiledModel), "Cannot load the network to the registered plugin with name 'BLA'"
|
||||
compiled_model = core.compile_model(model, "BLA")
|
||||
assert isinstance(compiled_model, CompiledModel), "Cannot load the network to the registered plugin with name 'BLA'"
|
||||
|
||||
|
||||
@pytest.mark.dynamic_library()
|
||||
@pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason="Device independent test")
|
||||
def test_register_plugins():
|
||||
def test_register_plugins(device):
|
||||
core = Core()
|
||||
if platform == "linux" or platform == "linux2":
|
||||
core.register_plugins(plugins_xml)
|
||||
elif platform == "darwin":
|
||||
core.register_plugins(plugins_osx_xml)
|
||||
elif platform == "win32":
|
||||
core.register_plugins(plugins_win_xml)
|
||||
|
||||
full_device_name = core.get_property(device, "FULL_DEVICE_NAME")
|
||||
plugins_xml = plugins_path(device, full_device_name)
|
||||
core.register_plugins(plugins_xml)
|
||||
model = core.read_model(model=test_net_xml, weights=test_net_bin)
|
||||
exec_net = core.compile_model(model, "CUSTOM")
|
||||
assert isinstance(exec_net, CompiledModel), (
|
||||
compiled_model = core.compile_model(model, "CUSTOM")
|
||||
os.remove(plugins_xml)
|
||||
assert isinstance(compiled_model, CompiledModel), (
|
||||
"Cannot load the network to "
|
||||
"the registered plugin with name 'CUSTOM' "
|
||||
"registered in the XML file"
|
||||
@ -336,8 +310,8 @@ def test_add_extension_template_extension(device):
|
||||
model.reshape(new_shapes)
|
||||
# compile to check objects can be destroyed
|
||||
# in order core -> model -> compiled
|
||||
compiled = core.compile_model(model, device)
|
||||
assert compiled.input().partial_shape == after_reshape
|
||||
compiled_model = core.compile_model(model, device)
|
||||
assert compiled_model.input().partial_shape == after_reshape
|
||||
|
||||
|
||||
def test_add_extension():
|
||||
|
@ -16,7 +16,7 @@ from openvino.runtime import Type, PartialShape, Shape, Layout
|
||||
from openvino.preprocess import PrePostProcessor
|
||||
|
||||
from tests.conftest import model_path
|
||||
from tests.test_utils.test_utils import generate_image
|
||||
from tests.test_utils.test_utils import generate_image, get_relu_model
|
||||
|
||||
is_myriad = os.environ.get("TEST_DEVICE") == "MYRIAD"
|
||||
test_net_xml, test_net_bin = model_path(is_myriad)
|
||||
@ -98,7 +98,7 @@ def test_get_profiling_info(device):
|
||||
assert request.latency > 0
|
||||
prof_info = request.get_profiling_info()
|
||||
soft_max_node = next(node for node in prof_info if node.node_name == "fc_out")
|
||||
assert soft_max_node.node_type == "Softmax"
|
||||
assert "Softmax" in soft_max_node.node_type
|
||||
assert soft_max_node.status == ProfilingInfo.Status.EXECUTED
|
||||
assert isinstance(soft_max_node.real_time, datetime.timedelta)
|
||||
assert isinstance(soft_max_node.cpu_time, datetime.timedelta)
|
||||
@ -107,7 +107,8 @@ def test_get_profiling_info(device):
|
||||
|
||||
def test_tensor_setter(device):
|
||||
core = Core()
|
||||
model = core.read_model(test_net_xml, test_net_bin)
|
||||
model = get_relu_model()
|
||||
|
||||
compiled_1 = core.compile_model(model=model, device_name=device)
|
||||
compiled_2 = core.compile_model(model=model, device_name=device)
|
||||
compiled_3 = core.compile_model(model=model, device_name=device)
|
||||
@ -124,12 +125,12 @@ def test_tensor_setter(device):
|
||||
res = request1.infer({0: tensor})
|
||||
key = list(res)[0]
|
||||
res_1 = np.sort(res[key])
|
||||
t2 = request1.get_tensor("fc_out")
|
||||
t2 = request1.get_output_tensor()
|
||||
assert np.allclose(t2.data, res[key].data, atol=1e-2, rtol=1e-2)
|
||||
|
||||
request = compiled_2.create_infer_request()
|
||||
res = request.infer({"data": tensor})
|
||||
res_2 = np.sort(request.get_tensor("fc_out").data)
|
||||
res_2 = np.sort(request.get_output_tensor().data)
|
||||
assert np.allclose(res_1, res_2, atol=1e-2, rtol=1e-2)
|
||||
|
||||
request.set_tensor("data", tensor)
|
||||
@ -204,6 +205,9 @@ def test_set_tensors(device):
|
||||
|
||||
def test_batched_tensors(device):
|
||||
core = Core()
|
||||
if device == "CPU":
|
||||
if "Intel" not in core.get_property(device, "FULL_DEVICE_NAME"):
|
||||
pytest.skip("Can't run on ARM plugin")
|
||||
|
||||
batch = 4
|
||||
one_shape = [1, 2, 2, 2]
|
||||
@ -349,9 +353,8 @@ def test_infer_list_as_inputs(device):
|
||||
|
||||
def test_infer_mixed_keys(device):
|
||||
core = Core()
|
||||
model = core.read_model(test_net_xml, test_net_bin)
|
||||
core.set_property(device, {"PERF_COUNT": "YES"})
|
||||
model = core.compile_model(model, device)
|
||||
model = get_relu_model()
|
||||
compiled_model = core.compile_model(model, device)
|
||||
|
||||
img = generate_image()
|
||||
tensor = Tensor(img)
|
||||
@ -359,9 +362,9 @@ def test_infer_mixed_keys(device):
|
||||
data2 = np.ones(shape=img.shape, dtype=np.float32)
|
||||
tensor2 = Tensor(data2)
|
||||
|
||||
request = model.create_infer_request()
|
||||
request = compiled_model.create_infer_request()
|
||||
res = request.infer({0: tensor2, "data": tensor})
|
||||
assert np.argmax(res[model.output()]) == 9
|
||||
assert np.argmax(res[compiled_model.output()]) == 531
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("ov_type", "numpy_dtype"), [
|
||||
@ -470,6 +473,8 @@ def test_infer_queue(device):
|
||||
|
||||
img = generate_image()
|
||||
infer_queue.set_callback(callback)
|
||||
assert infer_queue.is_ready()
|
||||
|
||||
for i in range(jobs):
|
||||
infer_queue.start_async({"data": img}, i)
|
||||
infer_queue.wait_all()
|
||||
@ -477,23 +482,6 @@ def test_infer_queue(device):
|
||||
assert all(job["latency"] > 0 for job in jobs_done)
|
||||
|
||||
|
||||
def test_infer_queue_is_ready(device):
|
||||
core = Core()
|
||||
param = ops.parameter([10])
|
||||
model = Model(ops.relu(param), [param])
|
||||
compiled_model = core.compile_model(model, device)
|
||||
infer_queue = AsyncInferQueue(compiled_model, 1)
|
||||
|
||||
def callback(request, _):
|
||||
time.sleep(0.001)
|
||||
|
||||
infer_queue.set_callback(callback)
|
||||
assert infer_queue.is_ready()
|
||||
infer_queue.start_async()
|
||||
assert not infer_queue.is_ready()
|
||||
infer_queue.wait_all()
|
||||
|
||||
|
||||
def test_infer_queue_iteration(device):
|
||||
core = Core()
|
||||
param = ops.parameter([10])
|
||||
@ -578,10 +566,10 @@ def test_infer_queue_fail_in_inference(device, with_callback):
|
||||
jobs = 6
|
||||
num_request = 4
|
||||
core = Core()
|
||||
data = ops.parameter([5, 2], dtype=np.float32, name="data")
|
||||
indexes = ops.parameter(Shape([3, 2]), dtype=np.int32, name="indexes")
|
||||
emb = ops.embedding_bag_packed_sum(data, indexes)
|
||||
model = Model(emb, [data, indexes])
|
||||
data = ops.parameter([10], dtype=np.float32, name="data")
|
||||
k_op = ops.parameter(Shape([]), dtype=np.int32, name="k")
|
||||
emb = ops.topk(data, k_op, axis=0, mode="max", sort="value")
|
||||
model = Model(emb, [data, k_op])
|
||||
compiled_model = core.compile_model(model, device)
|
||||
infer_queue = AsyncInferQueue(compiled_model, num_request)
|
||||
|
||||
@ -591,15 +579,15 @@ def test_infer_queue_fail_in_inference(device, with_callback):
|
||||
if with_callback:
|
||||
infer_queue.set_callback(callback)
|
||||
|
||||
data_tensor = Tensor(np.arange(10).reshape((5, 2)).astype(np.float32))
|
||||
indexes_tensor = Tensor(np.array([[100, 101], [102, 103], [104, 105]], dtype=np.int32))
|
||||
data_tensor = Tensor(np.arange(10).astype(np.float32))
|
||||
k_tensor = Tensor(np.array(11, dtype=np.int32))
|
||||
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
for _ in range(jobs):
|
||||
infer_queue.start_async({"data": data_tensor, "indexes": indexes_tensor})
|
||||
infer_queue.start_async({"data": data_tensor, "k": k_tensor})
|
||||
infer_queue.wait_all()
|
||||
|
||||
assert "has invalid embedding bag index:" in str(e.value)
|
||||
assert "Can not clone with new dims" in str(e.value)
|
||||
|
||||
|
||||
def test_infer_queue_get_idle_handle(device):
|
||||
@ -693,7 +681,7 @@ def test_results_async_infer(device):
|
||||
jobs = 8
|
||||
num_request = 4
|
||||
core = Core()
|
||||
model = core.read_model(test_net_xml, test_net_bin)
|
||||
model = get_relu_model()
|
||||
compiled_model = core.compile_model(model, device)
|
||||
infer_queue = AsyncInferQueue(compiled_model, num_request)
|
||||
jobs_done = [{"finished": False, "latency": 0} for _ in range(jobs)]
|
||||
|
@ -273,17 +273,16 @@ def test_properties_hint_model():
|
||||
assert property_tuple[0] == "MODEL_PTR"
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason=f"Cannot run test on device {os.environ.get('TEST_DEVICE')}, Plugin specific test")
|
||||
def test_single_property_setting():
|
||||
def test_single_property_setting(device):
|
||||
core = Core()
|
||||
|
||||
if "Intel" not in core.get_property("CPU", "FULL_DEVICE_NAME"):
|
||||
if device == "CPU" and "Intel" not in core.get_property(device, "FULL_DEVICE_NAME"):
|
||||
pytest.skip("This test runs only on openvino intel cpu plugin")
|
||||
|
||||
core.set_property("CPU", properties.streams.num(properties.streams.Num.AUTO))
|
||||
core.set_property(device, properties.streams.num(properties.streams.Num.AUTO))
|
||||
|
||||
assert properties.streams.Num.AUTO.to_integer() == -1
|
||||
assert type(core.get_property("CPU", properties.streams.num())) == int
|
||||
assert type(core.get_property(device, properties.streams.num())) == int
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason=f"Cannot run test on device {os.environ.get('TEST_DEVICE')}, Plugin specific test")
|
||||
@ -327,7 +326,7 @@ def test_single_property_setting():
|
||||
},
|
||||
],
|
||||
)
|
||||
def test_properties_core(properties_to_set):
|
||||
def test_core_cpu_properties(properties_to_set):
|
||||
core = Core()
|
||||
|
||||
if "Intel" not in core.get_property("CPU", "FULL_DEVICE_NAME"):
|
||||
@ -335,18 +334,11 @@ def test_properties_core(properties_to_set):
|
||||
|
||||
core.set_property(properties_to_set)
|
||||
|
||||
# RW properties without device name
|
||||
assert core.get_property(properties.cache_dir()) == "./"
|
||||
assert core.get_property(properties.force_tbb_terminate()) is False
|
||||
|
||||
# RW properties
|
||||
assert core.get_property("CPU", properties.enable_profiling()) is True
|
||||
assert core.get_property("CPU", properties.cache_dir()) == "./"
|
||||
assert core.get_property("CPU", properties.inference_num_threads()) == 9
|
||||
assert core.get_property("CPU", properties.affinity()) == properties.Affinity.NONE
|
||||
assert core.get_property("CPU", properties.hint.inference_precision()) == Type.f32
|
||||
assert core.get_property("CPU", properties.hint.performance_mode()) == properties.hint.PerformanceMode.LATENCY
|
||||
assert core.get_property("CPU", properties.hint.num_requests()) == 12
|
||||
assert core.get_property("CPU", properties.streams.num()) == 5
|
||||
|
||||
# RO properties
|
||||
|
@ -4,11 +4,11 @@
|
||||
from openvino.runtime import opset8
|
||||
from openvino.runtime.passes import Manager, GraphRewrite, MatcherPass, WrapType, Matcher
|
||||
|
||||
from tests.test_transformations.utils.utils import count_ops, get_test_model, PatternReplacement
|
||||
from tests.test_transformations.utils.utils import count_ops, get_relu_model, PatternReplacement
|
||||
|
||||
|
||||
def test_graph_rewrite():
|
||||
model = get_test_model()
|
||||
model = get_relu_model()
|
||||
|
||||
manager = Manager()
|
||||
# check that register pass returns pass instance
|
||||
@ -68,7 +68,7 @@ def test_register_new_node():
|
||||
manager = Manager()
|
||||
ins = manager.register_pass(InsertExp())
|
||||
rem = manager.register_pass(RemoveExp())
|
||||
manager.run_passes(get_test_model())
|
||||
manager.run_passes(get_relu_model())
|
||||
|
||||
assert ins.model_changed
|
||||
assert rem.model_changed
|
||||
|
@ -5,7 +5,7 @@ from openvino.runtime import opset8
|
||||
from openvino.runtime.passes import Manager, Matcher, MatcherPass, WrapType
|
||||
from openvino.runtime.utils import replace_node
|
||||
|
||||
from tests.test_transformations.utils.utils import count_ops, get_test_model, PatternReplacement
|
||||
from tests.test_transformations.utils.utils import count_ops, get_relu_model, PatternReplacement
|
||||
|
||||
|
||||
def test_simple_pattern_replacement():
|
||||
@ -27,7 +27,7 @@ def test_simple_pattern_replacement():
|
||||
|
||||
return Matcher(relu, "SimpleReplacement"), callback
|
||||
|
||||
model = get_test_model()
|
||||
model = get_relu_model()
|
||||
|
||||
manager = Manager()
|
||||
manager.register_pass(MatcherPass(*pattern_replacement()))
|
||||
@ -37,7 +37,7 @@ def test_simple_pattern_replacement():
|
||||
|
||||
|
||||
def test_matcher_pass():
|
||||
model = get_test_model()
|
||||
model = get_relu_model()
|
||||
|
||||
manager = Manager()
|
||||
# check that register pass returns pass instance
|
||||
@ -49,7 +49,7 @@ def test_matcher_pass():
|
||||
|
||||
|
||||
def test_matcher_pass_apply():
|
||||
model = get_test_model()
|
||||
model = get_relu_model()
|
||||
|
||||
pattern_replacement = PatternReplacement()
|
||||
pattern_replacement.apply(model.get_result().input_value(0).get_node())
|
||||
|
@ -3,12 +3,12 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
from openvino.runtime.passes import Manager
|
||||
|
||||
from tests.test_transformations.utils.utils import get_test_model, MyModelPass
|
||||
from tests.test_transformations.utils.utils import get_relu_model, MyModelPass
|
||||
|
||||
|
||||
def test_model_pass():
|
||||
manager = Manager()
|
||||
model_pass = manager.register_pass(MyModelPass())
|
||||
manager.run_passes(get_test_model())
|
||||
manager.run_passes(get_relu_model())
|
||||
|
||||
assert model_pass.model_changed
|
||||
|
@ -23,7 +23,7 @@ import openvino.runtime as ov
|
||||
from tests.test_utils.test_utils import create_filename_for_test
|
||||
|
||||
|
||||
def get_test_model():
|
||||
def get_relu_model():
|
||||
param = ov.opset8.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
|
||||
param.get_output_tensor(0).set_names({"parameter"})
|
||||
relu = ov.opset8.relu(param)
|
||||
@ -97,7 +97,7 @@ def get_gru_sequence_model():
|
||||
|
||||
|
||||
def test_moc_transformations():
|
||||
model = get_test_model()
|
||||
model = get_relu_model()
|
||||
|
||||
apply_moc_transformations(model, False)
|
||||
|
||||
@ -106,7 +106,7 @@ def test_moc_transformations():
|
||||
|
||||
|
||||
def test_moc_with_smart_reshape():
|
||||
model = get_test_model()
|
||||
model = get_relu_model()
|
||||
|
||||
apply_moc_transformations(model, cf=False, smart_reshape=True)
|
||||
|
||||
@ -115,7 +115,7 @@ def test_moc_with_smart_reshape():
|
||||
|
||||
|
||||
def test_pot_transformations():
|
||||
model = get_test_model()
|
||||
model = get_relu_model()
|
||||
|
||||
apply_pot_transformations(model, "GNA")
|
||||
|
||||
@ -124,7 +124,7 @@ def test_pot_transformations():
|
||||
|
||||
|
||||
def test_low_latency_transformation():
|
||||
model = get_test_model()
|
||||
model = get_relu_model()
|
||||
|
||||
apply_low_latency_transformation(model, True)
|
||||
|
||||
@ -133,7 +133,7 @@ def test_low_latency_transformation():
|
||||
|
||||
|
||||
def test_pruning_transformation():
|
||||
model = get_test_model()
|
||||
model = get_relu_model()
|
||||
|
||||
apply_pruning_transformation(model)
|
||||
|
||||
@ -142,7 +142,7 @@ def test_pruning_transformation():
|
||||
|
||||
|
||||
def test_make_stateful_transformations():
|
||||
model = get_test_model()
|
||||
model = get_relu_model()
|
||||
|
||||
apply_make_stateful_transformation(model, {"parameter": "result"})
|
||||
|
||||
@ -152,7 +152,7 @@ def test_make_stateful_transformations():
|
||||
|
||||
|
||||
def test_fused_names_cleanup():
|
||||
model = get_test_model()
|
||||
model = get_relu_model()
|
||||
|
||||
for node in model.get_ops():
|
||||
node.get_rt_info()["fused_names_0"] = "test_op_name"
|
||||
@ -252,7 +252,7 @@ def test_serialize_default_bin(request, is_path_xml, is_path_bin):
|
||||
xml_path, bin_path = create_filename_for_test(request.node.name,
|
||||
is_path_xml,
|
||||
is_path_bin)
|
||||
model = get_test_model()
|
||||
model = get_relu_model()
|
||||
serialize(model, xml_path)
|
||||
assert os.path.exists(bin_path)
|
||||
os.remove(xml_path)
|
||||
|
@ -15,7 +15,7 @@ from openvino.runtime.passes import (
|
||||
LowLatency2,
|
||||
Serialize,
|
||||
)
|
||||
from tests.test_transformations.utils.utils import count_ops, get_test_model
|
||||
from tests.test_transformations.utils.utils import count_ops, get_relu_model
|
||||
from tests.test_utils.test_utils import create_filename_for_test
|
||||
|
||||
|
||||
@ -117,7 +117,7 @@ def test_serialize_pass(request, is_path_xml, is_path_bin):
|
||||
is_path_xml,
|
||||
is_path_bin)
|
||||
|
||||
func = get_test_model()
|
||||
func = get_relu_model()
|
||||
|
||||
manager = Manager()
|
||||
manager.register_pass(Serialize(xml_path, bin_path))
|
||||
|
@ -6,7 +6,7 @@ from openvino.runtime import Model, PartialShape, opset8
|
||||
from openvino.runtime.utils import replace_node, replace_output_update_name
|
||||
|
||||
|
||||
def get_test_model():
|
||||
def get_relu_model():
|
||||
# Parameter->Relu->Result
|
||||
param = opset8.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
|
||||
relu = opset8.relu(param.output(0))
|
||||
|
@ -6,7 +6,7 @@ from openvino.runtime import Model, PartialShape, opset8
|
||||
from openvino.runtime.passes import ModelPass, Matcher, MatcherPass, WrapType
|
||||
|
||||
|
||||
def get_test_model():
|
||||
def get_relu_model():
|
||||
# Parameter->Relu->Result
|
||||
param = opset8.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
|
||||
relu = opset8.relu(param.output(0))
|
||||
|
@ -4,49 +4,94 @@
|
||||
|
||||
from typing import Tuple, Union, List
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from platform import processor
|
||||
|
||||
import openvino
|
||||
import openvino.runtime.opset8 as ops
|
||||
import pytest
|
||||
from openvino.runtime import Model, Core, Shape, Type
|
||||
from openvino.runtime.op import Parameter
|
||||
from openvino.runtime import Model, Core, Shape
|
||||
from openvino.utils import deprecated
|
||||
|
||||
|
||||
def get_test_model():
|
||||
element_type = Type.f32
|
||||
param = Parameter(element_type, Shape([1, 3, 22, 22]))
|
||||
relu = ops.relu(param)
|
||||
model = Model([relu], [param], "test")
|
||||
assert model is not None
|
||||
return model
|
||||
|
||||
|
||||
def test_compare_models():
|
||||
try:
|
||||
from openvino.test_utils import compare_models
|
||||
model = get_test_model()
|
||||
model = get_relu_model()
|
||||
status, _ = compare_models(model, model)
|
||||
assert status
|
||||
except RuntimeError:
|
||||
print("openvino.test_utils.compare_models is not available") # noqa: T201
|
||||
|
||||
|
||||
def generate_lib_name(device, full_device_name):
|
||||
lib_name = ""
|
||||
arch = processor()
|
||||
if arch == "x86_64" or "Intel" in full_device_name or device in ["GNA", "HDDL", "MYRIAD", "VPUX"]:
|
||||
lib_name = "openvino_intel_" + device.lower() + "_plugin"
|
||||
elif arch != "x86_64" and device == "CPU":
|
||||
lib_name = "openvino_arm_cpu_plugin"
|
||||
elif device in ["HETERO", "MULTI", "AUTO"]:
|
||||
lib_name = "openvino_" + device.lower() + "_plugin"
|
||||
return lib_name
|
||||
|
||||
|
||||
def plugins_path(device, full_device_name):
|
||||
lib_name = generate_lib_name(device, full_device_name)
|
||||
full_lib_name = ""
|
||||
|
||||
if sys.platform == "win32":
|
||||
full_lib_name = lib_name + ".dll"
|
||||
else:
|
||||
full_lib_name = "lib" + lib_name + ".so"
|
||||
|
||||
plugin_xml = f"""<ie>
|
||||
<plugins>
|
||||
<plugin location="{full_lib_name}" name="CUSTOM">
|
||||
</plugin>
|
||||
</plugins>
|
||||
</ie>"""
|
||||
|
||||
with open("plugin_path.xml", "w") as f:
|
||||
f.write(plugin_xml)
|
||||
|
||||
plugins_paths = os.path.join(os.getcwd(), "plugin_path.xml")
|
||||
return plugins_paths
|
||||
|
||||
|
||||
def generate_image(shape: Tuple = (1, 3, 32, 32), dtype: Union[str, np.dtype] = "float32") -> np.array:
|
||||
np.random.seed(42)
|
||||
return np.random.rand(*shape).astype(dtype)
|
||||
|
||||
|
||||
def generate_relu_model(input_shape: List[int]) -> openvino.runtime.ie_api.CompiledModel:
|
||||
param = ops.parameter(input_shape, np.float32, name="parameter")
|
||||
def get_relu_model(input_shape: List[int] = None) -> openvino.runtime.Model:
|
||||
if input_shape is None:
|
||||
input_shape = [1, 3, 32, 32]
|
||||
param = ops.parameter(input_shape, np.float32, name="data")
|
||||
relu = ops.relu(param, name="relu")
|
||||
model = Model([relu], [param], "test")
|
||||
model = Model([relu], [param], "test_model")
|
||||
model.get_ordered_ops()[2].friendly_name = "friendly"
|
||||
|
||||
assert model is not None
|
||||
return model
|
||||
|
||||
|
||||
def generate_relu_compiled_model(device, input_shape: List[int] = None) -> openvino.runtime.CompiledModel:
|
||||
if input_shape is None:
|
||||
input_shape = [1, 3, 32, 32]
|
||||
model = get_relu_model(input_shape)
|
||||
core = Core()
|
||||
return core.compile_model(model, "CPU", {})
|
||||
return core.compile_model(model, device, {})
|
||||
|
||||
|
||||
def generate_model_and_image(device, input_shape: List[int] = None):
|
||||
if input_shape is None:
|
||||
input_shape = [1, 3, 32, 32]
|
||||
return (generate_relu_compiled_model(device, input_shape), generate_image(input_shape))
|
||||
|
||||
|
||||
def generate_add_model() -> openvino._pyopenvino.Model:
|
||||
|
@ -1,11 +0,0 @@
|
||||
<!--
|
||||
Copyright (C) 2020 Intel Corporation
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
|
||||
<ie>
|
||||
<plugins>
|
||||
<plugin location="libopenvino_intel_cpu_plugin.so" name="CUSTOM">
|
||||
</plugin>
|
||||
</plugins>
|
||||
</ie>
|
@ -1,11 +0,0 @@
|
||||
<!--
|
||||
Copyright (C) 2020 Intel Corporation
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
|
||||
<ie>
|
||||
<plugins>
|
||||
<plugin location="libopenvino_intel_cpu_plugin.so" name="CUSTOM">
|
||||
</plugin>
|
||||
</plugins>
|
||||
</ie>
|
@ -1,11 +0,0 @@
|
||||
<!--
|
||||
Copyright (C) 2020 Intel Corporation
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
|
||||
<ie>
|
||||
<plugins>
|
||||
<plugin location="openvino_intel_cpu_plugin.dll" name="CUSTOM">
|
||||
</plugin>
|
||||
</plugins>
|
||||
</ie>
|
@ -8,7 +8,7 @@ import time
|
||||
|
||||
from openvino.inference_engine import ie_api as ie
|
||||
from tests_compatibility.conftest import model_path
|
||||
from tests_compatibility.test_utils.test_utils import generate_image
|
||||
from tests_compatibility.test_utils.test_utils import generate_image, generate_relu_model
|
||||
|
||||
|
||||
is_myriad = os.environ.get("TEST_DEVICE") == "MYRIAD"
|
||||
@ -17,34 +17,15 @@ test_net_xml, test_net_bin = model_path(is_myriad)
|
||||
|
||||
def test_infer(device):
|
||||
ie_core = ie.IECore()
|
||||
net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
|
||||
net = generate_relu_model([1, 3, 32, 32])
|
||||
exec_net = ie_core.load_network(net, device)
|
||||
img = generate_image()
|
||||
res = exec_net.infer({'data': img})
|
||||
assert np.argmax(res['fc_out'][0]) == 9
|
||||
res = exec_net.infer({'parameter': img})
|
||||
assert np.argmax(res['relu'][0]) == 531
|
||||
del exec_net
|
||||
del ie_core
|
||||
|
||||
|
||||
def test_infer_net_from_buffer(device):
|
||||
ie_core = ie.IECore()
|
||||
with open(test_net_bin, 'rb') as f:
|
||||
bin = f.read()
|
||||
with open(test_net_xml, 'rb') as f:
|
||||
xml = f.read()
|
||||
net = ie_core.read_network(model=xml, weights=bin, init_from_buffer=True)
|
||||
net2 = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
|
||||
exec_net = ie_core.load_network(net, device)
|
||||
exec_net2 = ie_core.load_network(net2, device)
|
||||
img = generate_image()
|
||||
res = exec_net.infer({'data': img})
|
||||
res2 = exec_net2.infer({'data': img})
|
||||
del ie_core
|
||||
del exec_net
|
||||
del exec_net2
|
||||
assert np.allclose(res['fc_out'], res2['fc_out'], atol=1E-4, rtol=1E-4)
|
||||
|
||||
|
||||
def test_infer_wrong_input_name(device):
|
||||
ie_core = ie.IECore()
|
||||
net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
|
||||
@ -92,34 +73,34 @@ def test_access_requests(device):
|
||||
|
||||
def test_async_infer_one_req(device):
|
||||
ie_core = ie.IECore()
|
||||
net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
|
||||
net = generate_relu_model([1, 3, 32, 32])
|
||||
exec_net = ie_core.load_network(net, device, num_requests=1)
|
||||
img = generate_image()
|
||||
request_handler = exec_net.start_async(request_id=0, inputs={'data': img})
|
||||
request_handler = exec_net.start_async(request_id=0, inputs={'parameter': img})
|
||||
request_handler.wait()
|
||||
res = request_handler.output_blobs['fc_out'].buffer
|
||||
assert np.argmax(res) == 9
|
||||
res = request_handler.output_blobs['relu'].buffer
|
||||
assert np.argmax(res) == 531
|
||||
del exec_net
|
||||
del ie_core
|
||||
|
||||
|
||||
def test_async_infer_many_req(device):
|
||||
ie_core = ie.IECore()
|
||||
net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
|
||||
net = generate_relu_model([1, 3, 32, 32])
|
||||
exec_net = ie_core.load_network(net, device, num_requests=5)
|
||||
img = generate_image()
|
||||
for id in range(5):
|
||||
request_handler = exec_net.start_async(request_id=id, inputs={'data': img})
|
||||
request_handler = exec_net.start_async(request_id=id, inputs={'parameter': img})
|
||||
request_handler.wait()
|
||||
res = request_handler.output_blobs['fc_out'].buffer
|
||||
assert np.argmax(res) == 9
|
||||
res = request_handler.output_blobs['relu'].buffer
|
||||
assert np.argmax(res) == 531
|
||||
del exec_net
|
||||
del ie_core
|
||||
|
||||
|
||||
def test_async_infer_many_req_get_idle(device):
|
||||
ie_core = ie.IECore()
|
||||
net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
|
||||
net = generate_relu_model([1, 3, 32, 32])
|
||||
num_requests = 5
|
||||
exec_net = ie_core.load_network(net, device, num_requests=num_requests)
|
||||
img = generate_image()
|
||||
@ -131,20 +112,20 @@ def test_async_infer_many_req_get_idle(device):
|
||||
assert(status == ie.StatusCode.OK)
|
||||
request_id = exec_net.get_idle_request_id()
|
||||
assert(request_id >= 0)
|
||||
request_handler = exec_net.start_async(request_id=request_id, inputs={'data': img})
|
||||
request_handler = exec_net.start_async(request_id=request_id, inputs={'parameter': img})
|
||||
check_id.add(request_id)
|
||||
status = exec_net.wait(timeout=ie.WaitMode.RESULT_READY)
|
||||
assert status == ie.StatusCode.OK
|
||||
for id in range(num_requests):
|
||||
if id in check_id:
|
||||
assert np.argmax(exec_net.requests[id].output_blobs['fc_out'].buffer) == 9
|
||||
assert np.argmax(exec_net.requests[id].output_blobs['relu'].buffer) == 531
|
||||
del exec_net
|
||||
del ie_core
|
||||
|
||||
|
||||
def test_wait_before_start(device):
|
||||
ie_core = ie.IECore()
|
||||
net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
|
||||
net = generate_relu_model([1, 3, 32, 32])
|
||||
num_requests = 5
|
||||
exec_net = ie_core.load_network(net, device, num_requests=num_requests)
|
||||
img = generate_image()
|
||||
@ -152,10 +133,10 @@ def test_wait_before_start(device):
|
||||
for id in range(num_requests):
|
||||
status = requests[id].wait()
|
||||
assert status == ie.StatusCode.INFER_NOT_STARTED
|
||||
request_handler = exec_net.start_async(request_id=id, inputs={'data': img})
|
||||
request_handler = exec_net.start_async(request_id=id, inputs={'parameter': img})
|
||||
status = requests[id].wait()
|
||||
assert status == ie.StatusCode.OK
|
||||
assert np.argmax(request_handler.output_blobs['fc_out'].buffer) == 9
|
||||
assert np.argmax(request_handler.output_blobs['relu'].buffer) == 531
|
||||
del exec_net
|
||||
del ie_core
|
||||
|
||||
@ -214,11 +195,11 @@ def test_wrong_num_requests_core(device):
|
||||
|
||||
def test_plugin_accessible_after_deletion(device):
|
||||
ie_core = ie.IECore()
|
||||
net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
|
||||
net = generate_relu_model([1, 3, 32, 32])
|
||||
exec_net = ie_core.load_network(net, device)
|
||||
img = generate_image()
|
||||
res = exec_net.infer({'data': img})
|
||||
assert np.argmax(res['fc_out'][0]) == 9
|
||||
res = exec_net.infer({'parameter': img})
|
||||
assert np.argmax(res['relu'][0]) == 531
|
||||
del exec_net
|
||||
del ie_core
|
||||
|
||||
|
@ -10,7 +10,7 @@ import time
|
||||
|
||||
from openvino.inference_engine import ie_api as ie
|
||||
from tests_compatibility.conftest import model_path, create_encoder
|
||||
from tests_compatibility.test_utils.test_utils import generate_image
|
||||
from tests_compatibility.test_utils.test_utils import generate_image, generate_relu_model
|
||||
import ngraph as ng
|
||||
from ngraph.impl import Function, Type
|
||||
|
||||
@ -129,13 +129,13 @@ def test_write_to_input_blobs_copy(device):
|
||||
|
||||
def test_infer(device):
|
||||
ie_core = ie.IECore()
|
||||
net = ie_core.read_network(test_net_xml, test_net_bin)
|
||||
net = generate_relu_model([1, 3, 32, 32])
|
||||
exec_net = ie_core.load_network(net, device, num_requests=1)
|
||||
img = generate_image()
|
||||
request = exec_net.requests[0]
|
||||
request.infer({'data': img})
|
||||
res = request.output_blobs['fc_out'].buffer
|
||||
assert np.argmax(res) == 9
|
||||
request.infer({'parameter': img})
|
||||
res = request.output_blobs['relu'].buffer
|
||||
assert np.argmax(res) == 531
|
||||
del exec_net
|
||||
del ie_core
|
||||
del net
|
||||
@ -143,14 +143,14 @@ def test_infer(device):
|
||||
|
||||
def test_async_infer_default_timeout(device):
|
||||
ie_core = ie.IECore()
|
||||
net = ie_core.read_network(test_net_xml, test_net_bin)
|
||||
net = generate_relu_model([1, 3, 32, 32])
|
||||
exec_net = ie_core.load_network(net, device, num_requests=1)
|
||||
img = generate_image()
|
||||
request = exec_net.requests[0]
|
||||
request.async_infer({'data': img})
|
||||
request.async_infer({'parameter': img})
|
||||
request.wait()
|
||||
res = request.output_blobs['fc_out'].buffer
|
||||
assert np.argmax(res) == 9
|
||||
res = request.output_blobs['relu'].buffer
|
||||
assert np.argmax(res) == 531
|
||||
del exec_net
|
||||
del ie_core
|
||||
del net
|
||||
@ -158,14 +158,14 @@ def test_async_infer_default_timeout(device):
|
||||
|
||||
def test_async_infer_wait_finish(device):
|
||||
ie_core = ie.IECore()
|
||||
net = ie_core.read_network(test_net_xml, test_net_bin)
|
||||
net = generate_relu_model([1, 3, 32, 32])
|
||||
exec_net = ie_core.load_network(net, device, num_requests=1)
|
||||
img = generate_image()
|
||||
request = exec_net.requests[0]
|
||||
request.async_infer({'data': img})
|
||||
request.async_infer({'parameter': img})
|
||||
request.wait(ie.WaitMode.RESULT_READY)
|
||||
res = request.output_blobs['fc_out'].buffer
|
||||
assert np.argmax(res) == 9
|
||||
res = request.output_blobs['relu'].buffer
|
||||
assert np.argmax(res) == 531
|
||||
del exec_net
|
||||
del ie_core
|
||||
del net
|
||||
@ -173,11 +173,11 @@ def test_async_infer_wait_finish(device):
|
||||
|
||||
def test_async_infer_wait_time(device):
|
||||
ie_core = ie.IECore()
|
||||
net = ie_core.read_network(test_net_xml, test_net_bin)
|
||||
net = generate_relu_model([1, 3, 32, 32])
|
||||
exec_net = ie_core.load_network(net, device, num_requests=2)
|
||||
img = generate_image()
|
||||
request = exec_net.requests[0]
|
||||
request.async_infer({'data': img})
|
||||
request.async_infer({'parameter': img})
|
||||
start_time = datetime.utcnow()
|
||||
status = request.wait(ie.WaitMode.RESULT_READY)
|
||||
assert status == ie.StatusCode.OK
|
||||
@ -185,7 +185,7 @@ def test_async_infer_wait_time(device):
|
||||
latency_ms = (time_delta.microseconds / 1000) + (time_delta.seconds * 1000)
|
||||
timeout = max(100, latency_ms)
|
||||
request = exec_net.requests[1]
|
||||
request.async_infer({'data': img})
|
||||
request.async_infer({'parameter': img})
|
||||
max_repeat = 10
|
||||
status = ie.StatusCode.REQUEST_BUSY
|
||||
i = 0
|
||||
@ -193,8 +193,8 @@ def test_async_infer_wait_time(device):
|
||||
status = request.wait(timeout)
|
||||
i += 1
|
||||
assert status == ie.StatusCode.OK
|
||||
res = request.output_blobs['fc_out'].buffer
|
||||
assert np.argmax(res) == 9
|
||||
res = request.output_blobs['relu'].buffer
|
||||
assert np.argmax(res) == 531
|
||||
del exec_net
|
||||
del ie_core
|
||||
del net
|
||||
@ -202,14 +202,14 @@ def test_async_infer_wait_time(device):
|
||||
|
||||
def test_async_infer_wait_status(device):
|
||||
ie_core = ie.IECore()
|
||||
net = ie_core.read_network(test_net_xml, test_net_bin)
|
||||
net = generate_relu_model([1, 3, 32, 32])
|
||||
exec_net = ie_core.load_network(net, device, num_requests=1)
|
||||
img = generate_image()
|
||||
request = exec_net.requests[0]
|
||||
request.async_infer({'data': img})
|
||||
request.async_infer({'parameter': img})
|
||||
request.wait(ie.WaitMode.RESULT_READY)
|
||||
res = request.output_blobs['fc_out'].buffer
|
||||
assert np.argmax(res) == 9
|
||||
res = request.output_blobs['relu'].buffer
|
||||
assert np.argmax(res) == 531
|
||||
status = request.wait(ie.WaitMode.STATUS_ONLY)
|
||||
assert status == ie.StatusCode.OK
|
||||
del exec_net
|
||||
@ -219,16 +219,16 @@ def test_async_infer_wait_status(device):
|
||||
|
||||
def test_async_infer_fill_inputs(device):
|
||||
ie_core = ie.IECore()
|
||||
net = ie_core.read_network(test_net_xml, test_net_bin)
|
||||
net = generate_relu_model([1, 3, 32, 32])
|
||||
exec_net = ie_core.load_network(net, device, num_requests=1)
|
||||
img = generate_image()
|
||||
request = exec_net.requests[0]
|
||||
request.input_blobs['data'].buffer[:] = img
|
||||
request.input_blobs['parameter'].buffer[:] = img
|
||||
request.async_infer()
|
||||
status_end = request.wait()
|
||||
assert status_end == ie.StatusCode.OK
|
||||
res = request.output_blobs['fc_out'].buffer
|
||||
assert np.argmax(res[0]) == 9
|
||||
res = request.output_blobs['relu'].buffer
|
||||
assert np.argmax(res[0]) == 531
|
||||
del exec_net
|
||||
del ie_core
|
||||
del net
|
||||
@ -236,20 +236,20 @@ def test_async_infer_fill_inputs(device):
|
||||
|
||||
def test_infer_modify_outputs(device):
|
||||
ie_core = ie.IECore()
|
||||
net = ie_core.read_network(test_net_xml, test_net_bin)
|
||||
net = generate_relu_model([1, 3, 32, 32])
|
||||
exec_net = ie_core.load_network(net, device, num_requests=1)
|
||||
img = generate_image()
|
||||
request = exec_net.requests[0]
|
||||
outputs0 = exec_net.infer({'data': img})
|
||||
outputs0 = exec_net.infer({'parameter': img})
|
||||
status_end = request.wait()
|
||||
assert status_end == ie.StatusCode.OK
|
||||
assert np.argmax(outputs0['fc_out']) == 9
|
||||
outputs0['fc_out'][:] = np.zeros(shape=(1, 10), dtype=np.float32)
|
||||
assert np.argmax(outputs0['relu']) == 531
|
||||
outputs0['relu'][:] = np.zeros(shape=(1, 3, 32, 32), dtype=np.float32)
|
||||
outputs1 = request.output_blobs
|
||||
assert np.argmax(outputs1['fc_out'].buffer) == 9
|
||||
outputs1['fc_out'].buffer[:] = np.ones(shape=(1, 10), dtype=np.float32)
|
||||
assert np.argmax(outputs1['relu'].buffer) == 531
|
||||
outputs1['relu'].buffer[:] = np.ones(shape=(1, 3, 32, 32), dtype=np.float32)
|
||||
outputs2 = request.output_blobs
|
||||
assert np.argmax(outputs2['fc_out'].buffer) == 9
|
||||
assert np.argmax(outputs2['relu'].buffer) == 531
|
||||
del exec_net
|
||||
del ie_core
|
||||
del net
|
||||
@ -269,16 +269,16 @@ def test_async_infer_callback(device):
|
||||
callback.callback_called = 1
|
||||
|
||||
ie_core = ie.IECore()
|
||||
net = ie_core.read_network(test_net_xml, test_net_bin)
|
||||
net = generate_relu_model([1, 3, 32, 32])
|
||||
exec_net = ie_core.load_network(net, device, num_requests=1)
|
||||
img = generate_image()
|
||||
request = exec_net.requests[0]
|
||||
request.set_completion_callback(callback)
|
||||
request.async_infer({'data': img})
|
||||
request.async_infer({'parameter': img})
|
||||
status = request.wait()
|
||||
assert status == ie.StatusCode.OK
|
||||
res = request.output_blobs['fc_out'].buffer
|
||||
assert np.argmax(res) == 9
|
||||
res = request.output_blobs['relu'].buffer
|
||||
assert np.argmax(res) == 531
|
||||
assert callback.callback_called == 1
|
||||
del exec_net
|
||||
del ie_core
|
||||
@ -297,18 +297,18 @@ def test_async_infer_callback_wait_before_start(device):
|
||||
callback.callback_called = 1
|
||||
|
||||
ie_core = ie.IECore()
|
||||
net = ie_core.read_network(test_net_xml, test_net_bin)
|
||||
net = generate_relu_model([1, 3, 32, 32])
|
||||
exec_net = ie_core.load_network(net, device, num_requests=1)
|
||||
img = generate_image()
|
||||
request = exec_net.requests[0]
|
||||
request.set_completion_callback(callback)
|
||||
status = request.wait()
|
||||
assert status == ie.StatusCode.INFER_NOT_STARTED
|
||||
request.async_infer({'data': img})
|
||||
request.async_infer({'parameter': img})
|
||||
status = request.wait()
|
||||
assert status == ie.StatusCode.OK
|
||||
res = request.output_blobs['fc_out'].buffer
|
||||
assert np.argmax(res) == 9
|
||||
res = request.output_blobs['relu'].buffer
|
||||
assert np.argmax(res) == 531
|
||||
assert callback.callback_called == 1
|
||||
del exec_net
|
||||
del ie_core
|
||||
@ -482,23 +482,23 @@ def test_getting_preprocess(device):
|
||||
|
||||
def test_resize_algorithm_work(device):
|
||||
ie_core = ie.IECore()
|
||||
net = ie_core.read_network(test_net_xml, test_net_bin)
|
||||
net = generate_relu_model([1, 3, 32, 32])
|
||||
exec_net_1 = ie_core.load_network(network=net, device_name=device, num_requests=1)
|
||||
|
||||
img = generate_image()
|
||||
res_1 = np.sort(exec_net_1.infer({"data": img})['fc_out'])
|
||||
res_1 = np.sort(exec_net_1.infer({"parameter": img})['relu'])
|
||||
|
||||
net.input_info['data'].preprocess_info.resize_algorithm = ie.ResizeAlgorithm.RESIZE_BILINEAR
|
||||
net.input_info['parameter'].preprocess_info.resize_algorithm = ie.ResizeAlgorithm.RESIZE_BILINEAR
|
||||
|
||||
exec_net_2 = ie_core.load_network(net, device)
|
||||
|
||||
tensor_desc = ie.TensorDesc("FP32", [1, 3, img.shape[2], img.shape[3]], "NCHW")
|
||||
img_blob = ie.Blob(tensor_desc, img)
|
||||
request = exec_net_2.requests[0]
|
||||
assert request.preprocess_info["data"].resize_algorithm == ie.ResizeAlgorithm.RESIZE_BILINEAR
|
||||
request.set_blob('data', img_blob)
|
||||
assert request.preprocess_info["parameter"].resize_algorithm == ie.ResizeAlgorithm.RESIZE_BILINEAR
|
||||
request.set_blob('parameter', img_blob)
|
||||
request.infer()
|
||||
res_2 = np.sort(request.output_blobs['fc_out'].buffer)
|
||||
res_2 = np.sort(request.output_blobs['relu'].buffer)
|
||||
|
||||
assert np.allclose(res_1, res_2, atol=1e-2, rtol=1e-2)
|
||||
|
||||
@ -578,7 +578,6 @@ def test_set_blob_with_incorrect_size(device):
|
||||
tensor_desc = exec_net.requests[0].input_blobs["data"].tensor_desc
|
||||
tensor_desc.dims = [tensor_desc.dims[0]*2, 4, 20, 20]
|
||||
blob = ie.Blob(tensor_desc)
|
||||
print(exec_net.requests[0].output_blobs)
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
exec_net.requests[0].set_blob("data", blob)
|
||||
assert f"Input blob size is not equal network input size" in str(e.value)
|
||||
|
@ -25,13 +25,17 @@ def generate_image(shape: Tuple = (1, 3, 32, 32), dtype: Union[str, np.dtype] =
|
||||
return np.random.rand(*shape).astype(dtype)
|
||||
|
||||
|
||||
def generate_model(input_shape: List[int]) -> openvino.inference_engine.ExecutableNetwork:
|
||||
def generate_relu_model(input_shape: List[int]) -> openvino.inference_engine.IENetwork:
|
||||
param = ng.parameter(input_shape, np.float32, name="parameter")
|
||||
relu = ng.relu(param, name="relu")
|
||||
func = Function([relu], [param], "test")
|
||||
func.get_ordered_ops()[2].friendly_name = "friendly"
|
||||
|
||||
core = IECore()
|
||||
caps = Function.to_capsule(func)
|
||||
cnnNetwork = IENetwork(caps)
|
||||
return core.load_network(cnnNetwork, "CPU", {})
|
||||
return cnnNetwork
|
||||
|
||||
|
||||
def generate_relu_compiled_model(input_shape: List[int], device = "CPU") -> openvino.inference_engine.ExecutableNetwork:
|
||||
core = IECore()
|
||||
cnnNetwork = generate_relu_model(input_shape)
|
||||
return core.load_network(cnnNetwork, device, {})
|
||||
|
Loading…
Reference in New Issue
Block a user