samples: Print verbose error messages to stderr (#7795)

* samples: Print verbose error messages to stderr

Printing error root cause is crucial for efficient debugging.
Moreover `stderr` may have different formatting in comparison
to `stdout` which improves readability.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@intel.com>

* fix code style pre-commit check

Co-authored-by: Vladimir Dudnik <vladimir.dudnik@intel.com>
This commit is contained in:
Karol Trzciński 2021-11-10 09:42:52 +01:00 committed by GitHub
parent 41f7893ae8
commit 76994c6ec9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 144 additions and 54 deletions

View File

@ -122,15 +122,19 @@ int main(int argc, char** argv) {
// ------------------------------------- // -------------------------------------
IEStatusCode status = ie_core_create("", &core); IEStatusCode status = ie_core_create("", &core);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_core_create status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
// Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin
// files) or ONNX (.onnx file) format // files) or ONNX (.onnx file) format
status = ie_core_read_network(core, input_model, NULL, &network); status = ie_core_read_network(core, input_model, NULL, &network);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_core_read_network status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// check the network topology // check the network topology
status = ie_network_get_inputs_number(network, &network_input_size); status = ie_network_get_inputs_number(network, &network_input_size);
if (status != OK || network_input_size != 1) { if (status != OK || network_input_size != 1) {
@ -140,7 +144,7 @@ int main(int argc, char** argv) {
status = ie_network_get_outputs_number(network, &network_output_size); status = ie_network_get_outputs_number(network, &network_output_size);
if (status != OK || network_output_size != 1) { if (status != OK || network_output_size != 1) {
printf("Sample supports topologies with 1 output only\n"); fprintf(stderr, "Sample supports topologies with 1 output only\n");
goto err; goto err;
} }
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
@ -151,8 +155,10 @@ int main(int argc, char** argv) {
// ----------------------------------------------------- // -----------------------------------------------------
status = ie_network_get_input_name(network, 0, &input_name); status = ie_network_get_input_name(network, 0, &input_name);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_network_get_input_name status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
/* Mark input as resizable by setting of a resize algorithm. /* Mark input as resizable by setting of a resize algorithm.
* In this case we will be able to set an input blob of any shape to an infer * In this case we will be able to set an input blob of any shape to an infer
* request. Resize and layout conversions are executed automatically during * request. Resize and layout conversions are executed automatically during
@ -160,15 +166,19 @@ int main(int argc, char** argv) {
status |= ie_network_set_input_resize_algorithm(network, input_name, RESIZE_BILINEAR); status |= ie_network_set_input_resize_algorithm(network, input_name, RESIZE_BILINEAR);
status |= ie_network_set_input_layout(network, input_name, NHWC); status |= ie_network_set_input_layout(network, input_name, NHWC);
status |= ie_network_set_input_precision(network, input_name, U8); status |= ie_network_set_input_precision(network, input_name, U8);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_network_set_input_* status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// --------------------------- Prepare output blobs // --------------------------- Prepare output blobs
// ---------------------------------------------------- // ----------------------------------------------------
status |= ie_network_get_output_name(network, 0, &output_name); status |= ie_network_get_output_name(network, 0, &output_name);
status |= ie_network_set_output_precision(network, output_name, FP32); status |= ie_network_set_output_precision(network, output_name, FP32);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_network_get_output_* status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
@ -176,15 +186,19 @@ int main(int argc, char** argv) {
// ------------------------------------------ // ------------------------------------------
ie_config_t config = {NULL, NULL, NULL}; ie_config_t config = {NULL, NULL, NULL};
status = ie_core_load_network(core, network, device_name, &config, &exe_network); status = ie_core_load_network(core, network, device_name, &config, &exe_network);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_core_load_network status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
// --------------------------- Step 5. Create infer request // --------------------------- Step 5. Create infer request
// ------------------------------------------------- // -------------------------------------------------
status = ie_exec_network_create_infer_request(exe_network, &infer_request); status = ie_exec_network_create_infer_request(exe_network, &infer_request);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_exec_network_create_infer_request status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
// --------------------------- Step 6. Prepare input // --------------------------- Step 6. Prepare input
@ -201,28 +215,34 @@ int main(int argc, char** argv) {
// memory // memory
status = ie_blob_make_memory_from_preallocated(&tensorDesc, img.mat_data, size, &imgBlob); status = ie_blob_make_memory_from_preallocated(&tensorDesc, img.mat_data, size, &imgBlob);
if (status != OK) { if (status != OK) {
fprintf(stderr, "ERROR ie_blob_make_memory_from_preallocated status %d, line %d\n", status, __LINE__);
image_free(&img); image_free(&img);
goto err; goto err;
} }
// infer_request accepts input blob of any size // infer_request accepts input blob of any size
status = ie_infer_request_set_blob(infer_request, input_name, imgBlob); status = ie_infer_request_set_blob(infer_request, input_name, imgBlob);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_infer_request_set_blob status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
// --------------------------- Step 7. Do inference // --------------------------- Step 7. Do inference
// -------------------------------------------------------- // --------------------------------------------------------
/* Running the request synchronously */ /* Running the request synchronously */
status = ie_infer_request_infer(infer_request); status = ie_infer_request_infer(infer_request);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_infer_request_infer status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
// --------------------------- Step 8. Process output // --------------------------- Step 8. Process output
// ------------------------------------------------------ // ------------------------------------------------------
status = ie_infer_request_get_blob(infer_request, output_name, &output_blob); status = ie_infer_request_get_blob(infer_request, output_name, &output_blob);
if (status != OK) { if (status != OK) {
fprintf(stderr, "ERROR ie_infer_request_get_blob status %d, line %d\n", status, __LINE__);
image_free(&img); image_free(&img);
goto err; goto err;
} }

View File

@ -178,8 +178,10 @@ int main(int argc, char** argv) {
} }
size_t input_width = 0, input_height = 0, img_size = 0; size_t input_width = 0, input_height = 0, img_size = 0;
if (!is_supported_image_size(argv[3], &input_width, &input_height)) if (!is_supported_image_size(argv[3], &input_width, &input_height)) {
fprintf(stderr, "ERROR is_supported_image_size, line %d\n", __LINE__);
return EXIT_FAILURE; return EXIT_FAILURE;
}
const char* input_model = argv[1]; const char* input_model = argv[1];
const char* input_image_path = argv[2]; const char* input_image_path = argv[2];
@ -196,15 +198,19 @@ int main(int argc, char** argv) {
// --------------------------- Step 1. Initialize inference engine core // --------------------------- Step 1. Initialize inference engine core
// ------------------------------------- // -------------------------------------
IEStatusCode status = ie_core_create("", &core); IEStatusCode status = ie_core_create("", &core);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_core_create status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
// Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin
// files) or ONNX (.onnx file) format // files) or ONNX (.onnx file) format
status = ie_core_read_network(core, input_model, NULL, &network); status = ie_core_read_network(core, input_model, NULL, &network);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_core_read_network status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
// --------------------------- Step 3. Configure input & output // --------------------------- Step 3. Configure input & output
@ -212,8 +218,10 @@ int main(int argc, char** argv) {
// --------------------------- Prepare input blobs // --------------------------- Prepare input blobs
// ----------------------------------------------------- // -----------------------------------------------------
status = ie_network_get_input_name(network, 0, &input_name); status = ie_network_get_input_name(network, 0, &input_name);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_network_get_input_name status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
/* Mark input as resizable by setting of a resize algorithm. /* Mark input as resizable by setting of a resize algorithm.
* In this case we will be able to set an input blob of any shape to an infer * In this case we will be able to set an input blob of any shape to an infer
@ -226,15 +234,19 @@ int main(int argc, char** argv) {
// pre-processing // pre-processing
status |= ie_network_set_color_format(network, input_name, NV12); status |= ie_network_set_color_format(network, input_name, NV12);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_network_set_input_* status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// --------------------------- Prepare output blobs // --------------------------- Prepare output blobs
// ---------------------------------------------------- // ----------------------------------------------------
status |= ie_network_get_output_name(network, 0, &output_name); status |= ie_network_get_output_name(network, 0, &output_name);
status |= ie_network_set_output_precision(network, output_name, FP32); status |= ie_network_set_output_precision(network, output_name, FP32);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_network_set_output_* status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
@ -242,15 +254,19 @@ int main(int argc, char** argv) {
// ------------------------------------------ // ------------------------------------------
ie_config_t config = {NULL, NULL, NULL}; ie_config_t config = {NULL, NULL, NULL};
status = ie_core_load_network(core, network, device_name, &config, &exe_network); status = ie_core_load_network(core, network, device_name, &config, &exe_network);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_core_load_network status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
// --------------------------- Step 5. Create infer request // --------------------------- Step 5. Create infer request
// ------------------------------------------------- // -------------------------------------------------
status = ie_exec_network_create_infer_request(exe_network, &infer_request); status = ie_exec_network_create_infer_request(exe_network, &infer_request);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_exec_network_create_infer_request status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
// --------------------------- Step 6. Prepare input // --------------------------- Step 6. Prepare input
@ -258,10 +274,14 @@ int main(int argc, char** argv) {
// size converted to NV12 data size: height(NV12) = 3 / 2 * logical height // size converted to NV12 data size: height(NV12) = 3 / 2 * logical height
img_size = input_width * (input_height * 3 / 2); img_size = input_width * (input_height * 3 / 2);
img_data = (unsigned char*)calloc(img_size, sizeof(unsigned char)); img_data = (unsigned char*)calloc(img_size, sizeof(unsigned char));
if (NULL == img_data) if (NULL == img_data) {
fprintf(stderr, "ERROR calloc returned NULL, line %d\n", __LINE__);
goto err; goto err;
if (img_size != read_image_from_file(input_image_path, img_data, img_size)) }
if (img_size != read_image_from_file(input_image_path, img_data, img_size)) {
fprintf(stderr, "ERROR ie_exec_network_create_infer_request `img_size` missmatch, line %d\n", __LINE__);
goto err; goto err;
}
// --------------------------- Create a blob to hold the NV12 input data // --------------------------- Create a blob to hold the NV12 input data
// ------------------------------- Create tensor descriptors for Y and UV // ------------------------------- Create tensor descriptors for Y and UV
@ -279,27 +299,35 @@ int main(int argc, char** argv) {
status |= ie_blob_make_memory_from_preallocated(&uv_tensor, img_data + y_plane_size, uv_plane_size, &uv_blob); status |= ie_blob_make_memory_from_preallocated(&uv_tensor, img_data + y_plane_size, uv_plane_size, &uv_blob);
// Create NV12Blob from Y and UV blobs // Create NV12Blob from Y and UV blobs
status |= ie_blob_make_memory_nv12(y_blob, uv_blob, &nv12_blob); status |= ie_blob_make_memory_nv12(y_blob, uv_blob, &nv12_blob);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_blob_make_memory_* status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
status = ie_infer_request_set_blob(infer_request, input_name, nv12_blob); status = ie_infer_request_set_blob(infer_request, input_name, nv12_blob);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_infer_request_set_blob status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
// --------------------------- Step 7. Do inference // --------------------------- Step 7. Do inference
// -------------------------------------------------------- // --------------------------------------------------------
/* Running the request synchronously */ /* Running the request synchronously */
status = ie_infer_request_infer(infer_request); status = ie_infer_request_infer(infer_request);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_infer_request_infer status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
// --------------------------- Step 8. Process output // --------------------------- Step 8. Process output
// ------------------------------------------------------ // ------------------------------------------------------
status = ie_infer_request_get_blob(infer_request, output_name, &output_blob); status = ie_infer_request_get_blob(infer_request, output_name, &output_blob);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_infer_request_get_blob status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
size_t class_num; size_t class_num;
struct classify_res* cls = output_blob_to_classify_res(output_blob, &class_num); struct classify_res* cls = output_blob_to_classify_res(output_blob, &class_num);

View File

@ -69,6 +69,7 @@ int ParseAndCheckCommandLine(int argc, char* argv[]) {
config_msg = optarg; config_msg = optarg;
break; break;
default: default:
fprintf(stderr, "Unknown argument `%c`. Please use -h option.\n", opt);
return -1; return -1;
} }
} }
@ -76,11 +77,11 @@ int ParseAndCheckCommandLine(int argc, char* argv[]) {
if (help) if (help)
return -1; return -1;
if (input_model == NULL) { if (input_model == NULL) {
printf("Model is required but not set. Please set -m option.\n"); fprintf(stderr, "Model is required but not set. Please set -m option.\n");
return -1; return -1;
} }
if (img_msg == NULL) { if (img_msg == NULL) {
printf("Input is required but not set.Please set -i option.\n"); fprintf(stderr, "Input is required but not set.Please set -i option.\n");
return -1; return -1;
} }
@ -96,14 +97,14 @@ int ParseAndCheckCommandLine(int argc, char* argv[]) {
void readInputFilesArgument(const char* arg) { void readInputFilesArgument(const char* arg) {
struct stat sb; struct stat sb;
if (stat(arg, &sb) != 0) { if (stat(arg, &sb) != 0) {
printf("%sFile %s cannot be opened!\n", warn, arg); fprintf(stderr, "%sFile %s cannot be opened!\n", warn, arg);
return; return;
} }
if (S_ISDIR(sb.st_mode)) { if (S_ISDIR(sb.st_mode)) {
DIR* dp; DIR* dp;
dp = opendir(arg); dp = opendir(arg);
if (dp == NULL) { if (dp == NULL) {
printf("%sFile %s cannot be opened!\n", warn, arg); fprintf(stderr, "%sFile %s cannot be opened!\n", warn, arg);
return; return;
} }
@ -189,6 +190,7 @@ void parseInputFilesArguments(int argc, char** argv) {
ie_config_t* parseConfig(const char* config_file, char comment) { ie_config_t* parseConfig(const char* config_file, char comment) {
FILE* file = fopen(config_file, "r"); FILE* file = fopen(config_file, "r");
if (!file) { if (!file) {
fprintf(stderr, "ERROR file `%s` opening failure\n", config_file);
return NULL; return NULL;
} }
@ -323,7 +325,7 @@ int main(int argc, char** argv) {
/** This file_paths stores paths to the processed images **/ /** This file_paths stores paths to the processed images **/
parseInputFilesArguments(argc, argv_temp); parseInputFilesArguments(argc, argv_temp);
if (!file_num) { if (!file_num) {
printf("No suitable images were found\n"); fprintf(stderr, "No suitable images were found\n");
free(argv_temp); free(argv_temp);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -334,16 +336,20 @@ int main(int argc, char** argv) {
printf("%sLoading Inference Engine\n", info); printf("%sLoading Inference Engine\n", info);
IEStatusCode status = ie_core_create("", &core); IEStatusCode status = ie_core_create("", &core);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_core_create status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ------------------------------ Get Available Devices // ------------------------------ Get Available Devices
// ------------------------------------------------------ // ------------------------------------------------------
ie_core_versions_t ver; ie_core_versions_t ver;
printf("%sDevice info: \n", info); printf("%sDevice info: \n", info);
status = ie_core_get_versions(core, device_name, &ver); status = ie_core_get_versions(core, device_name, &ver);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_core_get_versions status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
for (i = 0; i < ver.num_vers; ++i) { for (i = 0; i < ver.num_vers; ++i) {
printf(" %s\n", ver.versions[i].device_name); printf(" %s\n", ver.versions[i].device_name);
printf(" %s version ......... %zu.%zu\n", printf(" %s version ......... %zu.%zu\n",
@ -358,8 +364,10 @@ int main(int argc, char** argv) {
// Custom CPU extension is loaded as a shared library and passed as a // Custom CPU extension is loaded as a shared library and passed as a
// pointer to base extension // pointer to base extension
status = ie_core_add_extension(core, custom_ex_library_msg, "CPU"); status = ie_core_add_extension(core, custom_ex_library_msg, "CPU");
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_core_add_extension status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
printf("%sCustom extension loaded: %s\n", info, custom_ex_library_msg); printf("%sCustom extension loaded: %s\n", info, custom_ex_library_msg);
} }
@ -369,8 +377,10 @@ int main(int argc, char** argv) {
// description // description
ie_config_t cfg = {"CONFIG_FILE", custom_plugin_cfg_msg, NULL}; ie_config_t cfg = {"CONFIG_FILE", custom_plugin_cfg_msg, NULL};
status = ie_core_set_config(core, &cfg, device_name); status = ie_core_set_config(core, &cfg, device_name);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_core_set_config status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
printf("%sConfig for device plugin custom extension loaded: %s\n", info, custom_plugin_cfg_msg); printf("%sConfig for device plugin custom extension loaded: %s\n", info, custom_plugin_cfg_msg);
} }
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
@ -380,8 +390,10 @@ int main(int argc, char** argv) {
printf("%sLoading network:\n", info); printf("%sLoading network:\n", info);
printf("\t%s\n", input_model); printf("\t%s\n", input_model);
status = ie_core_read_network(core, input_model, NULL, &network); status = ie_core_read_network(core, input_model, NULL, &network);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_core_read_network status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
// --------------------------- Step 3. Configure input & output // --------------------------- Step 3. Configure input & output
@ -394,7 +406,7 @@ int main(int argc, char** argv) {
size_t input_num = 0; size_t input_num = 0;
status = ie_network_get_inputs_number(network, &input_num); status = ie_network_get_inputs_number(network, &input_num);
if (status != OK || (input_num != 1 && input_num != 2)) { if (status != OK || (input_num != 1 && input_num != 2)) {
printf("Sample supports topologies only with 1 or 2 inputs\n"); fprintf(stderr, "Sample supports topologies only with 1 or 2 inputs\n");
goto err; goto err;
} }
@ -435,7 +447,7 @@ int main(int argc, char** argv) {
status = ie_network_set_input_precision(network, name, FP32); status = ie_network_set_input_precision(network, name, FP32);
if (status != OK || (input_dim.dims[1] != 3 && input_dim.dims[1] != 6)) { if (status != OK || (input_dim.dims[1] != 3 && input_dim.dims[1] != 6)) {
printf("Invalid input info. Should be 3 or 6 values length\n"); fprintf(stderr, "Invalid input info. Should be 3 or 6 values length\n");
goto err; goto err;
} }
} }
@ -464,7 +476,7 @@ int main(int argc, char** argv) {
for (i = 0; i < file_num; ++i) { for (i = 0; i < file_num; ++i) {
c_mat_t img = {NULL, 0, 0, 0, 0, 0}; c_mat_t img = {NULL, 0, 0, 0, 0, 0};
if (image_read(file_paths[i], &img) == -1) { if (image_read(file_paths[i], &img) == -1) {
printf("%sImage %s cannot be read!\n", warn, file_paths[i]); fprintf(stderr, "%sImage %s cannot be read!\n", warn, file_paths[i]);
continue; continue;
} }
/** Store image data **/ /** Store image data **/
@ -504,7 +516,7 @@ int main(int argc, char** argv) {
} }
if (!image_num) { if (!image_num) {
printf("Valid input images were not found!\n"); fprintf(stderr, "Valid input images were not found!\n");
free(originalImages); free(originalImages);
free(images); free(images);
goto err; goto err;
@ -512,8 +524,10 @@ int main(int argc, char** argv) {
input_shapes_t shapes; input_shapes_t shapes;
status = ie_network_get_input_shapes(network, &shapes); status = ie_network_get_input_shapes(network, &shapes);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_network_get_input_shapes status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
/** Using ie_network_reshape() to set the batch size equal to the number of /** Using ie_network_reshape() to set the batch size equal to the number of
* input images **/ * input images **/
@ -521,14 +535,18 @@ int main(int argc, char** argv) {
* **/ * **/
shapes.shapes[0].shape.dims[0] = image_num; shapes.shapes[0].shape.dims[0] = image_num;
status = ie_network_reshape(network, shapes); status = ie_network_reshape(network, shapes);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_network_reshape status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
ie_network_input_shapes_free(&shapes); ie_network_input_shapes_free(&shapes);
input_shapes_t shapes2; input_shapes_t shapes2;
status = ie_network_get_input_shapes(network, &shapes2); status = ie_network_get_input_shapes(network, &shapes2);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_network_get_input_shapes status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
size_t batchSize = shapes2.shapes[0].shape.dims[0]; size_t batchSize = shapes2.shapes[0].shape.dims[0];
ie_network_input_shapes_free(&shapes2); ie_network_input_shapes_free(&shapes2);
printf("%sBatch size is %zu\n", info, batchSize); printf("%sBatch size is %zu\n", info, batchSize);
@ -541,20 +559,24 @@ int main(int argc, char** argv) {
status = ie_network_get_outputs_number(network, &output_num); status = ie_network_get_outputs_number(network, &output_num);
if (status != OK || !output_num) { if (status != OK || !output_num) {
printf("Can't find a DetectionOutput layer in the topology\n"); fprintf(stderr, "Can't find a DetectionOutput layer in the topology\n");
goto err; goto err;
} }
status = ie_network_get_output_name(network, output_num - 1, &output_name); status = ie_network_get_output_name(network, output_num - 1, &output_name);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_network_get_output_name status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
dimensions_t output_dim; dimensions_t output_dim;
status = ie_network_get_output_dims(network, output_name, &output_dim); status = ie_network_get_output_dims(network, output_name, &output_dim);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_network_get_output_dims status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
if (output_dim.ranks != 4) { if (output_dim.ranks != 4) {
printf("Incorrect output dimensions for SSD model\n"); fprintf(stderr, "Incorrect output dimensions for SSD model\n");
goto err; goto err;
} }
@ -569,8 +591,10 @@ int main(int argc, char** argv) {
/** Set the precision of output data provided by the user, should be called /** Set the precision of output data provided by the user, should be called
* before load of the network to the device **/ * before load of the network to the device **/
status = ie_network_set_output_precision(network, output_name, FP32); status = ie_network_set_output_precision(network, output_name, FP32);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_network_set_output_precision status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
// --------------------------- Step 4. Loading model to the device // --------------------------- Step 4. Loading model to the device
@ -581,14 +605,17 @@ int main(int argc, char** argv) {
status = ie_core_load_network(core, network, device_name, config, &exe_network); status = ie_core_load_network(core, network, device_name, config, &exe_network);
config_free(config); config_free(config);
if (status != OK) { if (status != OK) {
fprintf(stderr, "ERROR ie_core_load_network status %d, line %d\n", status, __LINE__);
goto err; goto err;
} }
} else { } else {
ie_config_t cfg = {NULL, NULL, NULL}; ie_config_t cfg = {NULL, NULL, NULL};
status = ie_core_load_network(core, network, device_name, &cfg, &exe_network); status = ie_core_load_network(core, network, device_name, &cfg, &exe_network);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_core_load_network status %d, line %d\n", status, __LINE__);
goto err; goto err;
} }
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
@ -596,8 +623,10 @@ int main(int argc, char** argv) {
// ------------------------------------------------- // -------------------------------------------------
printf("%sCreate infer request\n", info); printf("%sCreate infer request\n", info);
status = ie_exec_network_create_infer_request(exe_network, &infer_request); status = ie_exec_network_create_infer_request(exe_network, &infer_request);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_exec_network_create_infer_request status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
// --------------------------- Step 6. Prepare input // --------------------------- Step 6. Prepare input
@ -605,22 +634,28 @@ int main(int argc, char** argv) {
/** Creating input blob **/ /** Creating input blob **/
status = ie_infer_request_get_blob(infer_request, imageInputName, &imageInput); status = ie_infer_request_get_blob(infer_request, imageInputName, &imageInput);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_infer_request_get_blob status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
/** Filling input tensor with images. First b channel, then g and r channels /** Filling input tensor with images. First b channel, then g and r channels
* **/ * **/
dimensions_t input_tensor_dims; dimensions_t input_tensor_dims;
status = ie_blob_get_dims(imageInput, &input_tensor_dims); status = ie_blob_get_dims(imageInput, &input_tensor_dims);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_blob_get_dims status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
size_t num_channels = input_tensor_dims.dims[1]; size_t num_channels = input_tensor_dims.dims[1];
size_t image_size = input_tensor_dims.dims[3] * input_tensor_dims.dims[2]; size_t image_size = input_tensor_dims.dims[3] * input_tensor_dims.dims[2];
ie_blob_buffer_t blob_buffer; ie_blob_buffer_t blob_buffer;
status = ie_blob_get_buffer(imageInput, &blob_buffer); status = ie_blob_get_buffer(imageInput, &blob_buffer);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_blob_get_buffer status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
unsigned char* data = (unsigned char*)(blob_buffer.buffer); unsigned char* data = (unsigned char*)(blob_buffer.buffer);
/** Iterate over all input images **/ /** Iterate over all input images **/
@ -651,6 +686,7 @@ int main(int argc, char** argv) {
ie_blob_buffer_t info_blob_buffer; ie_blob_buffer_t info_blob_buffer;
status |= ie_blob_get_buffer(input2, &info_blob_buffer); status |= ie_blob_get_buffer(input2, &info_blob_buffer);
if (status != OK) { if (status != OK) {
fprintf(stderr, "ERROR ie_blob_get_buffer status %d, line %d\n", status, __LINE__);
ie_blob_free(&input2); ie_blob_free(&input2);
goto err; goto err;
} }
@ -672,8 +708,10 @@ int main(int argc, char** argv) {
printf("%sStart inference\n", info); printf("%sStart inference\n", info);
status = ie_infer_request_infer_async(infer_request); status = ie_infer_request_infer_async(infer_request);
status |= ie_infer_request_wait(infer_request, -1); status |= ie_infer_request_wait(infer_request, -1);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_infer_request_infer_async status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
// --------------------------- Step 8. Process output // --------------------------- Step 8. Process output
@ -681,13 +719,17 @@ int main(int argc, char** argv) {
printf("%sProcessing output blobs\n", info); printf("%sProcessing output blobs\n", info);
status = ie_infer_request_get_blob(infer_request, output_name, &output_blob); status = ie_infer_request_get_blob(infer_request, output_name, &output_blob);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_infer_request_get_blob status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
ie_blob_buffer_t output_blob_buffer; ie_blob_buffer_t output_blob_buffer;
status = ie_blob_get_cbuffer(output_blob, &output_blob_buffer); status = ie_blob_get_cbuffer(output_blob, &output_blob_buffer);
if (status != OK) if (status != OK) {
fprintf(stderr, "ERROR ie_blob_get_cbuffer status %d, line %d\n", status, __LINE__);
goto err; goto err;
}
const float* detection = (float*)(output_blob_buffer.cbuffer); const float* detection = (float*)(output_blob_buffer.cbuffer);
int** classes = (int**)calloc(image_num, sizeof(int*)); int** classes = (int**)calloc(image_num, sizeof(int*));