History

lavfi/dnn_backend_tf: Return Specific Error Codes

Switch to returning specific error codes or DNN_GENERIC_ERROR when an error is encountered. For TensorFlow C API errors, currently DNN_GENERIC_ERROR is returned.

Shubhanshu Saxena committed 4 years ago

Commit 3fa89bd1 parent 91af38f2 files · +85 −67Browse files

Showing the changes to libavfilter (2 of 2 files). Show all

Unified · Split

2 files
  1. libavfilter/dnn/dnn_backend_tf.c +83 −65
  2. libavfilter/dnn/dnn_backend_tf.h +2 −2
libavfilter/dnn/dnn_backend_tf.c+83−65
@@ -90,7 +90,7 @@ static const AVOption dnn_tensorflow_options[] = { · 89 unmodified lines
9090
9191 AVFILTER_DEFINE_CLASS(dnn_tensorflow);
9292
93−static DNNReturnType execute_model_tf(TFRequestItem *request, Queue *lltask_queue);
93+static int execute_model_tf(TFRequestItem *request, Queue *lltask_queue);
9494 static void infer_completion_callback(void *args);
9595 static inline void destroy_request_item(TFRequestItem **arg);
9696
@@ -152,9 +152,10 @@ static TFInferRequest *tf_create_inference_request(void) · 55 unmodified lines
152152 *
153153 * @param request pointer to the TFRequestItem for inference
154154 * @retval DNN_SUCCESS if execution is successful
155− * @retval DNN_ERROR if execution fails
155+ * @retval AVERROR(EINVAL) if request is NULL
156+ * @retval DNN_GENERIC_ERROR if execution fails
156157 */
157−static DNNReturnType tf_start_inference(void *args)
158+static int tf_start_inference(void *args)
158159 {
159160 TFRequestItem *request = args;
160161 TFInferRequest *infer_request = request->infer_request;
@@ -164,7 +165,7 @@ static DNNReturnType tf_start_inference(void *args) · 3 unmodified lines
164165
165166 if (!request) {
166167 av_log(&tf_model->ctx, AV_LOG_ERROR, "TFRequestItem is NULL\n");
167− return DNN_ERROR;
168+ return AVERROR(EINVAL);
168169 }
169170
170171 TF_SessionRun(tf_model->session, NULL,
@@ -178,7 +179,7 @@ static DNNReturnType tf_start_inference(void *args) · 7 unmodified lines
178179 if (ff_safe_queue_push_back(tf_model->request_queue, request) < 0) {
179180 destroy_request_item(&request);
180181 }
181− return DNN_ERROR;
182+ return DNN_GENERIC_ERROR;
182183 }
183184 return DNN_SUCCESS;
184185 }
@@ -202,14 +203,14 @@ static inline void destroy_request_item(TFRequestItem **arg) { · 17 unmodified lines
202203 av_freep(arg);
203204 }
204205
205−static DNNReturnType extract_lltask_from_task(TaskItem *task, Queue *lltask_queue)
206+static int extract_lltask_from_task(TaskItem *task, Queue *lltask_queue)
206207 {
207208 TFModel *tf_model = task->model;
208209 TFContext *ctx = &tf_model->ctx;
209210 LastLevelTaskItem *lltask = av_malloc(sizeof(*lltask));
210211 if (!lltask) {
211212 av_log(ctx, AV_LOG_ERROR, "Unable to allocate space for LastLevelTaskItem\n");
212− return DNN_ERROR;
213+ return AVERROR(ENOMEM);
213214 }
214215 task->inference_todo = 1;
215216 task->inference_done = 0;
@@ -217,7 +218,7 @@ static DNNReturnType extract_lltask_from_task(TaskItem *task, Queue *lltask_queu · 1 unmodified line
217218 if (ff_queue_push_back(lltask_queue, lltask) < 0) {
218219 av_log(ctx, AV_LOG_ERROR, "Failed to push back lltask_queue.\n");
219220 av_freep(&lltask);
220− return DNN_ERROR;
221+ return AVERROR(ENOMEM);
221222 }
222223 return DNN_SUCCESS;
223224 }
@@ -277,7 +278,7 @@ static TF_Tensor *allocate_input_tensor(const DNNData *input) · 53 unmodified lines
277278 input_dims[1] * input_dims[2] * input_dims[3] * size);
278279 }
279280
280−static DNNReturnType get_input_tf(void *model, DNNData *input, const char *input_name)
281+static int get_input_tf(void *model, DNNData *input, const char *input_name)
281282 {
282283 TFModel *tf_model = model;
283284 TFContext *ctx = &tf_model->ctx;
@@ -288,7 +289,7 @@ static DNNReturnType get_input_tf(void *model, DNNData *input, const char *input · 4 unmodified lines
288289 tf_output.oper = TF_GraphOperationByName(tf_model->graph, input_name);
289290 if (!tf_output.oper) {
290291 av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model\n", input_name);
291− return DNN_ERROR;
292+ return AVERROR(EINVAL);
292293 }
293294
294295 tf_output.index = 0;
@@ -300,7 +301,7 @@ static DNNReturnType get_input_tf(void *model, DNNData *input, const char *input · 5 unmodified lines
300301 if (TF_GetCode(status) != TF_OK){
301302 TF_DeleteStatus(status);
302303 av_log(ctx, AV_LOG_ERROR, "Failed to get input tensor shape: number of dimension incorrect\n");
303− return DNN_ERROR;
304+ return DNN_GENERIC_ERROR;
304305 }
305306 TF_DeleteStatus(status);
306307
@@ -313,10 +314,10 @@ static DNNReturnType get_input_tf(void *model, DNNData *input, const char *input · 6 unmodified lines
313314 return DNN_SUCCESS;
314315 }
315316
316−static DNNReturnType get_output_tf(void *model, const char *input_name, int input_width, int input_height,
317+static int get_output_tf(void *model, const char *input_name, int input_width, int input_height,
317318 const char *output_name, int *output_width, int *output_height)
318319 {
319− DNNReturnType ret;
320+ int ret;
320321 TFModel *tf_model = model;
321322 TFContext *ctx = &tf_model->ctx;
322323 TaskItem task;
@@ -329,20 +330,21 @@ static DNNReturnType get_output_tf(void *model, const char *input_name, int inpu · 6 unmodified lines
329330 .out_frame = NULL,
330331 };
331332
332− if (ff_dnn_fill_gettingoutput_task(&task, &exec_params, tf_model, input_height, input_width, ctx) != DNN_SUCCESS) {
333+ ret = ff_dnn_fill_gettingoutput_task(&task, &exec_params, tf_model, input_height, input_width, ctx);
334+ if (ret != DNN_SUCCESS) {
333335 goto err;
334336 }
335337
336− if (extract_lltask_from_task(&task, tf_model->lltask_queue) != DNN_SUCCESS) {
338+ ret = extract_lltask_from_task(&task, tf_model->lltask_queue);
339+ if (ret != DNN_SUCCESS) {
337340 av_log(ctx, AV_LOG_ERROR, "unable to extract inference from task.\n");
338− ret = DNN_ERROR;
339341 goto err;
340342 }
341343
342344 request = ff_safe_queue_pop_front(tf_model->request_queue);
343345 if (!request) {
344346 av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n");
345− ret = DNN_ERROR;
347+ ret = AVERROR(EINVAL);
346348 goto err;
347349 }
348350
@@ -386,7 +388,7 @@ static int hex_to_data(uint8_t *data, const char *p) · 37 unmodified lines
386388 return len;
387389 }
388390
389−static DNNReturnType load_tf_model(TFModel *tf_model, const char *model_filename)
391+static int load_tf_model(TFModel *tf_model, const char *model_filename)
390392 {
391393 TFContext *ctx = &tf_model->ctx;
392394 TF_Buffer *graph_def;
@@ -407,7 +409,7 @@ static DNNReturnType load_tf_model(TFModel *tf_model, const char *model_filename · 14 unmodified lines
407409 */
408410 if (strncmp(tf_model->ctx.options.sess_config, "0x", 2) != 0) {
409411 av_log(ctx, AV_LOG_ERROR, "sess_config should start with '0x'\n");
410− return DNN_ERROR;
412+ return AVERROR(EINVAL);
411413 }
412414 config = tf_model->ctx.options.sess_config + 2;
413415 sess_config_length = hex_to_data(NULL, config);
@@ -415,11 +417,11 @@ static DNNReturnType load_tf_model(TFModel *tf_model, const char *model_filename · 1 unmodified line
415417 sess_config = av_mallocz(sess_config_length + AV_INPUT_BUFFER_PADDING_SIZE);
416418 if (!sess_config) {
417419 av_log(ctx, AV_LOG_ERROR, "failed to allocate memory\n");
418− return DNN_ERROR;
420+ return AVERROR(ENOMEM);
419421 }
420422 if (hex_to_data(sess_config, config) < 0) {
421423 av_log(ctx, AV_LOG_ERROR, "failed to convert hex to data\n");
422− return DNN_ERROR;
424+ return AVERROR(EINVAL);
423425 }
424426 }
425427
@@ -427,7 +429,7 @@ static DNNReturnType load_tf_model(TFModel *tf_model, const char *model_filename · 1 unmodified line
427429 if (!graph_def){
428430 av_log(ctx, AV_LOG_ERROR, "Failed to read model \"%s\" graph\n", model_filename);
429431 av_freep(&sess_config);
430− return DNN_ERROR;
432+ return AVERROR(EINVAL);
431433 }
432434 tf_model->graph = TF_NewGraph();
433435 tf_model->status = TF_NewStatus();
@@ -440,7 +442,7 @@ static DNNReturnType load_tf_model(TFModel *tf_model, const char *model_filename · 6 unmodified lines
440442 TF_DeleteStatus(tf_model->status);
441443 av_log(ctx, AV_LOG_ERROR, "Failed to import serialized graph to model graph\n");
442444 av_freep(&sess_config);
443− return DNN_ERROR;
445+ return DNN_GENERIC_ERROR;
444446 }
445447
446448 init_op = TF_GraphOperationByName(tf_model->graph, "init");
@@ -455,7 +457,7 @@ static DNNReturnType load_tf_model(TFModel *tf_model, const char *model_filename · 8 unmodified lines
455457 TF_DeleteSessionOptions(sess_opts);
456458 av_log(ctx, AV_LOG_ERROR, "Failed to set config for sess options with %s\n",
457459 tf_model->ctx.options.sess_config);
458− return DNN_ERROR;
460+ return DNN_GENERIC_ERROR;
459461 }
460462 }
461463
@@ -466,7 +468,7 @@ static DNNReturnType load_tf_model(TFModel *tf_model, const char *model_filename · 4 unmodified lines
466468 TF_DeleteGraph(tf_model->graph);
467469 TF_DeleteStatus(tf_model->status);
468470 av_log(ctx, AV_LOG_ERROR, "Failed to create new session with model graph\n");
469− return DNN_ERROR;
471+ return DNN_GENERIC_ERROR;
470472 }
471473
472474 // Run initialization operation with name "init" if it is present in graph
@@ -481,7 +483,7 @@ static DNNReturnType load_tf_model(TFModel *tf_model, const char *model_filename · 8 unmodified lines
481483 TF_DeleteGraph(tf_model->graph);
482484 TF_DeleteStatus(tf_model->status);
483485 av_log(ctx, AV_LOG_ERROR, "Failed to run session when initializing\n");
484− return DNN_ERROR;
486+ return DNN_GENERIC_ERROR;
485487 }
486488 }
487489
@@ -490,7 +492,7 @@ static DNNReturnType load_tf_model(TFModel *tf_model, const char *model_filename · 2 unmodified lines
490492
491493 #define NAME_BUFFER_SIZE 256
492494
493−static DNNReturnType add_conv_layer(TFModel *tf_model, TF_Operation *transpose_op, TF_Operation **cur_op,
495+static int add_conv_layer(TFModel *tf_model, TF_Operation *transpose_op, TF_Operation **cur_op,
494496 ConvolutionalParams* params, const int layer)
495497 {
496498 TFContext *ctx = &tf_model->ctx;
@@ -594,7 +596,7 @@ static DNNReturnType add_conv_layer(TFModel *tf_model, TF_Operation *transpose_o · 97 unmodified lines
594596 break;
595597 default:
596598 avpriv_report_missing_feature(ctx, "convolutional activation function %d", params->activation);
597− return DNN_ERROR;
599+ return AVERROR(ENOSYS);
598600 }
599601 input.oper = *cur_op;
600602 TF_AddInput(op_desc, input);
@@ -609,10 +611,10 @@ err: · 8 unmodified lines
609611 TF_DeleteTensor(kernel_tensor);
610612 TF_DeleteTensor(biases_tensor);
611613 av_log(ctx, AV_LOG_ERROR, "Failed to add conv layer %d\n", layer);
612− return DNN_ERROR;
614+ return DNN_GENERIC_ERROR;
613615 }
614616
615−static DNNReturnType add_depth_to_space_layer(TFModel *tf_model, TF_Operation **cur_op,
617+static int add_depth_to_space_layer(TFModel *tf_model, TF_Operation **cur_op,
616618 DepthToSpaceParams *params, const int layer)
617619 {
618620 TFContext *ctx = &tf_model->ctx;
@@ -630,13 +632,13 @@ static DNNReturnType add_depth_to_space_layer(TFModel *tf_model, TF_Operation ** · 11 unmodified lines
630632 *cur_op = TF_FinishOperation(op_desc, tf_model->status);
631633 if (TF_GetCode(tf_model->status) != TF_OK){
632634 av_log(ctx, AV_LOG_ERROR, "Failed to add depth_to_space to layer %d\n", layer);
633− return DNN_ERROR;
635+ return DNN_GENERIC_ERROR;
634636 }
635637
636638 return DNN_SUCCESS;
637639 }
638640
639−static DNNReturnType add_pad_layer(TFModel *tf_model, TF_Operation **cur_op,
641+static int add_pad_layer(TFModel *tf_model, TF_Operation **cur_op,
640642 LayerPadParams *params, const int layer)
641643 {
642644 TFContext *ctx = &tf_model->ctx;
@@ -666,13 +668,13 @@ static DNNReturnType add_pad_layer(TFModel *tf_model, TF_Operation **cur_op, · 23 unmodified lines
666668 if (TF_GetCode(tf_model->status) != TF_OK){
667669 TF_DeleteTensor(tensor);
668670 av_log(ctx, AV_LOG_ERROR, "Failed to set value for pad of layer %d\n", layer);
669− return DNN_ERROR;
671+ return DNN_GENERIC_ERROR;
670672 }
671673 op = TF_FinishOperation(op_desc, tf_model->status);
672674 if (TF_GetCode(tf_model->status) != TF_OK){
673675 TF_DeleteTensor(tensor);
674676 av_log(ctx, AV_LOG_ERROR, "Failed to add pad to layer %d\n", layer);
675− return DNN_ERROR;
677+ return DNN_GENERIC_ERROR;
676678 }
677679
678680 op_desc = TF_NewOperation(tf_model->graph, "MirrorPad", "mirror_pad");
@@ -688,13 +690,13 @@ static DNNReturnType add_pad_layer(TFModel *tf_model, TF_Operation **cur_op, · 9 unmodified lines
688690 if (TF_GetCode(tf_model->status) != TF_OK){
689691 TF_DeleteTensor(tensor);
690692 av_log(ctx, AV_LOG_ERROR, "Failed to add mirror_pad to layer %d\n", layer);
691− return DNN_ERROR;
693+ return DNN_GENERIC_ERROR;
692694 }
693695
694696 return DNN_SUCCESS;
695697 }
696698
697−static DNNReturnType add_maximum_layer(TFModel *tf_model, TF_Operation **cur_op,
699+static int add_maximum_layer(TFModel *tf_model, TF_Operation **cur_op,
698700 DnnLayerMaximumParams *params, const int layer)
699701 {
700702 TFContext *ctx = &tf_model->ctx;
@@ -716,13 +718,13 @@ static DNNReturnType add_maximum_layer(TFModel *tf_model, TF_Operation **cur_op, · 15 unmodified lines
716718 if (TF_GetCode(tf_model->status) != TF_OK){
717719 TF_DeleteTensor(tensor);
718720 av_log(ctx, AV_LOG_ERROR, "Failed to set value for maximum/y of layer %d", layer);
719− return DNN_ERROR;
721+ return DNN_GENERIC_ERROR;
720722 }
721723 op = TF_FinishOperation(op_desc, tf_model->status);
722724 if (TF_GetCode(tf_model->status) != TF_OK){
723725 TF_DeleteTensor(tensor);
724726 av_log(ctx, AV_LOG_ERROR, "Failed to add maximum/y to layer %d\n", layer);
725− return DNN_ERROR;
727+ return DNN_GENERIC_ERROR;
726728 }
727729
728730 snprintf(name_buffer, NAME_BUFFER_SIZE, "maximum%d", layer);
@@ -737,13 +739,13 @@ static DNNReturnType add_maximum_layer(TFModel *tf_model, TF_Operation **cur_op, · 8 unmodified lines
737739 if (TF_GetCode(tf_model->status) != TF_OK){
738740 TF_DeleteTensor(tensor);
739741 av_log(ctx, AV_LOG_ERROR, "Failed to add maximum to layer %d\n", layer);
740− return DNN_ERROR;
742+ return DNN_GENERIC_ERROR;
741743 }
742744
743745 return DNN_SUCCESS;
744746 }
745747
746−static DNNReturnType load_native_model(TFModel *tf_model, const char *model_filename)
748+static int load_native_model(TFModel *tf_model, const char *model_filename)
747749 {
748750 TFContext *ctx = &tf_model->ctx;
749751 int32_t layer;
@@ -755,14 +757,14 @@ static DNNReturnType load_native_model(TFModel *tf_model, const char *model_file · 5 unmodified lines
755757 int32_t *transpose_perm;
756758 int64_t transpose_perm_shape[] = {4};
757759 int64_t input_shape[] = {1, -1, -1, -1};
758− DNNReturnType layer_add_res;
760+ int layer_add_res;
759761 DNNModel *model = NULL;
760762 NativeModel *native_model;
761763
762764 model = ff_dnn_load_model_native(model_filename, DFT_PROCESS_FRAME, NULL, NULL);
763765 if (!model){
764766 av_log(ctx, AV_LOG_ERROR, "Failed to load native model\n");
765− return DNN_ERROR;
767+ return AVERROR(EINVAL);
766768 }
767769
768770 native_model = model->model;
@@ -775,7 +777,7 @@ static DNNReturnType load_native_model(TFModel *tf_model, const char *model_file · 6 unmodified lines
775777 TF_DeleteGraph(tf_model->graph); \
776778 TF_DeleteStatus(tf_model->status); \
777779 av_log(ctx, AV_LOG_ERROR, "Failed to set value or add operator to layer\n"); \
778− return DNN_ERROR; \
780+ return DNN_GENERIC_ERROR; \
779781 }
780782
781783 op_desc = TF_NewOperation(tf_model->graph, "Placeholder", "x");
@@ -942,19 +944,21 @@ err: · 160 unmodified lines
942944 return NULL;
943945 }
944946
945−static DNNReturnType fill_model_input_tf(TFModel *tf_model, TFRequestItem *request) {
947+static int fill_model_input_tf(TFModel *tf_model, TFRequestItem *request) {
946948 DNNData input;
947949 LastLevelTaskItem *lltask;
948950 TaskItem *task;
949951 TFInferRequest *infer_request;
950952 TFContext *ctx = &tf_model->ctx;
953+ int ret = 0;
951954
952955 lltask = ff_queue_pop_front(tf_model->lltask_queue);
953956 av_assert0(lltask);
954957 task = lltask->task;
955958 request->lltask = lltask;
956959
957− if (get_input_tf(tf_model, &input, task->input_name) != DNN_SUCCESS) {
960+ ret = get_input_tf(tf_model, &input, task->input_name);
961+ if (ret != DNN_SUCCESS) {
958962 goto err;
959963 }
960964
@@ -965,12 +969,14 @@ static DNNReturnType fill_model_input_tf(TFModel *tf_model, TFRequestItem *reque · 4 unmodified lines
965969 infer_request->tf_input = av_malloc(sizeof(TF_Output));
966970 if (!infer_request->tf_input) {
967971 av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for input tensor\n");
972+ ret = AVERROR(ENOMEM);
968973 goto err;
969974 }
970975
971976 infer_request->tf_input->oper = TF_GraphOperationByName(tf_model->graph, task->input_name);
972977 if (!infer_request->tf_input->oper){
973978 av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model\n", task->input_name);
979+ ret = DNN_GENERIC_ERROR;
974980 goto err;
975981 }
976982 infer_request->tf_input->index = 0;
@@ -978,6 +984,7 @@ static DNNReturnType fill_model_input_tf(TFModel *tf_model, TFRequestItem *reque · 1 unmodified line
978984 infer_request->input_tensor = allocate_input_tensor(&input);
979985 if (!infer_request->input_tensor){
980986 av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for input tensor\n");
987+ ret = AVERROR(ENOMEM);
981988 goto err;
982989 }
983990 input.data = (float *)TF_TensorData(infer_request->input_tensor);
@@ -1003,12 +1010,14 @@ static DNNReturnType fill_model_input_tf(TFModel *tf_model, TFRequestItem *reque · 19 unmodified lines
10031010 infer_request->tf_outputs = av_malloc_array(task->nb_output, sizeof(TF_Output));
10041011 if (infer_request->tf_outputs == NULL) {
10051012 av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for *tf_outputs\n");
1013+ ret = AVERROR(ENOMEM);
10061014 goto err;
10071015 }
10081016
10091017 infer_request->output_tensors = av_calloc(task->nb_output, sizeof(*infer_request->output_tensors));
10101018 if (!infer_request->output_tensors) {
10111019 av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for output tensor\n");
1020+ ret = AVERROR(ENOMEM);
10121021 goto err;
10131022 }
10141023
@@ -1017,6 +1026,7 @@ static DNNReturnType fill_model_input_tf(TFModel *tf_model, TFRequestItem *reque · 2 unmodified lines
10171026 infer_request->tf_outputs[i].oper = TF_GraphOperationByName(tf_model->graph, task->output_names[i]);
10181027 if (!infer_request->tf_outputs[i].oper) {
10191028 av_log(ctx, AV_LOG_ERROR, "Could not find output \"%s\" in model\n", task->output_names[i]);
1029+ ret = DNN_GENERIC_ERROR;
10201030 goto err;
10211031 }
10221032 infer_request->tf_outputs[i].index = 0;
@@ -1025,7 +1035,7 @@ static DNNReturnType fill_model_input_tf(TFModel *tf_model, TFRequestItem *reque · 2 unmodified lines
10251035 return DNN_SUCCESS;
10261036 err:
10271037 tf_free_request(infer_request);
1028− return DNN_ERROR;
1038+ return ret;
10291039 }
10301040
10311041 static void infer_completion_callback(void *args) {
@@ -1086,12 +1096,13 @@ err: · 54 unmodified lines
10861096 }
10871097 }
10881098
1089−static DNNReturnType execute_model_tf(TFRequestItem *request, Queue *lltask_queue)
1099+static int execute_model_tf(TFRequestItem *request, Queue *lltask_queue)
10901100 {
10911101 TFModel *tf_model;
10921102 TFContext *ctx;
10931103 LastLevelTaskItem *lltask;
10941104 TaskItem *task;
1105+ int ret = 0;
10951106
10961107 if (ff_queue_size(lltask_queue) == 0) {
10971108 destroy_request_item(&request);
@@ -1103,7 +1114,8 @@ static DNNReturnType execute_model_tf(TFRequestItem *request, Queue *lltask_queu · 5 unmodified lines
11031114 tf_model = task->model;
11041115 ctx = &tf_model->ctx;
11051116
1106− if (fill_model_input_tf(tf_model, request) != DNN_SUCCESS) {
1117+ ret = fill_model_input_tf(tf_model, request);
1118+ if (ret != DNN_SUCCESS) {
11071119 goto err;
11081120 }
11091121
@@ -1112,58 +1124,64 @@ static DNNReturnType execute_model_tf(TFRequestItem *request, Queue *lltask_queu · 2 unmodified lines
11121124 goto err;
11131125 }
11141126 return DNN_SUCCESS;
1115− } else {
1116− if (tf_start_inference(request) != DNN_SUCCESS) {
1127+ }
1128+ else {
1129+ ret = tf_start_inference(request);
1130+ if (ret != DNN_SUCCESS) {
11171131 goto err;
11181132 }
11191133 infer_completion_callback(request);
1120− return (task->inference_done == task->inference_todo) ? DNN_SUCCESS : DNN_ERROR;
1134+ return (task->inference_done == task->inference_todo) ? DNN_SUCCESS : DNN_GENERIC_ERROR;
11211135 }
11221136 err:
11231137 tf_free_request(request->infer_request);
11241138 if (ff_safe_queue_push_back(tf_model->request_queue, request) < 0) {
11251139 destroy_request_item(&request);
11261140 }
1127− return DNN_ERROR;
1141+ return ret;
11281142 }
11291143
1130−DNNReturnType ff_dnn_execute_model_tf(const DNNModel *model, DNNExecBaseParams *exec_params)
1144+int ff_dnn_execute_model_tf(const DNNModel *model, DNNExecBaseParams *exec_params)
11311145 {
11321146 TFModel *tf_model = model->model;
11331147 TFContext *ctx = &tf_model->ctx;
11341148 TaskItem *task;
11351149 TFRequestItem *request;
1150+ int ret = 0;
11361151
1137− if (ff_check_exec_params(ctx, DNN_TF, model->func_type, exec_params) != 0) {
1138− return DNN_ERROR;
1152+ ret = ff_check_exec_params(ctx, DNN_TF, model->func_type, exec_params);
1153+ if (ret != 0) {
1154+ return ret;
11391155 }
11401156
11411157 task = av_malloc(sizeof(*task));
11421158 if (!task) {
11431159 av_log(ctx, AV_LOG_ERROR, "unable to alloc memory for task item.\n");
1144− return DNN_ERROR;
1160+ return AVERROR(ENOMEM);
11451161 }
11461162
1147− if (ff_dnn_fill_task(task, exec_params, tf_model, ctx->options.async, 1) != DNN_SUCCESS) {
1163+ ret = ff_dnn_fill_task(task, exec_params, tf_model, ctx->options.async, 1);
1164+ if (ret != DNN_SUCCESS) {
11481165 av_freep(&task);
1149− return DNN_ERROR;
1166+ return ret;
11501167 }
11511168
11521169 if (ff_queue_push_back(tf_model->task_queue, task) < 0) {
11531170 av_freep(&task);
11541171 av_log(ctx, AV_LOG_ERROR, "unable to push back task_queue.\n");
1155− return DNN_ERROR;
1172+ return AVERROR(ENOMEM);
11561173 }
11571174
1158− if (extract_lltask_from_task(task, tf_model->lltask_queue) != DNN_SUCCESS) {
1175+ ret = extract_lltask_from_task(task, tf_model->lltask_queue);
1176+ if (ret != DNN_SUCCESS) {
11591177 av_log(ctx, AV_LOG_ERROR, "unable to extract last level task from task.\n");
1160− return DNN_ERROR;
1178+ return ret;
11611179 }
11621180
11631181 request = ff_safe_queue_pop_front(tf_model->request_queue);
11641182 if (!request) {
11651183 av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n");
1166− return DNN_ERROR;
1184+ return AVERROR(EINVAL);
11671185 }
11681186 return execute_model_tf(request, tf_model->lltask_queue);
11691187 }
@@ -1174,12 +1192,12 @@ DNNAsyncStatusType ff_dnn_get_result_tf(const DNNModel *model, AVFrame **in, AVF · 4 unmodified lines
11741192 return ff_dnn_get_result_common(tf_model->task_queue, in, out);
11751193 }
11761194
1177−DNNReturnType ff_dnn_flush_tf(const DNNModel *model)
1195+int ff_dnn_flush_tf(const DNNModel *model)
11781196 {
11791197 TFModel *tf_model = model->model;
11801198 TFContext *ctx = &tf_model->ctx;
11811199 TFRequestItem *request;
1182− DNNReturnType ret;
1200+ int ret;
11831201
11841202 if (ff_queue_size(tf_model->lltask_queue) == 0) {
11851203 // no pending task need to flush
@@ -1189,7 +1207,7 @@ DNNReturnType ff_dnn_flush_tf(const DNNModel *model) · 3 unmodified lines
11891207 request = ff_safe_queue_pop_front(tf_model->request_queue);
11901208 if (!request) {
11911209 av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n");
1192− return DNN_ERROR;
1210+ return AVERROR(EINVAL);
11931211 }
11941212
11951213 ret = fill_model_input_tf(tf_model, request);
libavfilter/dnn/dnn_backend_tf.h+2−2
@@ -31,9 +31,9 @@ · 30 unmodified lines
3131
3232 DNNModel *ff_dnn_load_model_tf(const char *model_filename, DNNFunctionType func_type, const char *options, AVFilterContext *filter_ctx);
3333
34−DNNReturnType ff_dnn_execute_model_tf(const DNNModel *model, DNNExecBaseParams *exec_params);
34+int ff_dnn_execute_model_tf(const DNNModel *model, DNNExecBaseParams *exec_params);
3535 DNNAsyncStatusType ff_dnn_get_result_tf(const DNNModel *model, AVFrame **in, AVFrame **out);
36−DNNReturnType ff_dnn_flush_tf(const DNNModel *model);
36+int ff_dnn_flush_tf(const DNNModel *model);
3737
3838 void ff_dnn_free_model_tf(DNNModel **model);
3939

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