Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.
6403 Discussions

[OpenVino C API] inference engine error while reading network

muleymakarand
Novice
4,687 Views

Hi 

I have converted my ML model using a model optimizer. My project is developed in C language and my model will be part of this project. I am trying to load the model using openvino C API.

Below are my project details

Development Environment - Visual Studio 2019

OpenVino Version - 2021 version 3

 

I am following hello_classification example step by step

 

Below is my code

 

int main(int argc, char** argv) {
// ------------------------------ Parsing and validation of input args ---------------------------------
if (argc != 4) {
printf("Usage : ./hello_classification <path_to_model> <path_to_image> <device_name>\n");
return EXIT_FAILURE;
}

const char* input_model = argv[1];
const char* input_image_path = argv[2];
const char* device_name = argv[3];
ie_core_t* core = NULL;
ie_network_t* network = NULL;
ie_executable_network_t* exe_network = NULL;
ie_infer_request_t* infer_request = NULL;
char* input_name = NULL, * output_name = NULL;
ie_blob_t* imgBlob = NULL, * output_blob = NULL;
// -----------------------------------------------------------------------------------------------------

// --------------------------- 1. Load inference engine instance -------------------------------------

IEStatusCode status = ie_core_create("", &core);
if (status != OK) {
printf("Failed to create");
return -1;

// 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin files) or ONNX (.onnx file) format
status = ie_core_read_network(core, "saved_model.xml", "saved_model.bin", &network);
if (status != OK)
printf("Failed to read network");
goto err;

err:
if (core)
ie_core_free(&core);
if (network)
ie_network_free(&network);
if (input_name)
ie_network_name_free(&input_name);
if (output_name)
ie_network_name_free(&output_name);
if (exe_network)
ie_exec_network_free(&exe_network);
if (infer_request)
ie_infer_request_free(&infer_request);
if (imgBlob)
ie_blob_free(&imgBlob);
if (output_blob)
ie_blob_free(&output_blob);

return EXIT_FAILURE;

}

 

I am facing error on highlighted line. I am trying to use ie_core_read_network() and both saved_model.bin and saved_model.xml are in same  place as .exe

When i call this function, i get status as UNEXPECTED

Am  i missing something here?

0 Kudos
1 Solution
Iffa_Intel
Moderator
4,610 Views

That issue is related with MKLDNN plugin which usually happens if you didn't setup your environment properly (OpenVINO environment on your system).

 

Make sure you had done the steps as in here: https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_windows.html

 

Plus, make sure you had run the setupvars from your Visual Studio terminal before running anything inthe OpenVINO package.

 

You can also implement a script to auto run this in windows (Linux the setupvars should be set up to run permanently as in documentation shows)

 

My attachment is the example for that purpose.

 

 

 

View solution in original post

0 Kudos
11 Replies
Iffa_Intel
Moderator
4,660 Views

Hi,

 

OpenVINO samples usually rely on multiple libraries that need to be properly linked.

Your cmake file needs to have all the required settings for the build too.

The setupvars initialization is also crucial.

 

Can you share your error snippets instead?

"i get status as UNEXPECTED" is not enough detail.

 

 

Sincerely,

Iffa

 

 

 

0 Kudos
muleymakarand
Novice
4,648 Views

Hi Iffa,

 

Thanks for your reply. PFA error snippets.

I am able to create .exe file.

when I run the program I get on an error on  line

status = ie_core_read_network(core, input_model, NULL, &network);

status should be "OK" but I am getting status as "UNEXPECTED"

Iam using following params

1) core is created using plugins.xml on line

     ie_core_create("plugins.xml", &core);

2) for input_model I am giving path of model xml file 

3) for model weight parameter, i have tried giving NULL as well as .bin file path both

4) network is pointer for ie_network_t

 

If you need any details let me know.

0 Kudos
Iffa_Intel
Moderator
4,643 Views

It seems that something is incomplete in your custom code.

 

Please help to follow this guideline especially when you are customing the Inference Engine API: https://docs.openvinotoolkit.org/latest/openvino_docs_IE_DG_Deep_Learning_Inference_Engine_DevGuide.html

 

and this is the correct way of integrating your custom app with OpenVINO inference Engine:

https://docs.openvinotoolkit.org/latest/openvino_docs_IE_DG_Integrate_with_customer_application_new_API.html

 

0 Kudos
muleymakarand
Novice
4,635 Views

Hi Iffa,

 

Thanks for your quick response and these links, which have helped me proceed further. I was missing a couple of DLL's after including them I could read_network

Now I am having an error at the following function call

 

status = ie_network_get_input_name(network, 0, &input_name);
if (status != OK)
printf("\n not able to get network input name");
//goto err;
printf("\n Got input");

 

I have attached the error screenshot and my sample code.

0 Kudos
Iffa_Intel
Moderator
4,611 Views

That issue is related with MKLDNN plugin which usually happens if you didn't setup your environment properly (OpenVINO environment on your system).

 

Make sure you had done the steps as in here: https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_windows.html

 

Plus, make sure you had run the setupvars from your Visual Studio terminal before running anything inthe OpenVINO package.

 

You can also implement a script to auto run this in windows (Linux the setupvars should be set up to run permanently as in documentation shows)

 

My attachment is the example for that purpose.

 

 

 

0 Kudos
muleymakarand
Novice
4,596 Views

Hi Iifa,

 

Thanks for the quick reply. I rechecked my setup and it was correct. The problem was, I was running setupvars.bat separately and not in Visual Studio terminal. After your advice, I am running setupvars.bat in the Visual Studio terminal, and it solved my MKLDNN issue. Thanks a lot.

Now I am trying to do inference.

Unlike the Hello_classification example in samples (which uses an image as data for inference), my example has time-series data.

My input is 12*25 matrix which needs to be given to every inference step and output is 1*25. (i am trying to predict output at timestamp T+12 based on input from timestamp T0 to T11. It has 25 features at every timestamp. 

I understand that I need to create a blob (Based on the Hello Classification example), but I am not understanding how to do it.

Can you guide me on this?

0 Kudos
Iffa_Intel
Moderator
4,583 Views

If you look at the previous documentation that I gave you before, it has explanation regarding blob:

https://docs.openvinotoolkit.org/latest/openvino_docs_IE_DG_Integrate_with_customer_application_new_API.html


This also contains the blob function explanation: https://docs.openvinotoolkit.org/latest/ie_c_api/group__Blob.html



Sincerely,

Iffa




0 Kudos
muleymakarand
Novice
4,564 Views

Hi Iffa,

Sorry for the late reply, I was on leave.

I have gone through these links, and it has helped me in the creation of the blob. 

I am trying to invoke 

status = ie_infer_request_set_blob(infer_request, input_name, imgBlob);

but I am getting status as -1 (General Error)

 

From my side, I have tried setting various precision values, making input resizable (In my case network IP is fixed and i won't be resizing it, still I checked with resizing also)

I have ensured that my inputs to the function are not null.

Any idea what may be causing this error?

PFA my code and my error screenshot

 

0 Kudos
Iffa_Intel
Moderator
4,537 Views


Unfortunately, there is no specific documentation that explains in-depth the Error -1 (General Error).

However, the list of error for IEStatusCode can be obtained in this link: openvino/api_overview.md at 6a16b70e0ef7fba37052a2b7b3ddb63e8fc9b32e · openvinotoolkit/openvino (github.com)

 

​  OK = 0,

  GENERAL_ERROR = -1,

​  NOT_IMPLEMENTED = -2,

​  NETWORK_NOT_LOADED = -3,

​  PARAMETER_MISMATCH = -4,

​  NOT_FOUND = -5,

​  OUT_OF_BOUNDS = -6,

​  /* \* @brief exception not of std::exception derived type was thrown ​   */

​  UNEXPECTED = -7,

​  REQUEST_BUSY = -8,

​  RESULT_NOT_READY = -9,

​  NOT_ALLOCATED = -10,

​  INFER_NOT_STARTED = -11,

​  NETWORK_NOT_READ = -12

 

The error might comes from ie_infer_request_set_blob function itself - the format used might be wrong.

These methods are suggested (written in the documentation)

 

  • IEStatusCode ie_infer_request_set_blob(ie_infer_request_t *infer_request, ie_blob_t *blob)
    • Description: Sets the blob in a inference request.
  • Parameters:
    • infer_request : A pointer to ie_infer_request_t instance.
    • blob : A pointer to ie_blob_t instance.
  • Return value: Status code of the operation: OK(0) for success.


Sincerely,

Iffa



0 Kudos
Iffa_Intel
Moderator
4,514 Views

Greetings,


Intel will no longer monitor this thread since we have provided a solution. If you need any additional information from Intel, please submit a new question. 



Sincerely,

Iffa


muleymakarand
Novice
4,505 Views

Greetings,

 

Thanks to your continuous support, i am able to do inference using OpenVino C

 

Regards,

Makarand Muley 

Reply