コード例 #1
0
def test_read_network():
    ie_core = Core()
    net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
    assert isinstance(net, IENetwork)

    net = ie_core.read_network(model=test_net_xml)
    assert isinstance(net, IENetwork)
コード例 #2
0
def test_read_network_as_path():
    ie_core = Core()
    net = ie_core.read_network(model=Path(test_net_xml), weights=Path(test_net_bin))
    assert isinstance(net, IENetwork)

    net = ie_core.read_network(model=test_net_xml, weights=Path(test_net_bin))
    assert isinstance(net, IENetwork)

    net = ie_core.read_network(model=Path(test_net_xml))
    assert isinstance(net, IENetwork)
コード例 #3
0
def test_read_network_from_blob_valid():
    ie_core = Core()
    model = open(test_net_xml).read()
    blob = blob_from_file(test_net_bin)
    net = ie_core.read_network(model=model, blob=blob)
    ref_net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
    assert net.name == ref_net.name
    assert net.batch_size == ref_net.batch_size
    ii_net = net.input_info
    ii_net2 = ref_net.input_info
    o_net = net.outputs
    o_net2 = ref_net.outputs
    assert ii_net.keys() == ii_net2.keys()
    assert o_net.keys() == o_net2.keys()
コード例 #4
0
def test_blob_setter(device):
    ie_core = Core()
    net = ie_core.read_network(test_net_xml, test_net_bin)
    exec_net_1 = ie_core.load_network(network=net, device_name=device)

    net.input_info["data"].layout = "NHWC"
    exec_net_2 = ie_core.load_network(network=net, device_name=device)

    img = read_image()

    request1 = exec_net_1.create_infer_request()
    tensor_desc = TensorDesc("FP32", [1, 3, img.shape[2], img.shape[3]],
                             "NCHW")
    img_blob1 = Blob(tensor_desc, img)
    request1.set_input({"data": img_blob1})
    request1.infer()
    res_1 = np.sort(request1.get_blob("fc_out").buffer)

    img = np.transpose(img, axes=(0, 2, 3, 1)).astype(np.float32)
    tensor_desc = TensorDesc("FP32", [1, 3, 32, 32], "NHWC")
    img_blob = Blob(tensor_desc, img)
    request = exec_net_2.create_infer_request()
    request.set_blob("data", img_blob)
    request.infer()
    res_2 = np.sort(request.get_blob("fc_out").buffer)
    assert np.allclose(res_1, res_2, atol=1e-2, rtol=1e-2)
コード例 #5
0
def test_register_plugin():
    ie = Core()
    ie.register_plugin("MKLDNNPlugin", "BLA")
    net = ie.read_network(model=test_net_xml, weights=test_net_bin)
    exec_net = ie.load_network(net, "BLA")
    assert isinstance(exec_net, ExecutableNetwork), \
        "Cannot load the network to the registered plugin with name 'BLA'"
コード例 #6
0
def test_cancel(device):
    ie_core = Core()
    net = ie_core.read_network(test_net_xml, test_net_bin)
    exec_net = ie_core.load_network(net, device)
    img = read_image()
    td = TensorDesc("FP32", [1, 3, 32, 32], "NCHW")
    input_blob = Blob(td, img)
    request = exec_net.create_infer_request()

    def callback(req, code, array):
        array.append(42)

    data = []
    request.set_completion_callback(callback, data)
    request.set_input({"data": input_blob})
    request.async_infer()
    request.cancel()
    with pytest.raises(RuntimeError) as e:
        request.wait()
    assert "[ INFER_CANCELLED ]" in str(e.value)
    # check if callback has executed
    assert data == [42]

    request.async_infer()
    status = request.wait()
    assert status == StatusCode.OK
    assert data == [42, 42]
コード例 #7
0
def test_net_from_buffer_valid():
    ie_core = Core()
    with open(test_net_bin, "rb") as f:
        bin = f.read()
    with open(model_path()[0], "rb") as f:
        xml = f.read()
    net = ie_core.read_network(model=xml, weights=bin)
    ref_net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
    assert net.name == ref_net.name
    assert net.batch_size == ref_net.batch_size
    ii_net = net.input_info
    ii_net2 = ref_net.input_info
    o_net = net.outputs
    o_net2 = ref_net.outputs
    assert ii_net.keys() == ii_net2.keys()
    assert o_net.keys() == o_net2.keys()
コード例 #8
0
def test_read_net_from_buffer():
    ie_core = Core()
    with open(test_net_bin, "rb") as f:
        bin = f.read()
    with open(model_path()[0], "rb") as f:
        xml = f.read()
    net = ie_core.read_network(model=xml, weights=bin)
    assert isinstance(net, IENetwork)
コード例 #9
0
def import_onnx_model(model: onnx.ModelProto) -> Function:
    onnx.checker.check_model(model)
    model_byte_string = model.SerializeToString()

    ie = Core()
    ie_network = ie.read_network(bytes(model_byte_string),
                                 Blob(TensorDesc("U8", [], "C")))

    ng_function = ie_network.get_function()
    return ng_function
コード例 #10
0
def test_query_network(device):
    ie = Core()
    net = ie.read_network(model=test_net_xml, weights=test_net_bin)
    query_res = ie.query_network(network=net, device_name=device)
    func_net = net.get_function()
    ops_net = func_net.get_ordered_ops()
    ops_net_names = [op.friendly_name for op in ops_net]
    assert [key for key in query_res.keys() if key not in ops_net_names] == [], \
        "Not all network layers present in query_network results"
    assert next(iter(set(query_res.values()))) == device, "Wrong device for some layers"
コード例 #11
0
def test_set_zero_batch_size(device):
    ie_core = Core()
    net = ie_core.read_network(test_net_xml, test_net_bin)
    exec_net = ie_core.load_network(net, device)
    request = exec_net.create_infer_request()
    with pytest.raises(ValueError) as e:
        request.set_batch(0)
    assert "Batch size should be positive integer number but 0 specified" in str(e.value)
    del exec_net
    del ie_core
    del net
コード例 #12
0
def test_register_plugins():
    ie = Core()
    if platform == "linux" or platform == "linux2":
        ie.register_plugins(plugins_xml)
    elif platform == "darwin":
        ie.register_plugins(plugins_osx_xml)
    elif platform == "win32":
        ie.register_plugins(plugins_win_xml)

    net = ie.read_network(model=test_net_xml, weights=test_net_bin)
    exec_net = ie.load_network(net, "CUSTOM")
    assert isinstance(exec_net,
                      ExecutableNetwork), "Cannot load the network to " \
                                          "the registered plugin with name 'CUSTOM' " \
                                          "registred in the XML file"
コード例 #13
0
ファイル: test_onnx_import.py プロジェクト: SDxKeeper/dldt
def test_import_onnx_function():
    model_path = os.path.join(os.path.dirname(__file__), "models/add_abc.onnx")
    ie = Core()
    network = ie.read_network(model=model_path)

    ng_function = network.get_function()

    dtype = np.float32
    value_a = np.array([1.0], dtype=dtype)
    value_b = np.array([2.0], dtype=dtype)
    value_c = np.array([3.0], dtype=dtype)

    runtime = get_runtime()
    computation = runtime.computation(ng_function)
    result = computation(value_a, value_b, value_c)
    assert np.allclose(result, np.array([6], dtype=dtype))
コード例 #14
0
def test_get_perf_counts(device):
    ie_core = Core()
    net = ie_core.read_network(test_net_xml, test_net_bin)
    ie_core.set_config({"PERF_COUNT": "YES"}, device)
    exec_net = ie_core.load_network(net, device)
    img = read_image()
    request = exec_net.create_infer_request()
    td = TensorDesc("FP32", [1, 3, 32, 32], "NCHW")
    input_blob = Blob(td, img)
    request.set_input({"data": input_blob})
    request.infer()
    pc = request.get_perf_counts()
    assert pc["29"]["status"] == "EXECUTED"
    assert pc["29"]["layer_type"] == "FullyConnected"
    del exec_net
    del ie_core
    del net
コード例 #15
0
def test_import_onnx_with_external_data():
    model_path = os.path.join(os.path.dirname(__file__),
                              "models/external_data.onnx")
    ie = Core()
    network = ie.read_network(model=model_path)

    ng_function = network.get_function()

    dtype = np.float32
    value_a = np.array([1.0, 3.0, 5.0], dtype=dtype)
    value_b = np.array([3.0, 5.0, 1.0], dtype=dtype)
    # third input [5.0, 1.0, 3.0] read from external file

    runtime = get_runtime()
    computation = runtime.computation(ng_function)
    result = computation(value_a, value_b)
    assert np.allclose(result, np.array([3.0, 3.0, 3.0], dtype=dtype))
コード例 #16
0
def test_set_batch_size(device):
    ie_core = Core()
    ie_core.set_config({"DYN_BATCH_ENABLED": "YES"}, device)
    net = ie_core.read_network(test_net_xml, test_net_bin)
    net.batch_size = 10
    data = np.ones(shape=net.input_info["data"].input_data.shape)
    exec_net = ie_core.load_network(net, device)
    data[0] = read_image()[0]
    request = exec_net.create_infer_request()
    request.set_batch(1)
    td = TensorDesc("FP32", [1, 3, 32, 32], "NCHW")
    input_blob = Blob(td, data)
    request.set_input({"data": input_blob})
    request.infer()
    assert np.allclose(int(round(request.output_blobs["fc_out"].buffer[0][2])), 1), \
        "Incorrect data for 1st batch"
    del exec_net
    del ie_core
    del net
コード例 #17
0
def test_load_network(device):
    ie = Core()
    net = ie.read_network(model=test_net_xml, weights=test_net_bin)
    exec_net = ie.load_network(net, device)
    assert isinstance(exec_net, ExecutableNetwork)
コード例 #18
0
def test_read_network_from_blob():
    ie_core = Core()
    model = open(test_net_xml).read()
    blob = blob_from_file(test_net_bin)
    net = ie_core.read_network(model=model, blob=blob)
    assert isinstance(net, IENetwork)
コード例 #19
0
def test_read_network_from_onnx_as_path():
    ie_core = Core()
    net = ie_core.read_network(model=Path(test_net_onnx))
    assert isinstance(net, IENetwork)
コード例 #20
0
def test_read_network_from_onnx():
    ie_core = Core()
    net = ie_core.read_network(model=test_net_onnx)
    assert isinstance(net, IENetwork)