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