Unified · Split
| @@ -37,8 +37,8 @@ · 36 unmodified lines | ||
| 37 | 37 | #include <tensorflow/c/c_api.h> |
| 38 | 38 | |
| 39 | 39 | typedef struct TFModel { |
| 40 | + DNNModel model; | |
| 40 | 41 | DnnContext *ctx; |
| 41 | − DNNModel *model; | |
| 42 | 42 | TF_Graph *graph; |
| 43 | 43 | TF_Session *session; |
| 44 | 44 | TF_Status *status; |
| @@ -518,7 +518,7 @@ static void dnn_free_model_tf(DNNModel **model) · 473 unmodified lines | ||
| 518 | 518 | TF_DeleteStatus(tf_model->status); |
| 519 | 519 | } |
| 520 | 520 | av_freep(&tf_model); |
| 521 | − av_freep(&model); | |
| 521 | + *model = NULL; | |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 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 | 526 | DNNModel *model = NULL; |
| 527 | 527 | TFModel *tf_model = NULL; |
| 528 | 528 | |
| 529 | − model = av_mallocz(sizeof(DNNModel)); | |
| 530 | − if (!model){ | |
| 531 | − return NULL; | |
| 532 | − } | |
| 533 | − | |
| 534 | 529 | tf_model = av_mallocz(sizeof(TFModel)); |
| 535 | − if (!tf_model){ | |
| 536 | − av_freep(&model); | |
| 530 | + if (!tf_model) | |
| 537 | 531 | return NULL; |
| 538 | − } | |
| 532 | + model = &tf_model->model; | |
| 539 | 533 | model->model = tf_model; |
| 540 | − tf_model->model = model; | |
| 541 | 534 | tf_model->ctx = ctx; |
| 542 | 535 | |
| 543 | 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 | 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 | 647 | case DFT_PROCESS_FRAME: |
| 655 | 648 | if (task->do_ioproc) { |
| 656 | − if (tf_model->model->frame_pre_proc != NULL) { | |
| 657 | − tf_model->model->frame_pre_proc(task->in_frame, &input, tf_model->model->filter_ctx); | |
| 649 | + if (tf_model->model.frame_pre_proc != NULL) { | |
| 650 | + tf_model->model.frame_pre_proc(task->in_frame, &input, tf_model->model.filter_ctx); | |
| 658 | 651 | } else { |
| 659 | 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 | 657 | ff_frame_to_dnn_detect(task->in_frame, &input, ctx); |
| 665 | 658 | break; |
| 666 | 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 | 661 | break; |
| 669 | 662 | } |
| 670 | 663 | |
| @@ -724,12 +717,12 @@ static void infer_completion_callback(void *args) { · 53 unmodified lines | ||
| 724 | 717 | outputs[i].data = TF_TensorData(infer_request->output_tensors[i]); |
| 725 | 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 | 721 | case DFT_PROCESS_FRAME: |
| 729 | 722 | //it only support 1 output if it's frame in & frame out |
| 730 | 723 | if (task->do_ioproc) { |
| 731 | − if (tf_model->model->frame_post_proc != NULL) { | |
| 732 | − tf_model->model->frame_post_proc(task->out_frame, outputs, tf_model->model->filter_ctx); | |
| 724 | + if (tf_model->model.frame_post_proc != NULL) { | |
| 725 | + tf_model->model.frame_post_proc(task->out_frame, outputs, tf_model->model.filter_ctx); | |
| 733 | 726 | } else { |
| 734 | 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 | 735 | break; |
| 743 | 736 | case DFT_ANALYTICS_DETECT: |
| 744 | − if (!tf_model->model->detect_post_proc) { | |
| 737 | + if (!tf_model->model.detect_post_proc) { | |
| 745 | 738 | av_log(ctx, AV_LOG_ERROR, "Detect filter needs provide post proc\n"); |
| 746 | 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 | 742 | break; |
| 750 | 743 | default: |
| 751 | 744 | av_log(ctx, AV_LOG_ERROR, "Tensorflow backend does not support this kind of dnn filter now\n"); |