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
|
|
|
|
|
|
|
|
typedef enum {DNN_SUCCESS, DNN_ERROR} DNNReturnType;
|
|
|
|
|
2018-06-03 19:22:50 +02:00
|
|
|
typedef enum {DNN_NATIVE, DNN_TF} DNNBackendType;
|
2018-05-25 19:31:04 +02:00
|
|
|
|
|
|
|
typedef struct DNNData{
|
2018-07-27 18:34:02 +02:00
|
|
|
float *data;
|
2018-05-25 19:31:04 +02:00
|
|
|
int width, height, channels;
|
|
|
|
} DNNData;
|
|
|
|
|
|
|
|
typedef struct DNNModel{
|
|
|
|
// Stores model that can be different for different backends.
|
2018-07-27 18:34:02 +02:00
|
|
|
void *model;
|
2018-05-25 19:31:04 +02:00
|
|
|
// Sets model input and output, while allocating additional memory for intermediate calculations.
|
|
|
|
// Should be called at least once before model execution.
|
2018-07-27 18:34:02 +02:00
|
|
|
DNNReturnType (*set_input_output)(void *model, DNNData *input, DNNData *output);
|
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.
|
2018-07-27 18:34:02 +02:00
|
|
|
DNNModel *(*load_model)(const char *model_filename);
|
2018-05-25 19:31:04 +02:00
|
|
|
// Executes model with specified input and output. Returns DNN_ERROR otherwise.
|
2018-07-27 18:34:02 +02:00
|
|
|
DNNReturnType (*execute_model)(const DNNModel *model);
|
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
|