2018-05-25 19:31:04 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Sergey Lavrushkin
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* DNN inference engine interface.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AVFILTER_DNN_INTERFACE_H
|
|
|
|
#define AVFILTER_DNN_INTERFACE_H
|
|
|
|
|
2019-04-25 04:14:33 +02:00
|
|
|
#include <stdint.h>
|
2020-08-28 06:51:44 +02:00
|
|
|
#include "libavutil/frame.h"
|
2019-04-25 04:14:33 +02:00
|
|
|
|
2018-05-25 19:31:04 +02:00
|
|
|
typedef enum {DNN_SUCCESS, DNN_ERROR} DNNReturnType;
|
|
|
|
|
2020-05-25 09:38:09 +02:00
|
|
|
typedef enum {DNN_NATIVE, DNN_TF, DNN_OV} DNNBackendType;
|
2018-05-25 19:31:04 +02:00
|
|
|
|
2019-08-20 10:50:34 +02:00
|
|
|
typedef enum {DNN_FLOAT = 1, DNN_UINT8 = 4} DNNDataType;
|
2019-04-25 04:14:42 +02:00
|
|
|
|
2019-10-21 14:38:10 +02:00
|
|
|
typedef struct DNNData{
|
2019-04-25 04:14:42 +02:00
|
|
|
void *data;
|
|
|
|
DNNDataType dt;
|
|
|
|
int width, height, channels;
|
2018-05-25 19:31:04 +02:00
|
|
|
} DNNData;
|
|
|
|
|
|
|
|
typedef struct DNNModel{
|
|
|
|
// Stores model that can be different for different backends.
|
2018-07-27 18:34:02 +02:00
|
|
|
void *model;
|
2020-08-07 08:32:55 +02:00
|
|
|
// Stores options when the model is executed by the backend
|
|
|
|
const char *options;
|
2020-08-24 10:09:59 +02:00
|
|
|
// Stores userdata used for the interaction between AVFrame and DNNData
|
|
|
|
void *userdata;
|
2019-10-21 14:38:17 +02:00
|
|
|
// 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);
|
2020-09-11 16:15:04 +02:00
|
|
|
// Gets model output width/height with given input w/h
|
|
|
|
DNNReturnType (*get_output)(void *model, const char *input_name, int input_width, int input_height,
|
|
|
|
const char *output_name, int *output_width, int *output_height);
|
2020-08-28 06:51:44 +02:00
|
|
|
// set the pre process to transfer data from AVFrame to DNNData
|
|
|
|
// the default implementation within DNN is used if it is not provided by the filter
|
|
|
|
int (*pre_proc)(AVFrame *frame_in, DNNData *model_input, void *user_data);
|
|
|
|
// set the post process to transfer data from DNNData to AVFrame
|
|
|
|
// the default implementation within DNN is used if it is not provided by the filter
|
|
|
|
int (*post_proc)(AVFrame *frame_out, DNNData *model_output, void *user_data);
|
2018-05-25 19:31:04 +02:00
|
|
|
} 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.
|
2020-08-24 10:09:59 +02:00
|
|
|
DNNModel *(*load_model)(const char *model_filename, const char *options, void *userdata);
|
2020-09-10 16:29:57 +02:00
|
|
|
// Executes model with specified input and output. Returns DNN_ERROR otherwise.
|
|
|
|
DNNReturnType (*execute_model)(const DNNModel *model, const char *input_name, AVFrame *in_frame,
|
|
|
|
const char **output_names, uint32_t nb_output, AVFrame *out_frame);
|
2018-05-25 19:31:04 +02:00
|
|
|
// Frees memory allocated for model.
|
2018-07-27 18:34:02 +02:00
|
|
|
void (*free_model)(DNNModel **model);
|
2018-05-25 19:31:04 +02:00
|
|
|
} DNNModule;
|
|
|
|
|
|
|
|
// Initializes DNNModule depending on chosen backend.
|
2018-07-27 18:34:02 +02:00
|
|
|
DNNModule *ff_get_dnn_module(DNNBackendType backend_type);
|
2018-05-25 19:31:04 +02:00
|
|
|
|
|
|
|
#endif
|