1

I am having trouble reading OpenVINO IR networks (XML and bin) from memory using ie_core_read_network_from_memory() in the OpenVINO 2021.4 C API ie_c_api.h.

I suspect that I am creating the network weight blob wrong, but I cannot find any information on how to create weight blobs correctly for networks.

I have read the OpenVINO C API docs but cannot deduce from docs what I am doing wrong. The OpenVINO code repo contains some C code samples, but none of the samples seem to use ie_core_read_network_from_memory().

Below is a cut out of the code I am having trouble with.

// void* dmem->data        - network memory buffer (float32)
// size_t dmem->size       - size of network memory buffer (bytes)

ie_core_t* ov_core = NULL;
IEStatusCode status = ie_core_create("", &ov_core);
if (status != OK)
{
    // error handling
}

const dimensions_t weights_tensor_dims = 
                    { 4, { 1, 1, 1, dmem->size/sizeof(float) } };
tensor_desc_t weights_tensor_desc = { OIHW, weights_tensor_dims, FP32 };

ie_blob_t* ov_model_weight_blob = NULL;
status = ie_blob_make_memory_from_preallocated(
    &weights_tensor_desc, dmem->data, dmem->size, &ov_model_weight_blob);
if (status != OK)
{
    // error handling
}

// char* model_xml_desc        - the model's XML string

uint8_t* ov_model_xml_content = (uint8_t*)model_xml_desc;

ie_network_t* ov_network = NULL;
size_t xml_sz = strlen(ov_model_xml_content);
status = ie_core_read_network_from_memory(
    ov_core, ov_model_xml_content, xml_sz, ov_model_weight_blob, &ov_network);
if (status != OK)
{
    // Always get "GENERAL_ERROR (-1)"
}

The code works fine down to the ie_core_read_network_from_memory() call which results in "GENERAL_ERROR".

I have tried two models that were converted from Tensorflow. One is a simple [X] -> [Y] regression model (single input value, single output value). The other is also a regression model [X_1, X_2, ..., X_9] -> [Y] (nine input values, single output value). They work fine when reading them from file with ie_core_read_network(), but for my use case I must provide the network as a binary memory buffer and XML string.

I would appreciate any help, either by pointing out what I am getting wrong or directing me to some code samples that use ie_core_read_network_from_memory().

System information:

  • Windows 10
  • OpenVINO v2021.4.689
  • Microsoft Visual Studio 2019

UPDATE: An Intel employee reached out to me in another forum and pointed out that there is a unit test for ie_core_read_network_from_memory(). The unit test successfully reads a network from memory and made clear that I was in fact using a faulty tensor description to produce the weight blob, just as I suspected. Apparently the weight blob descriptor should be one dimensional, have memory layout ANY and datatype U8 even though the model weights are fp32.

From the unit test:

std::string bin_std = TestDataHelpers::generate_model_path("test_model", "test_model_fp32.bin");
const char* bin = bin_std.c_str();

//...

std::vector<uint8_t> weights_content(content_from_file(bin, true));
tensor_desc_t weights_desc { ANY, { 1, { weights_content.size() } }, U8 };

However, simply changing the tensor descriptor was not enough to get my code to work so it remains for me to properly translate the C++ code from the unit test to my C environment before the issue to can be considered solved.

Thanks

mags
  • 489
  • 2
  • 11

1 Answers1

-1

Refer to tensor_desc struct and standard layout format. Apart from that, it is recommended to use the Benchmark_app tool to test the inference performance.

Rommel_Intel
  • 1,369
  • 1
  • 4
  • 8
  • Thank you for your reply. Both the tensor_desc struct and layout format are present in `ie_c_api.h`, so they provide no new information, but I realize I was not excessively clear about having read `ie_c_api.h` in my post. I also don't quite see how the Benchmark app - although probably very good for benchmarking - can give me any guidance in why my calls to `ie_core_read_network_from_memory()` fail. – mags Mar 14 '22 at 10:39