[Python API] Remove pyngraph mark in ie python tests (#8013)

* [Python API] Remove pyngraph mark

* move ngraph import from test functions
This commit is contained in:
Anastasia Kuporosova 2021-10-19 13:14:12 +03:00 committed by GitHub
parent e3d5d4520f
commit bfb092a6d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 68 deletions

View File

@ -5,6 +5,8 @@ import os
import pytest import pytest
import numpy as np import numpy as np
import ngraph as ng
def model_path(is_myriad=False): def model_path(is_myriad=False):
path_to_repo = os.environ["MODELS_PATH"] path_to_repo = os.environ["MODELS_PATH"]
@ -43,16 +45,12 @@ def device():
def pytest_configure(config): def pytest_configure(config):
# register an additional markers # register an additional markers
config.addinivalue_line(
"markers", "ngraph_dependent_test"
)
config.addinivalue_line( config.addinivalue_line(
"markers", "template_plugin" "markers", "template_plugin"
) )
def create_encoder(input_shape, levels = 4): def create_encoder(input_shape, levels = 4):
import ngraph as ng
# input # input
input_node = ng.parameter(input_shape, np.float32, name="data") input_node = ng.parameter(input_shape, np.float32, name="data")
@ -86,7 +84,6 @@ def create_encoder(input_shape, levels = 4):
def create_relu(input_shape): def create_relu(input_shape):
import ngraph as ng
input_shape = ng.impl.PartialShape(input_shape) input_shape = ng.impl.PartialShape(input_shape)
param = ng.parameter(input_shape, dtype=np.float32, name="data") param = ng.parameter(input_shape, dtype=np.float32, name="data")
result = ng.relu(param, name="out") result = ng.relu(param, name="out")

View File

@ -7,7 +7,8 @@ import numpy as np
import os import os
from openvino.inference_engine import TensorDesc, Blob, IECore from openvino.inference_engine import TensorDesc, Blob, IECore
from conftest import image_path from conftest import image_path, create_encoder
import ngraph as ng
path_to_image = image_path() path_to_image = image_path()
@ -100,7 +101,6 @@ def test_incompatible_input_precision():
# issue 49903 # issue 49903
@pytest.mark.ngraph_dependent_test
@pytest.mark.skip(reason="Test will enable when CPU fix will be merge") @pytest.mark.skip(reason="Test will enable when CPU fix will be merge")
@pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason="Device dependent test") @pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason="Device dependent test")
def test_buffer_values_after_add_outputs(device): def test_buffer_values_after_add_outputs(device):
@ -140,11 +140,8 @@ def test_cannot_set_shape_preallocated_memory():
assert "Cannot call setShape for Blobs created on top of preallocated memory" in str(e.value) assert "Cannot call setShape for Blobs created on top of preallocated memory" in str(e.value)
@pytest.mark.ngraph_dependent_test
@pytest.mark.template_plugin @pytest.mark.template_plugin
def test_blob_set_shape_after_async_infer(): def test_blob_set_shape_after_async_infer():
from conftest import create_encoder
import ngraph as ng
function = create_encoder([1, 4, 20, 20]) function = create_encoder([1, 4, 20, 20])
net = ng.function_to_cnn(function) net = ng.function_to_cnn(function)
net.reshape({"data": [(1, 5), 4, 20, 20]}) net.reshape({"data": [(1, 5), 4, 20, 20]})

View File

@ -4,7 +4,8 @@
import pytest import pytest
from openvino.inference_engine import CDataPtr, IECore from openvino.inference_engine import CDataPtr, IECore
from conftest import model_path from conftest import model_path, create_relu
import ngraph as ng
test_net_xml, test_net_bin = model_path() test_net_xml, test_net_bin = model_path()
@ -58,11 +59,8 @@ def test_initialized(device):
assert exec_net.outputs['fc_out'].initialized, "Incorrect value for initialized property for layer 'fc_out" assert exec_net.outputs['fc_out'].initialized, "Incorrect value for initialized property for layer 'fc_out"
@pytest.mark.ngraph_dependent_test
@pytest.mark.template_plugin @pytest.mark.template_plugin
def test_is_dynamic(): def test_is_dynamic():
from conftest import create_relu
import ngraph as ng
function = create_relu([-1, 3, 20, 20]) function = create_relu([-1, 3, 20, 20])
net = ng.function_to_cnn(function) net = ng.function_to_cnn(function)
ie = IECore() ie = IECore()

View File

@ -4,7 +4,8 @@
import pytest import pytest
from openvino.inference_engine import IECore, DataPtr from openvino.inference_engine import IECore, DataPtr
from conftest import model_path from conftest import model_path, create_relu
import ngraph as ng
test_net_xml, test_net_bin = model_path() test_net_xml, test_net_bin = model_path()
@ -45,11 +46,8 @@ def test_initialized():
assert layer_out_data().initialized, "Incorrect value for initialized property for layer 'fc_out'" assert layer_out_data().initialized, "Incorrect value for initialized property for layer 'fc_out'"
@pytest.mark.ngraph_dependent_test
@pytest.mark.template_plugin @pytest.mark.template_plugin
def test_is_dynamic(): def test_is_dynamic():
from conftest import create_relu
import ngraph as ng
function = create_relu([-1, 3, 20, 20]) function = create_relu([-1, 3, 20, 20])
net = ng.function_to_cnn(function) net = ng.function_to_cnn(function)
assert net.input_info["data"].input_data.is_dynamic assert net.input_info["data"].input_data.is_dynamic

View File

@ -11,6 +11,7 @@ from queue import Queue
from openvino.inference_engine import IENetwork, IECore, ExecutableNetwork from openvino.inference_engine import IENetwork, IECore, ExecutableNetwork
from conftest import model_path, plugins_path, model_onnx_path from conftest import model_path, plugins_path, model_onnx_path
import ngraph as ng
test_net_xml, test_net_bin = model_path() test_net_xml, test_net_bin = model_path()
@ -61,9 +62,7 @@ def test_load_network_wrong_device():
assert 'Device with "BLA" name is not registered in the InferenceEngine' in str(e.value) assert 'Device with "BLA" name is not registered in the InferenceEngine' in str(e.value)
@pytest.mark.ngraph_dependent_test
def test_query_network(device): def test_query_network(device):
import ngraph as ng
ie = IECore() ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin) net = ie.read_network(model=test_net_xml, weights=test_net_bin)
query_res = ie.query_network(net, device) query_res = ie.query_network(net, device)

View File

@ -3,10 +3,10 @@
import os import os
import pytest import pytest
import warnings
import ngraph as ng
from openvino.inference_engine import IECore, IENetwork, DataPtr, InputInfoPtr, PreProcessInfo from openvino.inference_engine import IECore, IENetwork, DataPtr, InputInfoPtr, PreProcessInfo
from conftest import model_path from conftest import model_path, create_relu
test_net_xml, test_net_bin = model_path() test_net_xml, test_net_bin = model_path()
@ -134,9 +134,7 @@ def test_batch_size_after_reshape():
assert net.input_info['data'].input_data.shape == [8, 3, 32, 32] assert net.input_info['data'].input_data.shape == [8, 3, 32, 32]
@pytest.mark.ngraph_dependent_test
def test_serialize(): def test_serialize():
import ngraph as ng
ie = IECore() ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin) net = ie.read_network(model=test_net_xml, weights=test_net_bin)
net.serialize("./serialized_net.xml", "./serialized_net.bin") net.serialize("./serialized_net.xml", "./serialized_net.bin")
@ -159,15 +157,12 @@ def test_reshape():
assert net.input_info["data"].input_data.shape == [2, 3, 32, 32] assert net.input_info["data"].input_data.shape == [2, 3, 32, 32]
@pytest.mark.ngraph_dependent_test
@pytest.mark.parametrize("shape, p_shape", [ @pytest.mark.parametrize("shape, p_shape", [
([1, 3, 22, 22], [1, 3, -1, 25]), ([1, 3, 22, 22], [1, 3, -1, 25]),
([1, 3, 22, 22], [-1, -1, -1, -1]), ([1, 3, 22, 22], [-1, -1, -1, -1]),
([1, 3, -1, 25], [1, 3, 22, -1]) ([1, 3, -1, 25], [1, 3, 22, -1])
]) ])
def test_reshape_with_partial_shape(device, shape, p_shape): def test_reshape_with_partial_shape(device, shape, p_shape):
from conftest import create_relu
import ngraph as ng
function = create_relu(shape) function = create_relu(shape)
net = ng.function_to_cnn(function) net = ng.function_to_cnn(function)
net.reshape({"data": p_shape}) net.reshape({"data": p_shape})
@ -183,10 +178,7 @@ def test_reshape_with_partial_shape(device, shape, p_shape):
assert function.get_results()[0].get_output_partial_shape(0) == p_shape assert function.get_results()[0].get_output_partial_shape(0) == p_shape
@pytest.mark.ngraph_dependent_test def test_incorrect_reshape():
def test_incorrect_reshape(device):
from conftest import create_relu
import ngraph as ng
function = create_relu([1, 3, 22, 22]) function = create_relu([1, 3, 22, 22])
net = ng.function_to_cnn(function) net = ng.function_to_cnn(function)
with pytest.raises(ValueError) as e: with pytest.raises(ValueError) as e:
@ -226,6 +218,7 @@ def test_multi_out_data():
assert net.outputs["fc_out"].name == "fc_out" and net.outputs["fc_out"].shape == [1, 10] assert net.outputs["fc_out"].name == "fc_out" and net.outputs["fc_out"].shape == [1, 10]
pass pass
def test_tensor_names(): def test_tensor_names():
model = """ model = """
<net name="Network" version="10"> <net name="Network" version="10">
@ -284,11 +277,8 @@ def test_tensor_names():
assert net.get_ov_name_for_tensor("input") == "in1" assert net.get_ov_name_for_tensor("input") == "in1"
@pytest.mark.ngraph_dependent_test
@pytest.mark.template_plugin @pytest.mark.template_plugin
def test_create_two_exec_net(): def test_create_two_exec_net():
from conftest import create_relu
import ngraph as ng
function = create_relu([ng.Dimension(0,5), ng.Dimension(4), ng.Dimension(20), ng.Dimension(20)]) function = create_relu([ng.Dimension(0,5), ng.Dimension(4), ng.Dimension(20), ng.Dimension(20)])
net = ng.function_to_cnn(function) net = ng.function_to_cnn(function)
ie_core = IECore() ie_core = IECore()

View File

@ -4,13 +4,14 @@
import numpy as np import numpy as np
import os import os
import pytest import pytest
import warnings
import threading import threading
from datetime import datetime from datetime import datetime
import time import time
from openvino.inference_engine import ie_api as ie from openvino.inference_engine import ie_api as ie
from conftest import model_path, image_path from conftest import model_path, image_path, create_encoder
import ngraph as ng
from ngraph.impl import Function, Type
is_myriad = os.environ.get("TEST_DEVICE") == "MYRIAD" is_myriad = os.environ.get("TEST_DEVICE") == "MYRIAD"
test_net_xml, test_net_bin = model_path(is_myriad) test_net_xml, test_net_bin = model_path(is_myriad)
@ -18,8 +19,6 @@ path_to_img = image_path()
def create_function_with_memory(input_shape, data_type): def create_function_with_memory(input_shape, data_type):
from ngraph.impl import Function, Type
import ngraph as ng
input_data = ng.parameter(input_shape, name="input_data", dtype=data_type) input_data = ng.parameter(input_shape, name="input_data", dtype=data_type)
rv = ng.read_value(input_data, "var_id_667") rv = ng.read_value(input_data, "var_id_667")
add = ng.add(rv, input_data, name="MemoryAdd") add = ng.add(rv, input_data, name="MemoryAdd")
@ -380,7 +379,6 @@ def test_async_infer_wait_while_callback_will_not_finish(device):
assert callback_status['finished'] == True assert callback_status['finished'] == True
@pytest.mark.ngraph_dependent_test
def test_get_perf_counts(device): def test_get_perf_counts(device):
ie_core = ie.IECore() ie_core = ie.IECore()
net = ie_core.read_network(test_net_xml, test_net_bin) net = ie_core.read_network(test_net_xml, test_net_bin)
@ -391,7 +389,6 @@ def test_get_perf_counts(device):
request.infer({'data': img}) request.infer({'data': img})
pc = request.get_perf_counts() pc = request.get_perf_counts()
assert pc['29']["status"] == "EXECUTED" assert pc['29']["status"] == "EXECUTED"
assert pc['29']["layer_type"] == "FullyConnected"
del exec_net del exec_net
del ie_core del ie_core
del net del net
@ -529,7 +526,6 @@ def test_resize_algorithm_work(device):
assert np.allclose(res_1, res_2, atol=1e-2, rtol=1e-2) assert np.allclose(res_1, res_2, atol=1e-2, rtol=1e-2)
@pytest.mark.ngraph_dependent_test
@pytest.mark.parametrize("mode", ["set_init_memory_state", "reset_memory_state", "normal"]) @pytest.mark.parametrize("mode", ["set_init_memory_state", "reset_memory_state", "normal"])
@pytest.mark.parametrize("data_type", ["FP32", "FP16", "I32"]) @pytest.mark.parametrize("data_type", ["FP32", "FP16", "I32"])
@pytest.mark.parametrize("input_shape", [[10], [10, 10], [10, 10, 10], [2, 10, 10, 10]]) @pytest.mark.parametrize("input_shape", [[10], [10, 10], [10, 10, 10], [2, 10, 10, 10]])
@ -584,7 +580,6 @@ def test_query_state_write_buffer(device, input_shape, data_type, mode):
"Expected values: {} \n Actual values: {} \n".format(expected_res, res) "Expected values: {} \n Actual values: {} \n".format(expected_res, res)
@pytest.mark.ngraph_dependent_test
@pytest.mark.template_plugin @pytest.mark.template_plugin
@pytest.mark.parametrize("shape, p_shape, ref_shape", [ @pytest.mark.parametrize("shape, p_shape, ref_shape", [
([1, 4, 20, 20], [-1, 4, 20, 20], [5, 4, 20, 20]), ([1, 4, 20, 20], [-1, 4, 20, 20], [5, 4, 20, 20]),
@ -593,8 +588,6 @@ def test_query_state_write_buffer(device, input_shape, data_type, mode):
([1, 4, 20, 20], [(3,5), 4, 20, 20], [6, 4, 20, 20]), ([1, 4, 20, 20], [(3,5), 4, 20, 20], [6, 4, 20, 20]),
]) ])
def test_infer_dynamic_network_with_set_shape(shape, p_shape, ref_shape): def test_infer_dynamic_network_with_set_shape(shape, p_shape, ref_shape):
from conftest import create_encoder
import ngraph as ng
function = create_encoder(shape) function = create_encoder(shape)
net = ng.function_to_cnn(function) net = ng.function_to_cnn(function)
net.reshape({"data": p_shape}) net.reshape({"data": p_shape})
@ -611,7 +604,6 @@ def test_infer_dynamic_network_with_set_shape(shape, p_shape, ref_shape):
assert request.output_blobs['out'].tensor_desc.dims == ref_shape assert request.output_blobs['out'].tensor_desc.dims == ref_shape
@pytest.mark.ngraph_dependent_test
@pytest.mark.template_plugin @pytest.mark.template_plugin
@pytest.mark.parametrize("shape, p_shape, ref_shape", [ @pytest.mark.parametrize("shape, p_shape, ref_shape", [
([1, 4, 20, 20], [-1, 4, 20, 20], [5, 4, 20, 20]), ([1, 4, 20, 20], [-1, 4, 20, 20], [5, 4, 20, 20]),
@ -620,8 +612,6 @@ def test_infer_dynamic_network_with_set_shape(shape, p_shape, ref_shape):
([1, 4, 20, 20], [(3,5), 4, 20, 20], [6, 4, 20, 20]), ([1, 4, 20, 20], [(3,5), 4, 20, 20], [6, 4, 20, 20]),
]) ])
def test_infer_dynamic_network_without_set_shape(shape, p_shape, ref_shape): def test_infer_dynamic_network_without_set_shape(shape, p_shape, ref_shape):
from conftest import create_encoder
import ngraph as ng
function = create_encoder(shape) function = create_encoder(shape)
net = ng.function_to_cnn(function) net = ng.function_to_cnn(function)
net.reshape({"data": p_shape}) net.reshape({"data": p_shape})
@ -637,7 +627,6 @@ def test_infer_dynamic_network_without_set_shape(shape, p_shape, ref_shape):
assert request.output_blobs['out'].tensor_desc.dims == ref_shape assert request.output_blobs['out'].tensor_desc.dims == ref_shape
@pytest.mark.ngraph_dependent_test
@pytest.mark.template_plugin @pytest.mark.template_plugin
@pytest.mark.parametrize("shape, p_shape, ref_shape", [ @pytest.mark.parametrize("shape, p_shape, ref_shape", [
([1, 4, 20, 20], [-1, 4, 20, 20], [5, 4, 20, 20]), ([1, 4, 20, 20], [-1, 4, 20, 20], [5, 4, 20, 20]),
@ -646,8 +635,6 @@ def test_infer_dynamic_network_without_set_shape(shape, p_shape, ref_shape):
([1, 4, 20, 20], [(3,5), 4, 20, 20], [6, 4, 20, 20]), ([1, 4, 20, 20], [(3,5), 4, 20, 20], [6, 4, 20, 20]),
]) ])
def test_infer_dynamic_network_with_set_blob(shape, p_shape, ref_shape): def test_infer_dynamic_network_with_set_blob(shape, p_shape, ref_shape):
from conftest import create_encoder
import ngraph as ng
function = create_encoder(shape) function = create_encoder(shape)
net = ng.function_to_cnn(function) net = ng.function_to_cnn(function)
net.reshape({"data": p_shape}) net.reshape({"data": p_shape})
@ -667,11 +654,8 @@ def test_infer_dynamic_network_with_set_blob(shape, p_shape, ref_shape):
assert request.output_blobs["out"].tensor_desc.dims == ref_shape assert request.output_blobs["out"].tensor_desc.dims == ref_shape
@pytest.mark.ngraph_dependent_test
@pytest.mark.template_plugin @pytest.mark.template_plugin
def test_infer_dynamic_network_twice(): def test_infer_dynamic_network_twice():
from conftest import create_encoder
import ngraph as ng
shape, p_shape = [1, 4, 20, 20], [(0,5), 4, 20, 20] shape, p_shape = [1, 4, 20, 20], [(0,5), 4, 20, 20]
ref_shape1, ref_shape2 = [2, 4, 20, 20], [3, 4, 20, 20] ref_shape1, ref_shape2 = [2, 4, 20, 20], [3, 4, 20, 20]
function = create_encoder(shape) function = create_encoder(shape)
@ -689,11 +673,8 @@ def test_infer_dynamic_network_twice():
assert request.output_blobs['out'].tensor_desc.dims == ref_shape2 assert request.output_blobs['out'].tensor_desc.dims == ref_shape2
@pytest.mark.ngraph_dependent_test
@pytest.mark.template_plugin @pytest.mark.template_plugin
def test_infer_dynamic_network_with_set_blob_twice(): def test_infer_dynamic_network_with_set_blob_twice():
from conftest import create_encoder
import ngraph as ng
shape, p_shape = [1, 4, 20, 20], [(0,5), 4, 20, 20] shape, p_shape = [1, 4, 20, 20], [(0,5), 4, 20, 20]
ref_shape1, ref_shape2 = [2, 4, 20, 20], [3, 4, 20, 20] ref_shape1, ref_shape2 = [2, 4, 20, 20], [3, 4, 20, 20]
function = create_encoder(shape) function = create_encoder(shape)
@ -719,15 +700,12 @@ def test_infer_dynamic_network_with_set_blob_twice():
assert request.output_blobs['out'].tensor_desc.dims == ref_shape2 assert request.output_blobs['out'].tensor_desc.dims == ref_shape2
@pytest.mark.ngraph_dependent_test
@pytest.mark.template_plugin @pytest.mark.template_plugin
@pytest.mark.parametrize("shapes", [ @pytest.mark.parametrize("shapes", [
([3, 4, 20, 20], [3, 4, 20, 20], [3, 4, 20, 20]), ([3, 4, 20, 20], [3, 4, 20, 20], [3, 4, 20, 20]),
([3, 4, 20, 20], [3, 4, 28, 28], [3, 4, 45, 45]), ([3, 4, 20, 20], [3, 4, 28, 28], [3, 4, 45, 45]),
]) ])
def test_async_infer_dynamic_network_3_requests(shapes): def test_async_infer_dynamic_network_3_requests(shapes):
from conftest import create_encoder
import ngraph as ng
function = create_encoder([3, 4, 20, 20]) function = create_encoder([3, 4, 20, 20])
net = ng.function_to_cnn(function) net = ng.function_to_cnn(function)
net.reshape({"data": [3, 4, (20, 50), (20, 50)]}) net.reshape({"data": [3, 4, (20, 50), (20, 50)]})
@ -742,11 +720,8 @@ def test_async_infer_dynamic_network_3_requests(shapes):
assert request.output_blobs['out'].tensor_desc.dims == shapes[i] assert request.output_blobs['out'].tensor_desc.dims == shapes[i]
@pytest.mark.ngraph_dependent_test
@pytest.mark.template_plugin @pytest.mark.template_plugin
def test_set_blob_with_incorrect_name(): def test_set_blob_with_incorrect_name():
from conftest import create_encoder
import ngraph as ng
function = create_encoder([4, 4, 20, 20]) function = create_encoder([4, 4, 20, 20])
net = ng.function_to_cnn(function) net = ng.function_to_cnn(function)
ie_core = ie.IECore() ie_core = ie.IECore()
@ -760,11 +735,8 @@ def test_set_blob_with_incorrect_name():
assert f"Failed to find input or output with name: 'incorrect_name'" in str(e.value) assert f"Failed to find input or output with name: 'incorrect_name'" in str(e.value)
@pytest.mark.ngraph_dependent_test
@pytest.mark.template_plugin @pytest.mark.template_plugin
def test_set_blob_with_incorrect_size(): def test_set_blob_with_incorrect_size():
from conftest import create_encoder
import ngraph as ng
function = create_encoder([4, 4, 20, 20]) function = create_encoder([4, 4, 20, 20])
net = ng.function_to_cnn(function) net = ng.function_to_cnn(function)
ie_core = ie.IECore() ie_core = ie.IECore()
@ -782,11 +754,8 @@ def test_set_blob_with_incorrect_size():
assert f"Output blob size is not equal network output size" in str(e.value) assert f"Output blob size is not equal network output size" in str(e.value)
@pytest.mark.ngraph_dependent_test
@pytest.mark.template_plugin @pytest.mark.template_plugin
def test_set_blob_after_async_infer(): def test_set_blob_after_async_infer():
from conftest import create_encoder
import ngraph as ng
function = create_encoder([1, 4, 20, 20]) function = create_encoder([1, 4, 20, 20])
net = ng.function_to_cnn(function) net = ng.function_to_cnn(function)
net.reshape({"data": [(0, 5), 4, 20, 20]}) net.reshape({"data": [(0, 5), 4, 20, 20]})