mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
dnn: add userdata for load model parameter
the userdata will be used for the interaction between AVFrame and DNNData
This commit is contained in:
parent
dfbea7b210
commit
6918e240d7
@ -123,7 +123,7 @@ static DNNReturnType set_input_native(void *model, DNNData *input, const char *i
|
||||
// layers_num,layer_type,layer_parameterss,layer_type,layer_parameters...
|
||||
// For CONV layer: activation_function, input_num, output_num, kernel_size, kernel, biases
|
||||
// For DEPTH_TO_SPACE layer: block_size
|
||||
DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *options)
|
||||
DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *options, void *userdata)
|
||||
{
|
||||
DNNModel *model = NULL;
|
||||
char header_expected[] = "FFMPEGDNNNATIVE";
|
||||
@ -265,6 +265,7 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *optio
|
||||
|
||||
model->set_input = &set_input_native;
|
||||
model->get_input = &get_input_native;
|
||||
model->userdata = userdata;
|
||||
|
||||
return model;
|
||||
|
||||
|
@ -125,7 +125,7 @@ typedef struct NativeModel{
|
||||
int32_t operands_num;
|
||||
} NativeModel;
|
||||
|
||||
DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *options);
|
||||
DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *options, void *userdata);
|
||||
|
||||
DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output);
|
||||
|
||||
|
@ -174,7 +174,7 @@ err:
|
||||
return DNN_ERROR;
|
||||
}
|
||||
|
||||
DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options)
|
||||
DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options, void *userdata)
|
||||
{
|
||||
char *all_dev_names = NULL;
|
||||
DNNModel *model = NULL;
|
||||
@ -230,6 +230,7 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options)
|
||||
model->set_input = &set_input_ov;
|
||||
model->get_input = &get_input_ov;
|
||||
model->options = options;
|
||||
model->userdata = userdata;
|
||||
|
||||
return model;
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
#include "../dnn_interface.h"
|
||||
|
||||
DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options);
|
||||
DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options, void *userdata);
|
||||
|
||||
DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output);
|
||||
|
||||
|
@ -502,7 +502,7 @@ static DNNReturnType load_native_model(TFModel *tf_model, const char *model_file
|
||||
DNNModel *model = NULL;
|
||||
NativeModel *native_model;
|
||||
|
||||
model = ff_dnn_load_model_native(model_filename, NULL);
|
||||
model = ff_dnn_load_model_native(model_filename, NULL, NULL);
|
||||
if (!model){
|
||||
av_log(ctx, AV_LOG_ERROR, "Failed to load native model\n");
|
||||
return DNN_ERROR;
|
||||
@ -586,7 +586,7 @@ static DNNReturnType load_native_model(TFModel *tf_model, const char *model_file
|
||||
return DNN_SUCCESS;
|
||||
}
|
||||
|
||||
DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options)
|
||||
DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options, void *userdata)
|
||||
{
|
||||
DNNModel *model = NULL;
|
||||
TFModel *tf_model = NULL;
|
||||
@ -616,6 +616,7 @@ DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options)
|
||||
model->set_input = &set_input_tf;
|
||||
model->get_input = &get_input_tf;
|
||||
model->options = options;
|
||||
model->userdata = userdata;
|
||||
|
||||
return model;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
#include "../dnn_interface.h"
|
||||
|
||||
DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options);
|
||||
DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options, void *userdata);
|
||||
|
||||
DNNReturnType ff_dnn_execute_model_tf(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output);
|
||||
|
||||
|
@ -45,6 +45,8 @@ typedef struct DNNModel{
|
||||
void *model;
|
||||
// Stores options when the model is executed by the backend
|
||||
const char *options;
|
||||
// Stores userdata used for the interaction between AVFrame and DNNData
|
||||
void *userdata;
|
||||
// Gets model input information
|
||||
// Just reuse struct DNNData here, actually the DNNData.data field is not needed.
|
||||
DNNReturnType (*get_input)(void *model, DNNData *input, const char *input_name);
|
||||
@ -56,7 +58,7 @@ typedef struct DNNModel{
|
||||
// Stores pointers to functions for loading, executing, freeing DNN models for one of the backends.
|
||||
typedef struct DNNModule{
|
||||
// Loads model and parameters from given file. Returns NULL if it is not possible.
|
||||
DNNModel *(*load_model)(const char *model_filename, const char *options);
|
||||
DNNModel *(*load_model)(const char *model_filename, const char *options, void *userdata);
|
||||
// Executes model with specified input and output. Returns DNN_ERROR otherwise.
|
||||
DNNReturnType (*execute_model)(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output);
|
||||
// Frees memory allocated for model.
|
||||
|
@ -161,7 +161,7 @@ static av_cold int init(AVFilterContext *ctx)
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
|
||||
dr_context->model = (dr_context->dnn_module->load_model)(dr_context->model_filename, NULL);
|
||||
dr_context->model = (dr_context->dnn_module->load_model)(dr_context->model_filename, NULL, NULL);
|
||||
if (!dr_context->model) {
|
||||
av_log(ctx, AV_LOG_ERROR, "could not load DNN model\n");
|
||||
return AVERROR(EINVAL);
|
||||
|
@ -103,7 +103,7 @@ static av_cold int init(AVFilterContext *context)
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
|
||||
ctx->model = (ctx->dnn_module->load_model)(ctx->model_filename, ctx->backend_options);
|
||||
ctx->model = (ctx->dnn_module->load_model)(ctx->model_filename, ctx->backend_options, NULL);
|
||||
if (!ctx->model) {
|
||||
av_log(ctx, AV_LOG_ERROR, "could not load DNN model\n");
|
||||
return AVERROR(EINVAL);
|
||||
|
@ -81,7 +81,7 @@ static av_cold int init(AVFilterContext *context)
|
||||
av_log(context, AV_LOG_ERROR, "load_model for network was not specified\n");
|
||||
return AVERROR(EIO);
|
||||
}
|
||||
sr_context->model = (sr_context->dnn_module->load_model)(sr_context->model_filename, NULL);
|
||||
sr_context->model = (sr_context->dnn_module->load_model)(sr_context->model_filename, NULL, NULL);
|
||||
if (!sr_context->model){
|
||||
av_log(context, AV_LOG_ERROR, "could not load DNN model\n");
|
||||
return AVERROR(EIO);
|
||||
|
Loading…
Reference in New Issue
Block a user