dnn/openvino: add log error message

Signed-off-by: Ting Fu <ting.fu@intel.com>
This commit is contained in:
Ting Fu 2020-08-27 12:17:21 +08:00 committed by Guo, Yejun
parent a97d8469a6
commit 74358ff4a4

View File

@ -28,7 +28,12 @@
#include "libavutil/avassert.h" #include "libavutil/avassert.h"
#include <c_api/ie_c_api.h> #include <c_api/ie_c_api.h>
typedef struct OVContext {
const AVClass *class;
} OVContext;
typedef struct OVModel{ typedef struct OVModel{
OVContext ctx;
ie_core_t *core; ie_core_t *core;
ie_network_t *network; ie_network_t *network;
ie_executable_network_t *exe_network; ie_executable_network_t *exe_network;
@ -36,6 +41,14 @@ typedef struct OVModel{
ie_blob_t *input_blob; ie_blob_t *input_blob;
} OVModel; } OVModel;
static const AVClass dnn_openvino_class = {
.class_name = "dnn_openvino",
.item_name = av_default_item_name,
.option = NULL,
.version = LIBAVUTIL_VERSION_INT,
.category = AV_CLASS_CATEGORY_FILTER,
};
static DNNDataType precision_to_datatype(precision_e precision) static DNNDataType precision_to_datatype(precision_e precision)
{ {
switch (precision) switch (precision)
@ -51,6 +64,7 @@ static DNNDataType precision_to_datatype(precision_e precision)
static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input_name) static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input_name)
{ {
OVModel *ov_model = (OVModel *)model; OVModel *ov_model = (OVModel *)model;
OVContext *ctx = &ov_model->ctx;
char *model_input_name = NULL; char *model_input_name = NULL;
IEStatusCode status; IEStatusCode status;
size_t model_input_count = 0; size_t model_input_count = 0;
@ -58,25 +72,33 @@ static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input
precision_e precision; precision_e precision;
status = ie_network_get_inputs_number(ov_model->network, &model_input_count); status = ie_network_get_inputs_number(ov_model->network, &model_input_count);
if (status != OK) if (status != OK) {
av_log(ctx, AV_LOG_ERROR, "Failed to get input count\n");
return DNN_ERROR; return DNN_ERROR;
}
for (size_t i = 0; i < model_input_count; i++) { for (size_t i = 0; i < model_input_count; i++) {
status = ie_network_get_input_name(ov_model->network, i, &model_input_name); status = ie_network_get_input_name(ov_model->network, i, &model_input_name);
if (status != OK) if (status != OK) {
av_log(ctx, AV_LOG_ERROR, "Failed to get No.%d input's name\n", (int)i);
return DNN_ERROR; return DNN_ERROR;
}
if (strcmp(model_input_name, input_name) == 0) { if (strcmp(model_input_name, input_name) == 0) {
ie_network_name_free(&model_input_name); ie_network_name_free(&model_input_name);
status |= ie_network_get_input_dims(ov_model->network, input_name, &dims); status |= ie_network_get_input_dims(ov_model->network, input_name, &dims);
status |= ie_network_get_input_precision(ov_model->network, input_name, &precision); status |= ie_network_get_input_precision(ov_model->network, input_name, &precision);
if (status != OK) if (status != OK) {
av_log(ctx, AV_LOG_ERROR, "Failed to get No.%d input's dims or precision\n", (int)i);
return DNN_ERROR; return DNN_ERROR;
}
// The order of dims in the openvino is fixed and it is always NCHW for 4-D data. // The order of dims in the openvino is fixed and it is always NCHW for 4-D data.
// while we pass NHWC data from FFmpeg to openvino // while we pass NHWC data from FFmpeg to openvino
status = ie_network_set_input_layout(ov_model->network, input_name, NHWC); status = ie_network_set_input_layout(ov_model->network, input_name, NHWC);
if (status != OK) if (status != OK) {
av_log(ctx, AV_LOG_ERROR, "Input \"%s\" does not match layout NHWC\n", input_name);
return DNN_ERROR; return DNN_ERROR;
}
input->channels = dims.dims[1]; input->channels = dims.dims[1];
input->height = dims.dims[2]; input->height = dims.dims[2];
@ -88,12 +110,14 @@ static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input
ie_network_name_free(&model_input_name); ie_network_name_free(&model_input_name);
} }
av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model\n", model_input_name);
return DNN_ERROR; return DNN_ERROR;
} }
static DNNReturnType set_input_ov(void *model, DNNData *input, const char *input_name) static DNNReturnType set_input_ov(void *model, DNNData *input, const char *input_name)
{ {
OVModel *ov_model = (OVModel *)model; OVModel *ov_model = (OVModel *)model;
OVContext *ctx = &ov_model->ctx;
IEStatusCode status; IEStatusCode status;
dimensions_t dims; dimensions_t dims;
precision_e precision; precision_e precision;
@ -129,6 +153,7 @@ err:
ie_blob_free(&ov_model->input_blob); ie_blob_free(&ov_model->input_blob);
if (ov_model->infer_request) if (ov_model->infer_request)
ie_infer_request_free(&ov_model->infer_request); ie_infer_request_free(&ov_model->infer_request);
av_log(ctx, AV_LOG_ERROR, "Failed to create inference instance or get input data/dims/precision/memory\n");
return DNN_ERROR; return DNN_ERROR;
} }
@ -147,6 +172,7 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options)
ov_model = av_mallocz(sizeof(OVModel)); ov_model = av_mallocz(sizeof(OVModel));
if (!ov_model) if (!ov_model)
goto err; goto err;
ov_model->ctx.class = &dnn_openvino_class;
status = ie_core_create("", &ov_model->core); status = ie_core_create("", &ov_model->core);
if (status != OK) if (status != OK)
@ -188,25 +214,34 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNData *outputs, c
precision_e precision; precision_e precision;
ie_blob_buffer_t blob_buffer; ie_blob_buffer_t blob_buffer;
OVModel *ov_model = (OVModel *)model->model; OVModel *ov_model = (OVModel *)model->model;
OVContext *ctx = &ov_model->ctx;
IEStatusCode status = ie_infer_request_infer(ov_model->infer_request); IEStatusCode status = ie_infer_request_infer(ov_model->infer_request);
if (status != OK) if (status != OK) {
av_log(ctx, AV_LOG_ERROR, "Failed to start synchronous model inference\n");
return DNN_ERROR; return DNN_ERROR;
}
for (uint32_t i = 0; i < nb_output; ++i) { for (uint32_t i = 0; i < nb_output; ++i) {
const char *output_name = output_names[i]; const char *output_name = output_names[i];
ie_blob_t *output_blob = NULL; ie_blob_t *output_blob = NULL;
status = ie_infer_request_get_blob(ov_model->infer_request, output_name, &output_blob); status = ie_infer_request_get_blob(ov_model->infer_request, output_name, &output_blob);
if (status != OK) if (status != OK) {
av_log(ctx, AV_LOG_ERROR, "Failed to get model output data\n");
return DNN_ERROR; return DNN_ERROR;
}
status = ie_blob_get_buffer(output_blob, &blob_buffer); status = ie_blob_get_buffer(output_blob, &blob_buffer);
if (status != OK) if (status != OK) {
av_log(ctx, AV_LOG_ERROR, "Failed to access output memory\n");
return DNN_ERROR; return DNN_ERROR;
}
status |= ie_blob_get_dims(output_blob, &dims); status |= ie_blob_get_dims(output_blob, &dims);
status |= ie_blob_get_precision(output_blob, &precision); status |= ie_blob_get_precision(output_blob, &precision);
if (status != OK) if (status != OK) {
av_log(ctx, AV_LOG_ERROR, "Failed to get dims or precision of output\n");
return DNN_ERROR; return DNN_ERROR;
}
outputs[i].channels = dims.dims[1]; outputs[i].channels = dims.dims[1];
outputs[i].height = dims.dims[2]; outputs[i].height = dims.dims[2];