def test_infer_dynamic_network_with_set_blob_twice(): from conftest import create_ngraph_function import ngraph as ng shape, p_shape = [1, 4, 20, 20], [(0, 5), 4, 20, 20] ref_shape1, ref_shape2 = [2, 4, 20, 20], [3, 4, 20, 20] function = create_ngraph_function(shape) net = ng.function_to_cnn(function) net.reshape({"data": p_shape}) ie_core = ie.IECore() ie_core.register_plugin("templatePlugin", "TEMPLATE") exec_net = ie_core.load_network(net, "TEMPLATE") request = exec_net.requests[0] td = request.input_blobs['data'].tensor_desc td.dims = ref_shape1 blob = ie.Blob(td) request.set_blob("data", blob) request.infer({"data": np.ones(ref_shape1)}) assert exec_net.requests[0].input_blobs[ "data"].tensor_desc.dims == ref_shape1 assert request.output_blobs['out'].tensor_desc.dims == ref_shape1 td = request.input_blobs['data'].tensor_desc td.dims = ref_shape2 blob = ie.Blob(td) request.set_blob("data", blob) request.infer({"data": np.ones(ref_shape2)}) assert exec_net.requests[0].input_blobs[ "data"].tensor_desc.dims == ref_shape2 assert request.output_blobs['out'].tensor_desc.dims == ref_shape2
def test_get_IENetwork_from_nGraph(): func = create_ngraph_function([1, 3, 22, 22]) caps = Function.to_capsule(func) cnnNetwork = IENetwork(caps) assert cnnNetwork != None assert ng.function_from_cnn(cnnNetwork) != None func2 = ng.function_from_cnn(cnnNetwork) assert func2 != None
def test_incorrect_reshape(device): from conftest import create_ngraph_function import ngraph as ng function = create_ngraph_function([1, 3, 22, 22]) net = ng.function_to_cnn(function) with pytest.raises(ValueError) as e: net.reshape({"data": [(2, 4, 6), 3, 22, 22]}) assert "Incorrect PartialShape dimension definition '(2, 4, 6)' " \ "in shape '[(2, 4, 6), 3, 22, 22]', expected one or two values for a dimension! " in str(e.value)
def test_is_dynamic(): from conftest import create_ngraph_function import ngraph as ng function = create_ngraph_function([-1, 3, 20, 20]) net = ng.function_to_cnn(function) ie = IECore() ie.register_plugin("templatePlugin", "TEMPLATE") exec_net = ie.load_network(net, "TEMPLATE") assert exec_net.outputs["out"].is_dynamic p_shape = ng.partial_shape_from_data(exec_net.outputs["out"]) assert isinstance(p_shape, ng.impl.PartialShape) with pytest.raises(RuntimeError) as e: exec_net.outputs["out"].shape assert "Cannot return dims for Data with dynamic shapes!" in str(e.value)
def test_set_blob_with_incorrect_name(): from conftest import create_ngraph_function import ngraph as ng function = create_ngraph_function([4, 4, 20, 20]) net = ng.function_to_cnn(function) ie_core = ie.IECore() ie_core.register_plugin("templatePlugin", "TEMPLATE") exec_net = ie_core.load_network(net, "TEMPLATE") tensor_desc = exec_net.requests[0].input_blobs["data"].tensor_desc tensor_desc.dims = [4, 4, 20, 20] blob = ie.Blob(tensor_desc) with pytest.raises(RuntimeError) as e: exec_net.requests[0].set_blob("incorrect_name", blob) assert f"Failed to find input or output with name: 'incorrect_name'" in str(e.value)
def test_async_infer_dynamic_network_3_requests(shapes): from conftest import create_ngraph_function import ngraph as ng function = create_ngraph_function([3, 4, 20, 20]) net = ng.function_to_cnn(function) net.reshape({"data": [3, (2, 10), 20, 20]}) ie_core = ie.IECore() ie_core.register_plugin("templatePlugin", "TEMPLATE") exec_net = ie_core.load_network(net, "TEMPLATE", num_requests=3) for i, request in enumerate(exec_net.requests): request.async_infer({"data": np.ones(shapes[i])}) for i, request in enumerate(exec_net.requests): status = request.wait(ie.WaitMode.RESULT_READY) assert status == ie.StatusCode.OK assert request.output_blobs['out'].tensor_desc.dims == shapes[i]
def test_create_two_exec_net(): from conftest import create_ngraph_function import ngraph as ng function = create_ngraph_function([ ng.Dimension(0, 5), ng.Dimension(4), ng.Dimension(20), ng.Dimension(20) ]) net = ng.function_to_cnn(function) ie_core = IECore() ie_core.register_plugin("templatePlugin", "TEMPLATE") exec_net1 = ie_core.load_network(net, "TEMPLATE", num_requests=2) assert ng.function_from_cnn(net) != None exec_net2 = ie_core.load_network(net, "TEMPLATE", num_requests=2) assert ng.function_from_cnn(net) != None
def test_set_blob_after_async_infer(): from conftest import create_ngraph_function import ngraph as ng function = create_ngraph_function([ng.Dimension(0,5), ng.Dimension(4), ng.Dimension(20), ng.Dimension(20)]) net = ng.function_to_cnn(function) ie_core = ie.IECore() ie_core.register_plugin("templatePlugin", "TEMPLATE") exec_net = ie_core.load_network(net, "TEMPLATE") request = exec_net.requests[0] tensor_desc = request.input_blobs['data'].tensor_desc tensor_desc.dims = [2, 4, 20, 20] blob = ie.Blob(tensor_desc) request.async_infer({"data": np.ones([4, 4, 20, 20])}) with pytest.raises(RuntimeError) as e: request.set_blob("data", blob) assert "REQUEST_BUSY" in str(e.value)
def test_infer_dynamic_network_without_set_shape(shape, p_shape, ref_shape): from conftest import create_ngraph_function import ngraph as ng function = create_ngraph_function(shape) net = ng.function_to_cnn(function) net.reshape({"data": p_shape}) ie_core = ie.IECore() ie_core.register_plugin("templatePlugin", "TEMPLATE") exec_net = ie_core.load_network(net, "TEMPLATE") exec_net.infer({"data": np.ones(ref_shape)}) assert exec_net.requests[0].input_blobs["data"].tensor_desc.dims == ref_shape request = exec_net.requests[0] request.async_infer({"data": np.ones(ref_shape)}) status = request.wait(ie.WaitMode.RESULT_READY) assert status == ie.StatusCode.OK assert request.output_blobs['out'].tensor_desc.dims == ref_shape
def test_set_blob_with_incorrect_size(): from conftest import create_ngraph_function import ngraph as ng function = create_ngraph_function([4, 4, 20, 20]) net = ng.function_to_cnn(function) ie_core = ie.IECore() ie_core.register_plugin("templatePlugin", "TEMPLATE") exec_net = ie_core.load_network(net, "TEMPLATE") 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) 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) with pytest.raises(RuntimeError) as e: exec_net.requests[0].set_blob("out", blob) assert f"Output blob size is not equal network output size" in str(e.value)
def test_reshape_with_partial_shape(device, shape, p_shape): from conftest import create_ngraph_function import ngraph as ng function = create_ngraph_function(shape) net = ng.function_to_cnn(function) net.reshape({"data": p_shape}) changedFunction = ng.function_from_cnn(net) p_shape = ng.impl.PartialShape(p_shape) assert changedFunction.get_parameters()[0].get_partial_shape().is_dynamic assert changedFunction.get_results()[0].get_output_partial_shape( 0).is_dynamic assert function.get_parameters()[0].get_partial_shape().is_dynamic assert function.get_results()[0].get_output_partial_shape(0).is_dynamic assert changedFunction.get_parameters()[0].get_partial_shape() == p_shape assert changedFunction.get_results()[0].get_output_partial_shape( 0) == p_shape assert function.get_parameters()[0].get_partial_shape() == p_shape assert function.get_results()[0].get_output_partial_shape(0) == p_shape