Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -37,8 +37,8 @@ · 36 unmodified lines | |||
| 37 | #include <tensorflow/c/c_api.h> | 37 | #include <tensorflow/c/c_api.h> |
| 38 | 38 | ||
| 39 | typedef struct TFModel { | 39 | typedef struct TFModel { |
| 40 | DNNModel model; | ||
| 40 | DnnContext *ctx; | 41 | DnnContext *ctx; |
| 41 | DNNModel *model; | ||
| 42 | TF_Graph *graph; | 42 | TF_Graph *graph; |
| 43 | TF_Session *session; | 43 | TF_Session *session; |
| 44 | TF_Status *status; | 44 | TF_Status *status; |
| @@ -518,7 +518,7 @@ static void dnn_free_model_tf(DNNModel **model) · 473 unmodified lines | |||
| 518 | TF_DeleteStatus(tf_model->status); | 518 | TF_DeleteStatus(tf_model->status); |
| 519 | } | 519 | } |
| 520 | av_freep(&tf_model); | 520 | av_freep(&tf_model); |
| 521 | av_freep(&model); | 521 | *model = NULL; |
| 522 | } | 522 | } |
| 523 | 523 | ||
| 524 | static DNNModel *dnn_load_model_tf(DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *filter_ctx) | 524 | static DNNModel *dnn_load_model_tf(DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *filter_ctx) |
| @@ -526,18 +526,11 @@ static DNNModel *dnn_load_model_tf(DnnContext *ctx, DNNFunctionType func_type, A · 1 unmodified line | |||
| 526 | DNNModel *model = NULL; | 526 | DNNModel *model = NULL; |
| 527 | TFModel *tf_model = NULL; | 527 | TFModel *tf_model = NULL; |
| 528 | 528 | ||
| 529 | model = av_mallocz(sizeof(DNNModel)); | ||
| 530 | if (!model){ | ||
| 531 | return NULL; | ||
| 532 | } | ||
| 533 | |||
| 534 | tf_model = av_mallocz(sizeof(TFModel)); | 529 | tf_model = av_mallocz(sizeof(TFModel)); |
| 535 | if (!tf_model){ | 530 | if (!tf_model) |
| 536 | av_freep(&model); | ||
| 537 | return NULL; | 531 | return NULL; |
| 538 | } | 532 | model = &tf_model->model; |
| 539 | model->model = tf_model; | 533 | model->model = tf_model; |
| 540 | tf_model->model = model; | ||
| 541 | tf_model->ctx = ctx; | 534 | tf_model->ctx = ctx; |
| 542 | 535 | ||
| 543 | if (load_tf_model(tf_model, ctx->model_filename) != 0){ | 536 | if (load_tf_model(tf_model, ctx->model_filename) != 0){ |
| @@ -650,11 +643,11 @@ static int fill_model_input_tf(TFModel *tf_model, TFRequestItem *request) { · 106 unmodified lines | |||
| 650 | } | 643 | } |
| 651 | input.data = (float *)TF_TensorData(infer_request->input_tensor); | 644 | input.data = (float *)TF_TensorData(infer_request->input_tensor); |
| 652 | 645 | ||
| 653 | switch (tf_model->model->func_type) { | 646 | switch (tf_model->model.func_type) { |
| 654 | case DFT_PROCESS_FRAME: | 647 | case DFT_PROCESS_FRAME: |
| 655 | if (task->do_ioproc) { | 648 | if (task->do_ioproc) { |
| 656 | if (tf_model->model->frame_pre_proc != NULL) { | 649 | if (tf_model->model.frame_pre_proc != NULL) { |
| 657 | tf_model->model->frame_pre_proc(task->in_frame, &input, tf_model->model->filter_ctx); | 650 | tf_model->model.frame_pre_proc(task->in_frame, &input, tf_model->model.filter_ctx); |
| 658 | } else { | 651 | } else { |
| 659 | ff_proc_from_frame_to_dnn(task->in_frame, &input, ctx); | 652 | ff_proc_from_frame_to_dnn(task->in_frame, &input, ctx); |
| 660 | } | 653 | } |
| @@ -664,7 +657,7 @@ static int fill_model_input_tf(TFModel *tf_model, TFRequestItem *request) { · 3 unmodified lines | |||
| 664 | ff_frame_to_dnn_detect(task->in_frame, &input, ctx); | 657 | ff_frame_to_dnn_detect(task->in_frame, &input, ctx); |
| 665 | break; | 658 | break; |
| 666 | default: | 659 | default: |
| 667 | avpriv_report_missing_feature(ctx, "model function type %d", tf_model->model->func_type); | 660 | avpriv_report_missing_feature(ctx, "model function type %d", tf_model->model.func_type); |
| 668 | break; | 661 | break; |
| 669 | } | 662 | } |
| 670 | 663 | ||
| @@ -724,12 +717,12 @@ static void infer_completion_callback(void *args) { · 53 unmodified lines | |||
| 724 | outputs[i].data = TF_TensorData(infer_request->output_tensors[i]); | 717 | outputs[i].data = TF_TensorData(infer_request->output_tensors[i]); |
| 725 | outputs[i].dt = (DNNDataType)TF_TensorType(infer_request->output_tensors[i]); | 718 | outputs[i].dt = (DNNDataType)TF_TensorType(infer_request->output_tensors[i]); |
| 726 | } | 719 | } |
| 727 | switch (tf_model->model->func_type) { | 720 | switch (tf_model->model.func_type) { |
| 728 | case DFT_PROCESS_FRAME: | 721 | case DFT_PROCESS_FRAME: |
| 729 | //it only support 1 output if it's frame in & frame out | 722 | //it only support 1 output if it's frame in & frame out |
| 730 | if (task->do_ioproc) { | 723 | if (task->do_ioproc) { |
| 731 | if (tf_model->model->frame_post_proc != NULL) { | 724 | if (tf_model->model.frame_post_proc != NULL) { |
| 732 | tf_model->model->frame_post_proc(task->out_frame, outputs, tf_model->model->filter_ctx); | 725 | tf_model->model.frame_post_proc(task->out_frame, outputs, tf_model->model.filter_ctx); |
| 733 | } else { | 726 | } else { |
| 734 | ff_proc_from_dnn_to_frame(task->out_frame, outputs, ctx); | 727 | ff_proc_from_dnn_to_frame(task->out_frame, outputs, ctx); |
| 735 | } | 728 | } |
| @@ -741,11 +734,11 @@ static void infer_completion_callback(void *args) { · 5 unmodified lines | |||
| 741 | } | 734 | } |
| 742 | break; | 735 | break; |
| 743 | case DFT_ANALYTICS_DETECT: | 736 | case DFT_ANALYTICS_DETECT: |
| 744 | if (!tf_model->model->detect_post_proc) { | 737 | if (!tf_model->model.detect_post_proc) { |
| 745 | av_log(ctx, AV_LOG_ERROR, "Detect filter needs provide post proc\n"); | 738 | av_log(ctx, AV_LOG_ERROR, "Detect filter needs provide post proc\n"); |
| 746 | return; | 739 | return; |
| 747 | } | 740 | } |
| 748 | tf_model->model->detect_post_proc(task->in_frame, outputs, task->nb_output, tf_model->model->filter_ctx); | 741 | tf_model->model.detect_post_proc(task->in_frame, outputs, task->nb_output, tf_model->model.filter_ctx); |
| 749 | break; | 742 | break; |
| 750 | default: | 743 | default: |
| 751 | av_log(ctx, AV_LOG_ERROR, "Tensorflow backend does not support this kind of dnn filter now\n"); | 744 | av_log(ctx, AV_LOG_ERROR, "Tensorflow backend does not support this kind of dnn filter now\n"); |