def test_resize_algorithm_work(device): ie_core = ie.IECore() net = ie_core.read_network(test_net_xml, test_net_bin) exec_net_1 = ie_core.load_network(network=net, device_name=device, num_requests=1) img = read_image() res_1 = np.sort(exec_net_1.infer({"data": img})['fc_out']) net.input_info['data'].preprocess_info.resize_algorithm = ie.ResizeAlgorithm.RESIZE_BILINEAR exec_net_2 = ie_core.load_network(net, device) import cv2 image = cv2.imread(path_to_img) if image is None: raise FileNotFoundError("Input image not found") image = image / 255 image = image.transpose((2, 0, 1)).astype(np.float32) image = np.expand_dims(image, 0) tensor_desc = ie.TensorDesc("FP32", [1, 3, image.shape[2], image.shape[3]], "NCHW") img_blob = ie.Blob(tensor_desc, image) request = exec_net_2.requests[0] assert request.preprocess_info["data"].resize_algorithm == ie.ResizeAlgorithm.RESIZE_BILINEAR request.set_blob('data', img_blob) request.infer() res_2 = np.sort(request.output_blobs['fc_out'].buffer) assert np.allclose(res_1, res_2, atol=1e-2, rtol=1e-2)
def test_output_blobs(device): ie_core = ie.IECore() net = ie_core.read_network(test_net_xml, test_net_bin) executable_network = ie_core.load_network(net, device, num_requests=2) td = ie.TensorDesc("FP32", (1, 10), "NC") assert executable_network.requests[0].output_blobs[ 'fc_out'].tensor_desc == td
def test_blob_setter(device): ie_core = ie.IECore() if device == "CPU": if ie_core.get_metric(device, "FULL_DEVICE_NAME") == "arm_compute::NEON": pytest.skip("Can't run on ARM plugin") net = ie_core.read_network(test_net_xml, test_net_bin) exec_net_1 = ie_core.load_network(network=net, device_name=device, num_requests=1) net.input_info['data'].layout = "NHWC" exec_net_2 = ie_core.load_network(network=net, device_name=device, num_requests=1) img = read_image() res_1 = np.sort(exec_net_1.infer({"data": img})['fc_out']) img = np.transpose(img, axes=(0, 2, 3, 1)).astype(np.float32) tensor_desc = ie.TensorDesc("FP32", [1, 3, 32, 32], "NHWC") img_blob = ie.Blob(tensor_desc, img) request = exec_net_2.requests[0] request.set_blob('data', img_blob) request.infer() res_2 = np.sort(request.output_blobs['fc_out'].buffer) assert np.allclose(res_1, res_2, atol=1e-2, rtol=1e-2)
def test_blob_setter_with_preprocess(device): ie_core = ie.IECore() net = ie_core.read_network(test_net_xml, test_net_bin) exec_net = ie_core.load_network(network=net, device_name=device, num_requests=1) img = read_image() tensor_desc = ie.TensorDesc("FP32", [1, 3, 32, 32], "NCHW") img_blob = ie.Blob(tensor_desc, img) preprocess_info = ie.PreProcessInfo() preprocess_info.mean_variant = ie.MeanVariant.MEAN_IMAGE request = exec_net.requests[0] request.set_blob('data', img_blob, preprocess_info) pp = request.preprocess_info["data"] assert pp.mean_variant == ie.MeanVariant.MEAN_IMAGE
def test_blob_setter(device): ie_core = ie.IECore() net = ie_core.read_network(test_net_xml, test_net_bin) exec_net_1 = ie_core.load_network(network=net, device_name=device, num_requests=1) net.input_info['data'].layout = "NHWC" exec_net_2 = ie_core.load_network(network=net, device_name=device, num_requests=1) img = read_image() res_1 = np.sort(exec_net_1.infer({"data": img})['fc_out']) img = np.transpose(img, axes=(0, 2, 3, 1)).astype(np.float32) tensor_desc = ie.TensorDesc("FP32", [1, 3, 32, 32], "NHWC") img_blob = ie.Blob(tensor_desc, img) request = exec_net_2.requests[0] request.set_blob('data', img_blob) request.infer() res_2 = np.sort(request.output_blobs['fc_out'].buffer) assert np.allclose(res_1, res_2, atol=1e-2, rtol=1e-2)
def test_input_blobs(device): ie_core = ie.IECore() net = ie_core.read_network(test_net_xml, test_net_bin) executable_network = ie_core.load_network(net, device, num_requests=2) td = ie.TensorDesc("FP32", (1, 3, 32, 32), "NCHW") assert executable_network.requests[0].input_blobs['data'].tensor_desc == td