History

dnn: add backend options when load the model

different backend might need different options for a better performance, so, add the parameter into dnn interface, as a preparation.

Guo, Yejun committed 6 years ago

Commit 0a51abe1 parent 4ed6bca10 files · +17 −10Browse files

Unified · Split

10 files
  1. libavfilter/dnn/dnn_backend_native.c +2 −1
  2. libavfilter/dnn/dnn_backend_native.h +1 −1
  3. libavfilter/dnn/dnn_backend_openvino.c +2 −1
  4. libavfilter/dnn/dnn_backend_openvino.h +1 −1
  5. libavfilter/dnn/dnn_backend_tf.c +2 −1
  6. libavfilter/dnn/dnn_backend_tf.h +1 −1
  7. libavfilter/dnn_interface.h +3 −1
  8. libavfilter/vf_derain.c +1 −1
  9. libavfilter/vf_dnn_processing.c +3 −1
  10. libavfilter/vf_sr.c +1 −1
libavfilter/dnn/dnn_backend_native.c+2−1
@@ -115,7 +115,7 @@ static DNNReturnType set_input_output_native(void *model, DNNData *input, const · 114 unmodified lines
115115 // layers_num,layer_type,layer_parameterss,layer_type,layer_parameters...
116116 // For CONV layer: activation_function, input_num, output_num, kernel_size, kernel, biases
117117 // For DEPTH_TO_SPACE layer: block_size
118−DNNModel *ff_dnn_load_model_native(const char *model_filename)
118+DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *options)
119119 {
120120 DNNModel *model = NULL;
121121 char header_expected[] = "FFMPEGDNNNATIVE";
@@ -245,6 +245,7 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename) · 123 unmodified lines
245245
246246 model->set_input_output = &set_input_output_native;
247247 model->get_input = &get_input_native;
248+ model->options = options;
248249
249250 return model;
250251
libavfilter/dnn/dnn_backend_native.h+1−1
@@ -116,7 +116,7 @@ typedef struct ConvolutionalNetwork{ · 115 unmodified lines
116116 uint32_t nb_output;
117117 } ConvolutionalNetwork;
118118
119−DNNModel *ff_dnn_load_model_native(const char *model_filename);
119+DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *options);
120120
121121 DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *outputs, uint32_t nb_output);
122122
libavfilter/dnn/dnn_backend_openvino.c+2−1
@@ -155,7 +155,7 @@ err: · 154 unmodified lines
155155 return DNN_ERROR;
156156 }
157157
158−DNNModel *ff_dnn_load_model_ov(const char *model_filename)
158+DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options)
159159 {
160160 DNNModel *model = NULL;
161161 OVModel *ov_model = NULL;
@@ -186,6 +186,7 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename) · 24 unmodified lines
186186 model->model = (void *)ov_model;
187187 model->set_input_output = &set_input_output_ov;
188188 model->get_input = &get_input_ov;
189+ model->options = options;
189190
190191 return model;
191192
libavfilter/dnn/dnn_backend_openvino.h+1−1
@@ -29,7 +29,7 @@ · 28 unmodified lines
2929
3030 #include "../dnn_interface.h"
3131
32−DNNModel *ff_dnn_load_model_ov(const char *model_filename);
32+DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options);
3333
3434 DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNData *outputs, uint32_t nb_output);
3535
libavfilter/dnn/dnn_backend_tf.c+2−1
@@ -572,7 +572,7 @@ static DNNReturnType load_native_model(TFModel *tf_model, const char *model_file · 571 unmodified lines
572572 return DNN_SUCCESS;
573573 }
574574
575−DNNModel *ff_dnn_load_model_tf(const char *model_filename)
575+DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options)
576576 {
577577 DNNModel *model = NULL;
578578 TFModel *tf_model = NULL;
@@ -600,6 +600,7 @@ DNNModel *ff_dnn_load_model_tf(const char *model_filename) · 21 unmodified lines
600600 model->model = (void *)tf_model;
601601 model->set_input_output = &set_input_output_tf;
602602 model->get_input = &get_input_tf;
603+ model->options = options;
603604
604605 return model;
605606 }
libavfilter/dnn/dnn_backend_tf.h+1−1
@@ -29,7 +29,7 @@ · 28 unmodified lines
2929
3030 #include "../dnn_interface.h"
3131
32−DNNModel *ff_dnn_load_model_tf(const char *model_filename);
32+DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options);
3333
3434 DNNReturnType ff_dnn_execute_model_tf(const DNNModel *model, DNNData *outputs, uint32_t nb_output);
3535
libavfilter/dnn_interface.h+3−1
@@ -43,6 +43,8 @@ typedef struct DNNData{ · 42 unmodified lines
4343 typedef struct DNNModel{
4444 // Stores model that can be different for different backends.
4545 void *model;
46+ // Stores options when the model is executed by the backend
47+ const char *options;
4648 // Gets model input information
4749 // Just reuse struct DNNData here, actually the DNNData.data field is not needed.
4850 DNNReturnType (*get_input)(void *model, DNNData *input, const char *input_name);
@@ -54,7 +56,7 @@ typedef struct DNNModel{ · 5 unmodified lines
5456 // Stores pointers to functions for loading, executing, freeing DNN models for one of the backends.
5557 typedef struct DNNModule{
5658 // Loads model and parameters from given file. Returns NULL if it is not possible.
57− DNNModel *(*load_model)(const char *model_filename);
59+ DNNModel *(*load_model)(const char *model_filename, const char *options);
5860 // Executes model with specified input and output. Returns DNN_ERROR otherwise.
5961 DNNReturnType (*execute_model)(const DNNModel *model, DNNData *outputs, uint32_t nb_output);
6062 // Frees memory allocated for model.
libavfilter/vf_derain.c+1−1
@@ -161,7 +161,7 @@ static av_cold int init(AVFilterContext *ctx) · 160 unmodified lines
161161 return AVERROR(EINVAL);
162162 }
163163
164− dr_context->model = (dr_context->dnn_module->load_model)(dr_context->model_filename);
164+ dr_context->model = (dr_context->dnn_module->load_model)(dr_context->model_filename, NULL);
165165 if (!dr_context->model) {
166166 av_log(ctx, AV_LOG_ERROR, "could not load DNN model\n");
167167 return AVERROR(EINVAL);
libavfilter/vf_dnn_processing.c+3−1
@@ -41,6 +41,7 @@ typedef struct DnnProcessingContext { · 40 unmodified lines
4141 DNNBackendType backend_type;
4242 char *model_inputname;
4343 char *model_outputname;
44+ char *backend_options;
4445
4546 DNNModule *dnn_module;
4647 DNNModel *model;
@@ -69,6 +70,7 @@ static const AVOption dnn_processing_options[] = { · 22 unmodified lines
6970 { "model", "path to model file", OFFSET(model_filename), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS },
7071 { "input", "input name of the model", OFFSET(model_inputname), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS },
7172 { "output", "output name of the model", OFFSET(model_outputname), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS },
73+ { "options", "backend options", OFFSET(backend_options), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS },
7274 { NULL }
7375 };
7476
@@ -101,7 +103,7 @@ static av_cold int init(AVFilterContext *context) · 26 unmodified lines
101103 return AVERROR(EINVAL);
102104 }
103105
104− ctx->model = (ctx->dnn_module->load_model)(ctx->model_filename);
106+ ctx->model = (ctx->dnn_module->load_model)(ctx->model_filename, ctx->backend_options);
105107 if (!ctx->model) {
106108 av_log(ctx, AV_LOG_ERROR, "could not load DNN model\n");
107109 return AVERROR(EINVAL);
libavfilter/vf_sr.c+1−1
@@ -81,7 +81,7 @@ static av_cold int init(AVFilterContext *context) · 80 unmodified lines
8181 av_log(context, AV_LOG_ERROR, "load_model for network was not specified\n");
8282 return AVERROR(EIO);
8383 }
84− sr_context->model = (sr_context->dnn_module->load_model)(sr_context->model_filename);
84+ sr_context->model = (sr_context->dnn_module->load_model)(sr_context->model_filename, NULL);
8585 if (!sr_context->model){
8686 av_log(context, AV_LOG_ERROR, "could not load DNN model\n");
8787 return AVERROR(EIO);

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