remove the requirment that the name of DNN model input/output should be "x"/"y",
Showing the changes to libavfilter (4 of 4 files). Show all
Unified · Split
| @@ -25,7 +25,7 @@ · 24 unmodified lines | |||
| 25 | 25 | ||
| 26 | #include "dnn_backend_native.h" | 26 | #include "dnn_backend_native.h" |
| 27 | 27 | ||
| 28 | static DNNReturnType set_input_output_native(void *model, DNNData *input, DNNData *output) | 28 | static DNNReturnType set_input_output_native(void *model, DNNData *input, const char *input_name, DNNData *output, const char *output_name) |
| 29 | { | 29 | { |
| 30 | ConvolutionalNetwork *network = (ConvolutionalNetwork *)model; | 30 | ConvolutionalNetwork *network = (ConvolutionalNetwork *)model; |
| 31 | InputParams *input_params; | 31 | InputParams *input_params; |
| @@ -76,7 +76,7 @@ static TF_Buffer *read_graph(const char *model_filename) · 75 unmodified lines | |||
| 76 | return graph_buf; | 76 | return graph_buf; |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | static DNNReturnType set_input_output_tf(void *model, DNNData *input, DNNData *output) | 79 | static DNNReturnType set_input_output_tf(void *model, DNNData *input, const char *input_name, DNNData *output, const char *output_name) |
| 80 | { | 80 | { |
| 81 | TFModel *tf_model = (TFModel *)model; | 81 | TFModel *tf_model = (TFModel *)model; |
| 82 | int64_t input_dims[] = {1, input->height, input->width, input->channels}; | 82 | int64_t input_dims[] = {1, input->height, input->width, input->channels}; |
| @@ -84,8 +84,8 @@ static DNNReturnType set_input_output_tf(void *model, DNNData *input, DNNData *o · 1 unmodified line | |||
| 84 | const TF_Operation *init_op = TF_GraphOperationByName(tf_model->graph, "init"); | 84 | const TF_Operation *init_op = TF_GraphOperationByName(tf_model->graph, "init"); |
| 85 | TF_Tensor *output_tensor; | 85 | TF_Tensor *output_tensor; |
| 86 | 86 | ||
| 87 | // Input operation should be named 'x' | 87 | // Input operation |
| 88 | tf_model->input.oper = TF_GraphOperationByName(tf_model->graph, "x"); | 88 | tf_model->input.oper = TF_GraphOperationByName(tf_model->graph, input_name); |
| 89 | if (!tf_model->input.oper){ | 89 | if (!tf_model->input.oper){ |
| 90 | return DNN_ERROR; | 90 | return DNN_ERROR; |
| 91 | } | 91 | } |
| @@ -100,8 +100,8 @@ static DNNReturnType set_input_output_tf(void *model, DNNData *input, DNNData *o · 8 unmodified lines | |||
| 100 | } | 100 | } |
| 101 | input->data = (float *)TF_TensorData(tf_model->input_tensor); | 101 | input->data = (float *)TF_TensorData(tf_model->input_tensor); |
| 102 | 102 | ||
| 103 | // Output operation should be named 'y' | 103 | // Output operation |
| 104 | tf_model->output.oper = TF_GraphOperationByName(tf_model->graph, "y"); | 104 | tf_model->output.oper = TF_GraphOperationByName(tf_model->graph, output_name); |
| 105 | if (!tf_model->output.oper){ | 105 | if (!tf_model->output.oper){ |
| 106 | return DNN_ERROR; | 106 | return DNN_ERROR; |
| 107 | } | 107 | } |
| @@ -40,7 +40,7 @@ typedef struct DNNModel{ · 39 unmodified lines | |||
| 40 | void *model; | 40 | void *model; |
| 41 | // Sets model input and output, while allocating additional memory for intermediate calculations. | 41 | // Sets model input and output, while allocating additional memory for intermediate calculations. |
| 42 | // Should be called at least once before model execution. | 42 | // Should be called at least once before model execution. |
| 43 | DNNReturnType (*set_input_output)(void *model, DNNData *input, DNNData *output); | 43 | DNNReturnType (*set_input_output)(void *model, DNNData *input, const char *input_name, DNNData *output, const char *output_name); |
| 44 | } DNNModel; | 44 | } DNNModel; |
| 45 | 45 | ||
| 46 | // Stores pointers to functions for loading, executing, freeing DNN models for one of the backends. | 46 | // Stores pointers to functions for loading, executing, freeing DNN models for one of the backends. |
| @@ -121,7 +121,7 @@ static int config_props(AVFilterLink *inlink) · 120 unmodified lines | |||
| 121 | sr_context->input.height = inlink->h * sr_context->scale_factor; | 121 | sr_context->input.height = inlink->h * sr_context->scale_factor; |
| 122 | sr_context->input.channels = 1; | 122 | sr_context->input.channels = 1; |
| 123 | 123 | ||
| 124 | result = (sr_context->model->set_input_output)(sr_context->model->model, &sr_context->input, &sr_context->output); | 124 | result = (sr_context->model->set_input_output)(sr_context->model->model, &sr_context->input, "x", &sr_context->output, "y"); |
| 125 | if (result != DNN_SUCCESS){ | 125 | if (result != DNN_SUCCESS){ |
| 126 | av_log(context, AV_LOG_ERROR, "could not set input and output for the model\n"); | 126 | av_log(context, AV_LOG_ERROR, "could not set input and output for the model\n"); |
| 127 | return AVERROR(EIO); | 127 | return AVERROR(EIO); |
| @@ -130,7 +130,7 @@ static int config_props(AVFilterLink *inlink) · 2 unmodified lines | |||
| 130 | if (sr_context->input.height != sr_context->output.height || sr_context->input.width != sr_context->output.width){ | 130 | if (sr_context->input.height != sr_context->output.height || sr_context->input.width != sr_context->output.width){ |
| 131 | sr_context->input.width = inlink->w; | 131 | sr_context->input.width = inlink->w; |
| 132 | sr_context->input.height = inlink->h; | 132 | sr_context->input.height = inlink->h; |
| 133 | result = (sr_context->model->set_input_output)(sr_context->model->model, &sr_context->input, &sr_context->output); | 133 | result = (sr_context->model->set_input_output)(sr_context->model->model, &sr_context->input, "x", &sr_context->output, "y"); |
| 134 | if (result != DNN_SUCCESS){ | 134 | if (result != DNN_SUCCESS){ |
| 135 | av_log(context, AV_LOG_ERROR, "could not set input and output for the model\n"); | 135 | av_log(context, AV_LOG_ERROR, "could not set input and output for the model\n"); |
| 136 | return AVERROR(EIO); | 136 | return AVERROR(EIO); |