History

dnn/openvino: add log error message

Ting Fu committed 6 years ago

Commit 74358ff1 parent a97d8461 file · +43 −8Browse files

Unified · Split

libavfilter/dnn/dnn_backend_openvino.c+43−8
@@ -28,7 +28,12 @@ · 27 unmodified lines
2828 #include "libavutil/avassert.h"
2929 #include <c_api/ie_c_api.h>
3030
31+typedef struct OVContext {
32+ const AVClass *class;
33+} OVContext;
34+
3135 typedef struct OVModel{
36+ OVContext ctx;
3237 ie_core_t *core;
3338 ie_network_t *network;
3439 ie_executable_network_t *exe_network;
@@ -36,6 +41,14 @@ typedef struct OVModel{ · 1 unmodified line
3641 ie_blob_t *input_blob;
3742 } OVModel;
3843
44+static const AVClass dnn_openvino_class = {
45+ .class_name = "dnn_openvino",
46+ .item_name = av_default_item_name,
47+ .option = NULL,
48+ .version = LIBAVUTIL_VERSION_INT,
49+ .category = AV_CLASS_CATEGORY_FILTER,
50+};
51+
3952 static DNNDataType precision_to_datatype(precision_e precision)
4053 {
4154 switch (precision)
@@ -51,6 +64,7 @@ static DNNDataType precision_to_datatype(precision_e precision) · 9 unmodified lines
5164 static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input_name)
5265 {
5366 OVModel *ov_model = (OVModel *)model;
67+ OVContext *ctx = &ov_model->ctx;
5468 char *model_input_name = NULL;
5569 IEStatusCode status;
5670 size_t model_input_count = 0;
@@ -58,25 +72,33 @@ static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input · 1 unmodified line
5872 precision_e precision;
5973
6074 status = ie_network_get_inputs_number(ov_model->network, &model_input_count);
61− if (status != OK)
75+ if (status != OK) {
76+ av_log(ctx, AV_LOG_ERROR, "Failed to get input count\n");
6277 return DNN_ERROR;
78+ }
6379
6480 for (size_t i = 0; i < model_input_count; i++) {
6581 status = ie_network_get_input_name(ov_model->network, i, &model_input_name);
66− if (status != OK)
82+ if (status != OK) {
83+ av_log(ctx, AV_LOG_ERROR, "Failed to get No.%d input's name\n", (int)i);
6784 return DNN_ERROR;
85+ }
6886 if (strcmp(model_input_name, input_name) == 0) {
6987 ie_network_name_free(&model_input_name);
7088 status |= ie_network_get_input_dims(ov_model->network, input_name, &dims);
7189 status |= ie_network_get_input_precision(ov_model->network, input_name, &precision);
72− if (status != OK)
90+ if (status != OK) {
91+ av_log(ctx, AV_LOG_ERROR, "Failed to get No.%d input's dims or precision\n", (int)i);
7392 return DNN_ERROR;
93+ }
7494
7595 // The order of dims in the openvino is fixed and it is always NCHW for 4-D data.
7696 // while we pass NHWC data from FFmpeg to openvino
7797 status = ie_network_set_input_layout(ov_model->network, input_name, NHWC);
78− if (status != OK)
98+ if (status != OK) {
99+ av_log(ctx, AV_LOG_ERROR, "Input \"%s\" does not match layout NHWC\n", input_name);
79100 return DNN_ERROR;
101+ }
80102
81103 input->channels = dims.dims[1];
82104 input->height = dims.dims[2];
@@ -88,12 +110,14 @@ static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input · 5 unmodified lines
88110 ie_network_name_free(&model_input_name);
89111 }
90112
113+ av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model\n", model_input_name);
91114 return DNN_ERROR;
92115 }
93116
94117 static DNNReturnType set_input_ov(void *model, DNNData *input, const char *input_name)
95118 {
96119 OVModel *ov_model = (OVModel *)model;
120+ OVContext *ctx = &ov_model->ctx;
97121 IEStatusCode status;
98122 dimensions_t dims;
99123 precision_e precision;
@@ -129,6 +153,7 @@ err: · 29 unmodified lines
129153 ie_blob_free(&ov_model->input_blob);
130154 if (ov_model->infer_request)
131155 ie_infer_request_free(&ov_model->infer_request);
156+ av_log(ctx, AV_LOG_ERROR, "Failed to create inference instance or get input data/dims/precision/memory\n");
132157 return DNN_ERROR;
133158 }
134159
@@ -147,6 +172,7 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options) · 12 unmodified lines
147172 ov_model = av_mallocz(sizeof(OVModel));
148173 if (!ov_model)
149174 goto err;
175+ ov_model->ctx.class = &dnn_openvino_class;
150176
151177 status = ie_core_create("", &ov_model->core);
152178 if (status != OK)
@@ -188,25 +214,34 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNData *outputs, c · 35 unmodified lines
188214 precision_e precision;
189215 ie_blob_buffer_t blob_buffer;
190216 OVModel *ov_model = (OVModel *)model->model;
217+ OVContext *ctx = &ov_model->ctx;
191218 IEStatusCode status = ie_infer_request_infer(ov_model->infer_request);
192− if (status != OK)
219+ if (status != OK) {
220+ av_log(ctx, AV_LOG_ERROR, "Failed to start synchronous model inference\n");
193221 return DNN_ERROR;
222+ }
194223
195224 for (uint32_t i = 0; i < nb_output; ++i) {
196225 const char *output_name = output_names[i];
197226 ie_blob_t *output_blob = NULL;
198227 status = ie_infer_request_get_blob(ov_model->infer_request, output_name, &output_blob);
199− if (status != OK)
228+ if (status != OK) {
229+ av_log(ctx, AV_LOG_ERROR, "Failed to get model output data\n");
200230 return DNN_ERROR;
231+ }
201232
202233 status = ie_blob_get_buffer(output_blob, &blob_buffer);
203− if (status != OK)
234+ if (status != OK) {
235+ av_log(ctx, AV_LOG_ERROR, "Failed to access output memory\n");
204236 return DNN_ERROR;
237+ }
205238
206239 status |= ie_blob_get_dims(output_blob, &dims);
207240 status |= ie_blob_get_precision(output_blob, &precision);
208− if (status != OK)
241+ if (status != OK) {
242+ av_log(ctx, AV_LOG_ERROR, "Failed to get dims or precision of output\n");
209243 return DNN_ERROR;
244+ }
210245
211246 outputs[i].channels = dims.dims[1];
212247 outputs[i].height = dims.dims[2];

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t