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.
Showing the changes to libavfilter (2 of 2 files). Show all
Unified · Split
| @@ -90,7 +90,7 @@ static const AVOption dnn_tensorflow_options[] = { · 89 unmodified lines | ||
| 90 | 90 | |
| 91 | 91 | AVFILTER_DEFINE_CLASS(dnn_tensorflow); |
| 92 | 92 | |
| 93 | −static DNNReturnType execute_model_tf(TFRequestItem *request, Queue *lltask_queue); | |
| 93 | +static int execute_model_tf(TFRequestItem *request, Queue *lltask_queue); | |
| 94 | 94 | static void infer_completion_callback(void *args); |
| 95 | 95 | static inline void destroy_request_item(TFRequestItem **arg); |
| 96 | 96 | |
| @@ -152,9 +152,10 @@ static TFInferRequest *tf_create_inference_request(void) · 55 unmodified lines | ||
| 152 | 152 | * |
| 153 | 153 | * @param request pointer to the TFRequestItem for inference |
| 154 | 154 | * @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 | |
| 156 | 157 | */ |
| 157 | −static DNNReturnType tf_start_inference(void *args) | |
| 158 | +static int tf_start_inference(void *args) | |
| 158 | 159 | { |
| 159 | 160 | TFRequestItem *request = args; |
| 160 | 161 | TFInferRequest *infer_request = request->infer_request; |
| @@ -164,7 +165,7 @@ static DNNReturnType tf_start_inference(void *args) · 3 unmodified lines | ||
| 164 | 165 | |
| 165 | 166 | if (!request) { |
| 166 | 167 | av_log(&tf_model->ctx, AV_LOG_ERROR, "TFRequestItem is NULL\n"); |
| 167 | − return DNN_ERROR; | |
| 168 | + return AVERROR(EINVAL); | |
| 168 | 169 | } |
| 169 | 170 | |
| 170 | 171 | TF_SessionRun(tf_model->session, NULL, |
| @@ -178,7 +179,7 @@ static DNNReturnType tf_start_inference(void *args) · 7 unmodified lines | ||
| 178 | 179 | if (ff_safe_queue_push_back(tf_model->request_queue, request) < 0) { |
| 179 | 180 | destroy_request_item(&request); |
| 180 | 181 | } |
| 181 | − return DNN_ERROR; | |
| 182 | + return DNN_GENERIC_ERROR; | |
| 182 | 183 | } |
| 183 | 184 | return DNN_SUCCESS; |
| 184 | 185 | } |
| @@ -202,14 +203,14 @@ static inline void destroy_request_item(TFRequestItem **arg) { · 17 unmodified lines | ||
| 202 | 203 | av_freep(arg); |
| 203 | 204 | } |
| 204 | 205 | |
| 205 | −static DNNReturnType extract_lltask_from_task(TaskItem *task, Queue *lltask_queue) | |
| 206 | +static int extract_lltask_from_task(TaskItem *task, Queue *lltask_queue) | |
| 206 | 207 | { |
| 207 | 208 | TFModel *tf_model = task->model; |
| 208 | 209 | TFContext *ctx = &tf_model->ctx; |
| 209 | 210 | LastLevelTaskItem *lltask = av_malloc(sizeof(*lltask)); |
| 210 | 211 | if (!lltask) { |
| 211 | 212 | av_log(ctx, AV_LOG_ERROR, "Unable to allocate space for LastLevelTaskItem\n"); |
| 212 | − return DNN_ERROR; | |
| 213 | + return AVERROR(ENOMEM); | |
| 213 | 214 | } |
| 214 | 215 | task->inference_todo = 1; |
| 215 | 216 | task->inference_done = 0; |
| @@ -217,7 +218,7 @@ static DNNReturnType extract_lltask_from_task(TaskItem *task, Queue *lltask_queu · 1 unmodified line | ||
| 217 | 218 | if (ff_queue_push_back(lltask_queue, lltask) < 0) { |
| 218 | 219 | av_log(ctx, AV_LOG_ERROR, "Failed to push back lltask_queue.\n"); |
| 219 | 220 | av_freep(&lltask); |
| 220 | − return DNN_ERROR; | |
| 221 | + return AVERROR(ENOMEM); | |
| 221 | 222 | } |
| 222 | 223 | return DNN_SUCCESS; |
| 223 | 224 | } |
| @@ -277,7 +278,7 @@ static TF_Tensor *allocate_input_tensor(const DNNData *input) · 53 unmodified lines | ||
| 277 | 278 | input_dims[1] * input_dims[2] * input_dims[3] * size); |
| 278 | 279 | } |
| 279 | 280 | |
| 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) | |
| 281 | 282 | { |
| 282 | 283 | TFModel *tf_model = model; |
| 283 | 284 | TFContext *ctx = &tf_model->ctx; |
| @@ -288,7 +289,7 @@ static DNNReturnType get_input_tf(void *model, DNNData *input, const char *input · 4 unmodified lines | ||
| 288 | 289 | tf_output.oper = TF_GraphOperationByName(tf_model->graph, input_name); |
| 289 | 290 | if (!tf_output.oper) { |
| 290 | 291 | av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model\n", input_name); |
| 291 | − return DNN_ERROR; | |
| 292 | + return AVERROR(EINVAL); | |
| 292 | 293 | } |
| 293 | 294 | |
| 294 | 295 | tf_output.index = 0; |
| @@ -300,7 +301,7 @@ static DNNReturnType get_input_tf(void *model, DNNData *input, const char *input · 5 unmodified lines | ||
| 300 | 301 | if (TF_GetCode(status) != TF_OK){ |
| 301 | 302 | TF_DeleteStatus(status); |
| 302 | 303 | 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; | |
| 304 | 305 | } |
| 305 | 306 | TF_DeleteStatus(status); |
| 306 | 307 | |
| @@ -313,10 +314,10 @@ static DNNReturnType get_input_tf(void *model, DNNData *input, const char *input · 6 unmodified lines | ||
| 313 | 314 | return DNN_SUCCESS; |
| 314 | 315 | } |
| 315 | 316 | |
| 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, | |
| 317 | 318 | const char *output_name, int *output_width, int *output_height) |
| 318 | 319 | { |
| 319 | − DNNReturnType ret; | |
| 320 | + int ret; | |
| 320 | 321 | TFModel *tf_model = model; |
| 321 | 322 | TFContext *ctx = &tf_model->ctx; |
| 322 | 323 | TaskItem task; |
| @@ -329,20 +330,21 @@ static DNNReturnType get_output_tf(void *model, const char *input_name, int inpu · 6 unmodified lines | ||
| 329 | 330 | .out_frame = NULL, |
| 330 | 331 | }; |
| 331 | 332 | |
| 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) { | |
| 333 | 335 | goto err; |
| 334 | 336 | } |
| 335 | 337 | |
| 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) { | |
| 337 | 340 | av_log(ctx, AV_LOG_ERROR, "unable to extract inference from task.\n"); |
| 338 | − ret = DNN_ERROR; | |
| 339 | 341 | goto err; |
| 340 | 342 | } |
| 341 | 343 | |
| 342 | 344 | request = ff_safe_queue_pop_front(tf_model->request_queue); |
| 343 | 345 | if (!request) { |
| 344 | 346 | av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n"); |
| 345 | − ret = DNN_ERROR; | |
| 347 | + ret = AVERROR(EINVAL); | |
| 346 | 348 | goto err; |
| 347 | 349 | } |
| 348 | 350 | |
| @@ -386,7 +388,7 @@ static int hex_to_data(uint8_t *data, const char *p) · 37 unmodified lines | ||
| 386 | 388 | return len; |
| 387 | 389 | } |
| 388 | 390 | |
| 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) | |
| 390 | 392 | { |
| 391 | 393 | TFContext *ctx = &tf_model->ctx; |
| 392 | 394 | TF_Buffer *graph_def; |
| @@ -407,7 +409,7 @@ static DNNReturnType load_tf_model(TFModel *tf_model, const char *model_filename · 14 unmodified lines | ||
| 407 | 409 | */ |
| 408 | 410 | if (strncmp(tf_model->ctx.options.sess_config, "0x", 2) != 0) { |
| 409 | 411 | av_log(ctx, AV_LOG_ERROR, "sess_config should start with '0x'\n"); |
| 410 | − return DNN_ERROR; | |
| 412 | + return AVERROR(EINVAL); | |
| 411 | 413 | } |
| 412 | 414 | config = tf_model->ctx.options.sess_config + 2; |
| 413 | 415 | 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 | ||
| 415 | 417 | sess_config = av_mallocz(sess_config_length + AV_INPUT_BUFFER_PADDING_SIZE); |
| 416 | 418 | if (!sess_config) { |
| 417 | 419 | av_log(ctx, AV_LOG_ERROR, "failed to allocate memory\n"); |
| 418 | − return DNN_ERROR; | |
| 420 | + return AVERROR(ENOMEM); | |
| 419 | 421 | } |
| 420 | 422 | if (hex_to_data(sess_config, config) < 0) { |
| 421 | 423 | av_log(ctx, AV_LOG_ERROR, "failed to convert hex to data\n"); |
| 422 | − return DNN_ERROR; | |
| 424 | + return AVERROR(EINVAL); | |
| 423 | 425 | } |
| 424 | 426 | } |
| 425 | 427 | |
| @@ -427,7 +429,7 @@ static DNNReturnType load_tf_model(TFModel *tf_model, const char *model_filename · 1 unmodified line | ||
| 427 | 429 | if (!graph_def){ |
| 428 | 430 | av_log(ctx, AV_LOG_ERROR, "Failed to read model \"%s\" graph\n", model_filename); |
| 429 | 431 | av_freep(&sess_config); |
| 430 | − return DNN_ERROR; | |
| 432 | + return AVERROR(EINVAL); | |
| 431 | 433 | } |
| 432 | 434 | tf_model->graph = TF_NewGraph(); |
| 433 | 435 | tf_model->status = TF_NewStatus(); |
| @@ -440,7 +442,7 @@ static DNNReturnType load_tf_model(TFModel *tf_model, const char *model_filename · 6 unmodified lines | ||
| 440 | 442 | TF_DeleteStatus(tf_model->status); |
| 441 | 443 | av_log(ctx, AV_LOG_ERROR, "Failed to import serialized graph to model graph\n"); |
| 442 | 444 | av_freep(&sess_config); |
| 443 | − return DNN_ERROR; | |
| 445 | + return DNN_GENERIC_ERROR; | |
| 444 | 446 | } |
| 445 | 447 | |
| 446 | 448 | 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 | ||
| 455 | 457 | TF_DeleteSessionOptions(sess_opts); |
| 456 | 458 | av_log(ctx, AV_LOG_ERROR, "Failed to set config for sess options with %s\n", |
| 457 | 459 | tf_model->ctx.options.sess_config); |
| 458 | − return DNN_ERROR; | |
| 460 | + return DNN_GENERIC_ERROR; | |
| 459 | 461 | } |
| 460 | 462 | } |
| 461 | 463 | |
| @@ -466,7 +468,7 @@ static DNNReturnType load_tf_model(TFModel *tf_model, const char *model_filename · 4 unmodified lines | ||
| 466 | 468 | TF_DeleteGraph(tf_model->graph); |
| 467 | 469 | TF_DeleteStatus(tf_model->status); |
| 468 | 470 | av_log(ctx, AV_LOG_ERROR, "Failed to create new session with model graph\n"); |
| 469 | − return DNN_ERROR; | |
| 471 | + return DNN_GENERIC_ERROR; | |
| 470 | 472 | } |
| 471 | 473 | |
| 472 | 474 | // 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 | ||
| 481 | 483 | TF_DeleteGraph(tf_model->graph); |
| 482 | 484 | TF_DeleteStatus(tf_model->status); |
| 483 | 485 | av_log(ctx, AV_LOG_ERROR, "Failed to run session when initializing\n"); |
| 484 | − return DNN_ERROR; | |
| 486 | + return DNN_GENERIC_ERROR; | |
| 485 | 487 | } |
| 486 | 488 | } |
| 487 | 489 | |
| @@ -490,7 +492,7 @@ static DNNReturnType load_tf_model(TFModel *tf_model, const char *model_filename · 2 unmodified lines | ||
| 490 | 492 | |
| 491 | 493 | #define NAME_BUFFER_SIZE 256 |
| 492 | 494 | |
| 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, | |
| 494 | 496 | ConvolutionalParams* params, const int layer) |
| 495 | 497 | { |
| 496 | 498 | TFContext *ctx = &tf_model->ctx; |
| @@ -594,7 +596,7 @@ static DNNReturnType add_conv_layer(TFModel *tf_model, TF_Operation *transpose_o · 97 unmodified lines | ||
| 594 | 596 | break; |
| 595 | 597 | default: |
| 596 | 598 | avpriv_report_missing_feature(ctx, "convolutional activation function %d", params->activation); |
| 597 | − return DNN_ERROR; | |
| 599 | + return AVERROR(ENOSYS); | |
| 598 | 600 | } |
| 599 | 601 | input.oper = *cur_op; |
| 600 | 602 | TF_AddInput(op_desc, input); |
| @@ -609,10 +611,10 @@ err: · 8 unmodified lines | ||
| 609 | 611 | TF_DeleteTensor(kernel_tensor); |
| 610 | 612 | TF_DeleteTensor(biases_tensor); |
| 611 | 613 | av_log(ctx, AV_LOG_ERROR, "Failed to add conv layer %d\n", layer); |
| 612 | − return DNN_ERROR; | |
| 614 | + return DNN_GENERIC_ERROR; | |
| 613 | 615 | } |
| 614 | 616 | |
| 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, | |
| 616 | 618 | DepthToSpaceParams *params, const int layer) |
| 617 | 619 | { |
| 618 | 620 | TFContext *ctx = &tf_model->ctx; |
| @@ -630,13 +632,13 @@ static DNNReturnType add_depth_to_space_layer(TFModel *tf_model, TF_Operation ** · 11 unmodified lines | ||
| 630 | 632 | *cur_op = TF_FinishOperation(op_desc, tf_model->status); |
| 631 | 633 | if (TF_GetCode(tf_model->status) != TF_OK){ |
| 632 | 634 | 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; | |
| 634 | 636 | } |
| 635 | 637 | |
| 636 | 638 | return DNN_SUCCESS; |
| 637 | 639 | } |
| 638 | 640 | |
| 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, | |
| 640 | 642 | LayerPadParams *params, const int layer) |
| 641 | 643 | { |
| 642 | 644 | TFContext *ctx = &tf_model->ctx; |
| @@ -666,13 +668,13 @@ static DNNReturnType add_pad_layer(TFModel *tf_model, TF_Operation **cur_op, · 23 unmodified lines | ||
| 666 | 668 | if (TF_GetCode(tf_model->status) != TF_OK){ |
| 667 | 669 | TF_DeleteTensor(tensor); |
| 668 | 670 | 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; | |
| 670 | 672 | } |
| 671 | 673 | op = TF_FinishOperation(op_desc, tf_model->status); |
| 672 | 674 | if (TF_GetCode(tf_model->status) != TF_OK){ |
| 673 | 675 | TF_DeleteTensor(tensor); |
| 674 | 676 | av_log(ctx, AV_LOG_ERROR, "Failed to add pad to layer %d\n", layer); |
| 675 | − return DNN_ERROR; | |
| 677 | + return DNN_GENERIC_ERROR; | |
| 676 | 678 | } |
| 677 | 679 | |
| 678 | 680 | 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 | ||
| 688 | 690 | if (TF_GetCode(tf_model->status) != TF_OK){ |
| 689 | 691 | TF_DeleteTensor(tensor); |
| 690 | 692 | 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; | |
| 692 | 694 | } |
| 693 | 695 | |
| 694 | 696 | return DNN_SUCCESS; |
| 695 | 697 | } |
| 696 | 698 | |
| 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, | |
| 698 | 700 | DnnLayerMaximumParams *params, const int layer) |
| 699 | 701 | { |
| 700 | 702 | TFContext *ctx = &tf_model->ctx; |
| @@ -716,13 +718,13 @@ static DNNReturnType add_maximum_layer(TFModel *tf_model, TF_Operation **cur_op, · 15 unmodified lines | ||
| 716 | 718 | if (TF_GetCode(tf_model->status) != TF_OK){ |
| 717 | 719 | TF_DeleteTensor(tensor); |
| 718 | 720 | 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; | |
| 720 | 722 | } |
| 721 | 723 | op = TF_FinishOperation(op_desc, tf_model->status); |
| 722 | 724 | if (TF_GetCode(tf_model->status) != TF_OK){ |
| 723 | 725 | TF_DeleteTensor(tensor); |
| 724 | 726 | 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; | |
| 726 | 728 | } |
| 727 | 729 | |
| 728 | 730 | 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 | ||
| 737 | 739 | if (TF_GetCode(tf_model->status) != TF_OK){ |
| 738 | 740 | TF_DeleteTensor(tensor); |
| 739 | 741 | av_log(ctx, AV_LOG_ERROR, "Failed to add maximum to layer %d\n", layer); |
| 740 | − return DNN_ERROR; | |
| 742 | + return DNN_GENERIC_ERROR; | |
| 741 | 743 | } |
| 742 | 744 | |
| 743 | 745 | return DNN_SUCCESS; |
| 744 | 746 | } |
| 745 | 747 | |
| 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) | |
| 747 | 749 | { |
| 748 | 750 | TFContext *ctx = &tf_model->ctx; |
| 749 | 751 | int32_t layer; |
| @@ -755,14 +757,14 @@ static DNNReturnType load_native_model(TFModel *tf_model, const char *model_file · 5 unmodified lines | ||
| 755 | 757 | int32_t *transpose_perm; |
| 756 | 758 | int64_t transpose_perm_shape[] = {4}; |
| 757 | 759 | int64_t input_shape[] = {1, -1, -1, -1}; |
| 758 | − DNNReturnType layer_add_res; | |
| 760 | + int layer_add_res; | |
| 759 | 761 | DNNModel *model = NULL; |
| 760 | 762 | NativeModel *native_model; |
| 761 | 763 | |
| 762 | 764 | model = ff_dnn_load_model_native(model_filename, DFT_PROCESS_FRAME, NULL, NULL); |
| 763 | 765 | if (!model){ |
| 764 | 766 | av_log(ctx, AV_LOG_ERROR, "Failed to load native model\n"); |
| 765 | − return DNN_ERROR; | |
| 767 | + return AVERROR(EINVAL); | |
| 766 | 768 | } |
| 767 | 769 | |
| 768 | 770 | native_model = model->model; |
| @@ -775,7 +777,7 @@ static DNNReturnType load_native_model(TFModel *tf_model, const char *model_file · 6 unmodified lines | ||
| 775 | 777 | TF_DeleteGraph(tf_model->graph); \ |
| 776 | 778 | TF_DeleteStatus(tf_model->status); \ |
| 777 | 779 | 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; \ | |
| 779 | 781 | } |
| 780 | 782 | |
| 781 | 783 | op_desc = TF_NewOperation(tf_model->graph, "Placeholder", "x"); |
| @@ -942,19 +944,21 @@ err: · 160 unmodified lines | ||
| 942 | 944 | return NULL; |
| 943 | 945 | } |
| 944 | 946 | |
| 945 | −static DNNReturnType fill_model_input_tf(TFModel *tf_model, TFRequestItem *request) { | |
| 947 | +static int fill_model_input_tf(TFModel *tf_model, TFRequestItem *request) { | |
| 946 | 948 | DNNData input; |
| 947 | 949 | LastLevelTaskItem *lltask; |
| 948 | 950 | TaskItem *task; |
| 949 | 951 | TFInferRequest *infer_request; |
| 950 | 952 | TFContext *ctx = &tf_model->ctx; |
| 953 | + int ret = 0; | |
| 951 | 954 | |
| 952 | 955 | lltask = ff_queue_pop_front(tf_model->lltask_queue); |
| 953 | 956 | av_assert0(lltask); |
| 954 | 957 | task = lltask->task; |
| 955 | 958 | request->lltask = lltask; |
| 956 | 959 | |
| 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) { | |
| 958 | 962 | goto err; |
| 959 | 963 | } |
| 960 | 964 | |
| @@ -965,12 +969,14 @@ static DNNReturnType fill_model_input_tf(TFModel *tf_model, TFRequestItem *reque · 4 unmodified lines | ||
| 965 | 969 | infer_request->tf_input = av_malloc(sizeof(TF_Output)); |
| 966 | 970 | if (!infer_request->tf_input) { |
| 967 | 971 | av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for input tensor\n"); |
| 972 | + ret = AVERROR(ENOMEM); | |
| 968 | 973 | goto err; |
| 969 | 974 | } |
| 970 | 975 | |
| 971 | 976 | infer_request->tf_input->oper = TF_GraphOperationByName(tf_model->graph, task->input_name); |
| 972 | 977 | if (!infer_request->tf_input->oper){ |
| 973 | 978 | av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model\n", task->input_name); |
| 979 | + ret = DNN_GENERIC_ERROR; | |
| 974 | 980 | goto err; |
| 975 | 981 | } |
| 976 | 982 | infer_request->tf_input->index = 0; |
| @@ -978,6 +984,7 @@ static DNNReturnType fill_model_input_tf(TFModel *tf_model, TFRequestItem *reque · 1 unmodified line | ||
| 978 | 984 | infer_request->input_tensor = allocate_input_tensor(&input); |
| 979 | 985 | if (!infer_request->input_tensor){ |
| 980 | 986 | av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for input tensor\n"); |
| 987 | + ret = AVERROR(ENOMEM); | |
| 981 | 988 | goto err; |
| 982 | 989 | } |
| 983 | 990 | 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 | ||
| 1003 | 1010 | infer_request->tf_outputs = av_malloc_array(task->nb_output, sizeof(TF_Output)); |
| 1004 | 1011 | if (infer_request->tf_outputs == NULL) { |
| 1005 | 1012 | av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for *tf_outputs\n"); |
| 1013 | + ret = AVERROR(ENOMEM); | |
| 1006 | 1014 | goto err; |
| 1007 | 1015 | } |
| 1008 | 1016 | |
| 1009 | 1017 | infer_request->output_tensors = av_calloc(task->nb_output, sizeof(*infer_request->output_tensors)); |
| 1010 | 1018 | if (!infer_request->output_tensors) { |
| 1011 | 1019 | av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for output tensor\n"); |
| 1020 | + ret = AVERROR(ENOMEM); | |
| 1012 | 1021 | goto err; |
| 1013 | 1022 | } |
| 1014 | 1023 | |
| @@ -1017,6 +1026,7 @@ static DNNReturnType fill_model_input_tf(TFModel *tf_model, TFRequestItem *reque · 2 unmodified lines | ||
| 1017 | 1026 | infer_request->tf_outputs[i].oper = TF_GraphOperationByName(tf_model->graph, task->output_names[i]); |
| 1018 | 1027 | if (!infer_request->tf_outputs[i].oper) { |
| 1019 | 1028 | av_log(ctx, AV_LOG_ERROR, "Could not find output \"%s\" in model\n", task->output_names[i]); |
| 1029 | + ret = DNN_GENERIC_ERROR; | |
| 1020 | 1030 | goto err; |
| 1021 | 1031 | } |
| 1022 | 1032 | 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 | ||
| 1025 | 1035 | return DNN_SUCCESS; |
| 1026 | 1036 | err: |
| 1027 | 1037 | tf_free_request(infer_request); |
| 1028 | − return DNN_ERROR; | |
| 1038 | + return ret; | |
| 1029 | 1039 | } |
| 1030 | 1040 | |
| 1031 | 1041 | static void infer_completion_callback(void *args) { |
| @@ -1086,12 +1096,13 @@ err: · 54 unmodified lines | ||
| 1086 | 1096 | } |
| 1087 | 1097 | } |
| 1088 | 1098 | |
| 1089 | −static DNNReturnType execute_model_tf(TFRequestItem *request, Queue *lltask_queue) | |
| 1099 | +static int execute_model_tf(TFRequestItem *request, Queue *lltask_queue) | |
| 1090 | 1100 | { |
| 1091 | 1101 | TFModel *tf_model; |
| 1092 | 1102 | TFContext *ctx; |
| 1093 | 1103 | LastLevelTaskItem *lltask; |
| 1094 | 1104 | TaskItem *task; |
| 1105 | + int ret = 0; | |
| 1095 | 1106 | |
| 1096 | 1107 | if (ff_queue_size(lltask_queue) == 0) { |
| 1097 | 1108 | destroy_request_item(&request); |
| @@ -1103,7 +1114,8 @@ static DNNReturnType execute_model_tf(TFRequestItem *request, Queue *lltask_queu · 5 unmodified lines | ||
| 1103 | 1114 | tf_model = task->model; |
| 1104 | 1115 | ctx = &tf_model->ctx; |
| 1105 | 1116 | |
| 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) { | |
| 1107 | 1119 | goto err; |
| 1108 | 1120 | } |
| 1109 | 1121 | |
| @@ -1112,58 +1124,64 @@ static DNNReturnType execute_model_tf(TFRequestItem *request, Queue *lltask_queu · 2 unmodified lines | ||
| 1112 | 1124 | goto err; |
| 1113 | 1125 | } |
| 1114 | 1126 | 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) { | |
| 1117 | 1131 | goto err; |
| 1118 | 1132 | } |
| 1119 | 1133 | 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; | |
| 1121 | 1135 | } |
| 1122 | 1136 | err: |
| 1123 | 1137 | tf_free_request(request->infer_request); |
| 1124 | 1138 | if (ff_safe_queue_push_back(tf_model->request_queue, request) < 0) { |
| 1125 | 1139 | destroy_request_item(&request); |
| 1126 | 1140 | } |
| 1127 | − return DNN_ERROR; | |
| 1141 | + return ret; | |
| 1128 | 1142 | } |
| 1129 | 1143 | |
| 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) | |
| 1131 | 1145 | { |
| 1132 | 1146 | TFModel *tf_model = model->model; |
| 1133 | 1147 | TFContext *ctx = &tf_model->ctx; |
| 1134 | 1148 | TaskItem *task; |
| 1135 | 1149 | TFRequestItem *request; |
| 1150 | + int ret = 0; | |
| 1136 | 1151 | |
| 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; | |
| 1139 | 1155 | } |
| 1140 | 1156 | |
| 1141 | 1157 | task = av_malloc(sizeof(*task)); |
| 1142 | 1158 | if (!task) { |
| 1143 | 1159 | av_log(ctx, AV_LOG_ERROR, "unable to alloc memory for task item.\n"); |
| 1144 | − return DNN_ERROR; | |
| 1160 | + return AVERROR(ENOMEM); | |
| 1145 | 1161 | } |
| 1146 | 1162 | |
| 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) { | |
| 1148 | 1165 | av_freep(&task); |
| 1149 | − return DNN_ERROR; | |
| 1166 | + return ret; | |
| 1150 | 1167 | } |
| 1151 | 1168 | |
| 1152 | 1169 | if (ff_queue_push_back(tf_model->task_queue, task) < 0) { |
| 1153 | 1170 | av_freep(&task); |
| 1154 | 1171 | av_log(ctx, AV_LOG_ERROR, "unable to push back task_queue.\n"); |
| 1155 | − return DNN_ERROR; | |
| 1172 | + return AVERROR(ENOMEM); | |
| 1156 | 1173 | } |
| 1157 | 1174 | |
| 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) { | |
| 1159 | 1177 | av_log(ctx, AV_LOG_ERROR, "unable to extract last level task from task.\n"); |
| 1160 | − return DNN_ERROR; | |
| 1178 | + return ret; | |
| 1161 | 1179 | } |
| 1162 | 1180 | |
| 1163 | 1181 | request = ff_safe_queue_pop_front(tf_model->request_queue); |
| 1164 | 1182 | if (!request) { |
| 1165 | 1183 | av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n"); |
| 1166 | − return DNN_ERROR; | |
| 1184 | + return AVERROR(EINVAL); | |
| 1167 | 1185 | } |
| 1168 | 1186 | return execute_model_tf(request, tf_model->lltask_queue); |
| 1169 | 1187 | } |
| @@ -1174,12 +1192,12 @@ DNNAsyncStatusType ff_dnn_get_result_tf(const DNNModel *model, AVFrame **in, AVF · 4 unmodified lines | ||
| 1174 | 1192 | return ff_dnn_get_result_common(tf_model->task_queue, in, out); |
| 1175 | 1193 | } |
| 1176 | 1194 | |
| 1177 | −DNNReturnType ff_dnn_flush_tf(const DNNModel *model) | |
| 1195 | +int ff_dnn_flush_tf(const DNNModel *model) | |
| 1178 | 1196 | { |
| 1179 | 1197 | TFModel *tf_model = model->model; |
| 1180 | 1198 | TFContext *ctx = &tf_model->ctx; |
| 1181 | 1199 | TFRequestItem *request; |
| 1182 | − DNNReturnType ret; | |
| 1200 | + int ret; | |
| 1183 | 1201 | |
| 1184 | 1202 | if (ff_queue_size(tf_model->lltask_queue) == 0) { |
| 1185 | 1203 | // no pending task need to flush |
| @@ -1189,7 +1207,7 @@ DNNReturnType ff_dnn_flush_tf(const DNNModel *model) · 3 unmodified lines | ||
| 1189 | 1207 | request = ff_safe_queue_pop_front(tf_model->request_queue); |
| 1190 | 1208 | if (!request) { |
| 1191 | 1209 | av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n"); |
| 1192 | − return DNN_ERROR; | |
| 1210 | + return AVERROR(EINVAL); | |
| 1193 | 1211 | } |
| 1194 | 1212 | |
| 1195 | 1213 | ret = fill_model_input_tf(tf_model, request); |
| @@ -31,9 +31,9 @@ · 30 unmodified lines | ||
| 31 | 31 | |
| 32 | 32 | DNNModel *ff_dnn_load_model_tf(const char *model_filename, DNNFunctionType func_type, const char *options, AVFilterContext *filter_ctx); |
| 33 | 33 | |
| 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); | |
| 35 | 35 | 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); | |
| 37 | 37 | |
| 38 | 38 | void ff_dnn_free_model_tf(DNNModel **model); |
| 39 | 39 | |