FFmpeg
dnn_backend_native.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Sergey Lavrushkin
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * DNN inference functions interface for native backend.
24  */
25 
26 
27 #ifndef AVFILTER_DNN_DNN_BACKEND_NATIVE_H
28 #define AVFILTER_DNN_DNN_BACKEND_NATIVE_H
29 
30 #include "../dnn_interface.h"
31 #include "libavformat/avio.h"
32 #include "libavutil/opt.h"
33 
34 /**
35  * the enum value of DNNLayerType should not be changed,
36  * the same values are used in convert_from_tensorflow.py
37  * and, it is used to index the layer execution/load function pointer.
38  */
39 typedef enum {
40  DLT_INPUT = 0,
49 } DNNLayerType;
50 
53 
54 typedef struct Layer{
56  /**
57  * a layer can have multiple inputs and one output.
58  * 4 is just a big enough number for input operands (increase it if necessary),
59  * do not use 'int32_t *input_operand_indexes', so we don't worry about mem leaks.
60  */
63  void *params;
64 } Layer;
65 
66 typedef struct DnnOperand{
67  /**
68  * there are two memory layouts, NHWC or NCHW, so we use dims,
69  * dims[0] is Number.
70  */
71  int32_t dims[4];
72 
73  /**
74  * input/output/intermediate operand of the network
75  */
77 
78  /**
79  * support different kinds of data type such as float, half float, int8 etc,
80  * first support float now.
81  */
83 
84  /**
85  * NHWC if 1, otherwise NCHW.
86  * let's first support NHWC only, this flag is for extensive usage.
87  */
88  int8_t isNHWC;
89 
90  /**
91  * to avoid possible memory leak, do not use char *name
92  */
93  char name[128];
94 
95  /**
96  * data pointer with data length in bytes.
97  * usedNumbersLeft is only valid for intermediate operand,
98  * it means how many layers still depend on this operand,
99  * todo: the memory can be reused when usedNumbersLeft is zero.
100  */
101  void *data;
104 }DnnOperand;
105 
106 typedef struct InputParams{
108 } InputParams;
109 
110 typedef struct NativeOptions{
111  uint32_t conv2d_threads;
112 } NativeOptions;
113 
114 typedef struct NativeContext {
115  const AVClass *class;
117 } NativeContext;
118 
119 // Represents simple feed-forward convolutional network.
120 typedef struct NativeModel{
126 } NativeModel;
127 
128 DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *options);
129 
130 DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output);
131 
132 void ff_dnn_free_model_native(DNNModel **model);
133 
134 // NOTE: User must check for error (return value <= 0) to handle
135 // case like integer overflow.
138 #endif
DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output)
DNNPaddingParam
int8_t isNHWC
NHWC if 1, otherwise NCHW.
Buffered I/O operations.
DNNOperandType type
input/output/intermediate operand of the network
DnnOperand * operands
int32_t input_operand_indexes[4]
a layer can have multiple inputs and one output.
AVOptions.
int32_t calculate_operand_dims_count(const DnnOperand *oprd)
#define height
DNNDataType data_type
support different kinds of data type such as float, half float, int8 etc, first support float now...
channels
Definition: aptx.h:33
DNNModel * ff_dnn_load_model_native(const char *model_filename, const char *options)
NativeContext ctx
DNNDataType
Definition: dnn_interface.h:35
void * data
data pointer with data length in bytes.
int32_t usedNumbersLeft
int32_t calculate_operand_data_length(const DnnOperand *oprd)
int32_t
DNNReturnType
Definition: dnn_interface.h:31
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
DNNOperandType
Describe the class of an AVClass context structure.
Definition: log.h:67
void ff_dnn_free_model_native(DNNModel **model)
DNNLayerType type
DNNLayerType
the enum value of DNNLayerType should not be changed, the same values are used in convert_from_tensor...
const OptionDef options[]
Definition: ffmpeg_opt.c:3393
NativeOptions options
void * params
int32_t output_operand_index
const char * name
Definition: opengl_enc.c:102