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
28#include "libavutil/avassert.h"28#include "libavutil/avassert.h"
29#include <c_api/ie_c_api.h>29#include <c_api/ie_c_api.h>
30 30
31typedef struct OVContext {
32 const AVClass *class;
33} OVContext;
34
31typedef struct OVModel{35typedef struct OVModel{
36 OVContext ctx;
32 ie_core_t *core;37 ie_core_t *core;
33 ie_network_t *network;38 ie_network_t *network;
34 ie_executable_network_t *exe_network;39 ie_executable_network_t *exe_network;
@@ -36,6 +41,14 @@ typedef struct OVModel{ · 1 unmodified line
36 ie_blob_t *input_blob;41 ie_blob_t *input_blob;
37} OVModel;42} OVModel;
38 43
44static 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
39static DNNDataType precision_to_datatype(precision_e precision)52static DNNDataType precision_to_datatype(precision_e precision)
40{53{
41 switch (precision)54 switch (precision)
@@ -51,6 +64,7 @@ static DNNDataType precision_to_datatype(precision_e precision) · 9 unmodified lines
51static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input_name)64static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input_name)
52{65{
53 OVModel *ov_model = (OVModel *)model;66 OVModel *ov_model = (OVModel *)model;
67 OVContext *ctx = &ov_model->ctx;
54 char *model_input_name = NULL;68 char *model_input_name = NULL;
55 IEStatusCode status;69 IEStatusCode status;
56 size_t model_input_count = 0;70 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
58 precision_e precision;72 precision_e precision;
59 73
60 status = ie_network_get_inputs_number(ov_model->network, &model_input_count);74 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");
62 return DNN_ERROR;77 return DNN_ERROR;
78 }
63 79
64 for (size_t i = 0; i < model_input_count; i++) {80 for (size_t i = 0; i < model_input_count; i++) {
65 status = ie_network_get_input_name(ov_model->network, i, &model_input_name);81 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);
67 return DNN_ERROR;84 return DNN_ERROR;
85 }
68 if (strcmp(model_input_name, input_name) == 0) {86 if (strcmp(model_input_name, input_name) == 0) {
69 ie_network_name_free(&model_input_name);87 ie_network_name_free(&model_input_name);
70 status |= ie_network_get_input_dims(ov_model->network, input_name, &dims);88 status |= ie_network_get_input_dims(ov_model->network, input_name, &dims);
71 status |= ie_network_get_input_precision(ov_model->network, input_name, &precision);89 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);
73 return DNN_ERROR;92 return DNN_ERROR;
93 }
74 94
75 // The order of dims in the openvino is fixed and it is always NCHW for 4-D data.95 // The order of dims in the openvino is fixed and it is always NCHW for 4-D data.
76 // while we pass NHWC data from FFmpeg to openvino96 // while we pass NHWC data from FFmpeg to openvino
77 status = ie_network_set_input_layout(ov_model->network, input_name, NHWC);97 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);
79 return DNN_ERROR;100 return DNN_ERROR;
101 }
80 102
81 input->channels = dims.dims[1];103 input->channels = dims.dims[1];
82 input->height = dims.dims[2];104 input->height = dims.dims[2];
@@ -88,12 +110,14 @@ static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input · 5 unmodified lines
88 ie_network_name_free(&model_input_name);110 ie_network_name_free(&model_input_name);
89 }111 }
90 112
113 av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model\n", model_input_name);
91 return DNN_ERROR;114 return DNN_ERROR;
92}115}
93 116
94static DNNReturnType set_input_ov(void *model, DNNData *input, const char *input_name)117static DNNReturnType set_input_ov(void *model, DNNData *input, const char *input_name)
95{118{
96 OVModel *ov_model = (OVModel *)model;119 OVModel *ov_model = (OVModel *)model;
120 OVContext *ctx = &ov_model->ctx;
97 IEStatusCode status;121 IEStatusCode status;
98 dimensions_t dims;122 dimensions_t dims;
99 precision_e precision;123 precision_e precision;
@@ -129,6 +153,7 @@ err: · 29 unmodified lines
129 ie_blob_free(&ov_model->input_blob);153 ie_blob_free(&ov_model->input_blob);
130 if (ov_model->infer_request)154 if (ov_model->infer_request)
131 ie_infer_request_free(&ov_model->infer_request);155 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");
132 return DNN_ERROR;157 return DNN_ERROR;
133}158}
134 159
@@ -147,6 +172,7 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options) · 12 unmodified lines
147 ov_model = av_mallocz(sizeof(OVModel));172 ov_model = av_mallocz(sizeof(OVModel));
148 if (!ov_model)173 if (!ov_model)
149 goto err;174 goto err;
175 ov_model->ctx.class = &dnn_openvino_class;
150 176
151 status = ie_core_create("", &ov_model->core);177 status = ie_core_create("", &ov_model->core);
152 if (status != OK)178 if (status != OK)
@@ -188,25 +214,34 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNData *outputs, c · 35 unmodified lines
188 precision_e precision;214 precision_e precision;
189 ie_blob_buffer_t blob_buffer;215 ie_blob_buffer_t blob_buffer;
190 OVModel *ov_model = (OVModel *)model->model;216 OVModel *ov_model = (OVModel *)model->model;
217 OVContext *ctx = &ov_model->ctx;
191 IEStatusCode status = ie_infer_request_infer(ov_model->infer_request);218 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");
193 return DNN_ERROR;221 return DNN_ERROR;
222 }
194 223
195 for (uint32_t i = 0; i < nb_output; ++i) {224 for (uint32_t i = 0; i < nb_output; ++i) {
196 const char *output_name = output_names[i];225 const char *output_name = output_names[i];
197 ie_blob_t *output_blob = NULL;226 ie_blob_t *output_blob = NULL;
198 status = ie_infer_request_get_blob(ov_model->infer_request, output_name, &output_blob);227 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");
200 return DNN_ERROR;230 return DNN_ERROR;
231 }
201 232
202 status = ie_blob_get_buffer(output_blob, &blob_buffer);233 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");
204 return DNN_ERROR;236 return DNN_ERROR;
237 }
205 238
206 status |= ie_blob_get_dims(output_blob, &dims);239 status |= ie_blob_get_dims(output_blob, &dims);
207 status |= ie_blob_get_precision(output_blob, &precision);240 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");
209 return DNN_ERROR;243 return DNN_ERROR;
244 }
210 245
211 outputs[i].channels = dims.dims[1];246 outputs[i].channels = dims.dims[1];
212 outputs[i].height = dims.dims[2];247 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