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 
33 /**
34  * the enum value of DNNLayerType should not be changed,
35  * the same values are used in convert_from_tensorflow.py
36  * and, it is used to index the layer execution/load function pointer.
37  */
38 typedef enum {
39  DLT_INPUT = 0,
45 } DNNLayerType;
46 
48 
49 typedef struct Layer{
51  /**
52  * a layer can have multiple inputs and one output.
53  * 4 is just a big enough number for input operands (increase it if necessary),
54  * do not use 'int32_t *input_operand_indexes', so we don't worry about mem leaks.
55  */
58  void *params;
59 } Layer;
60 
61 typedef struct DnnOperand{
62  /**
63  * there are two memory layouts, NHWC or NCHW, so we use dims,
64  * dims[0] is Number.
65  */
66  int32_t dims[4];
67 
68  /**
69  * input/output/intermediate operand of the network
70  */
72 
73  /**
74  * support different kinds of data type such as float, half float, int8 etc,
75  * first support float now.
76  */
78 
79  /**
80  * NHWC if 1, otherwise NCHW.
81  * let's first support NHWC only, this flag is for extensive usage.
82  */
83  int8_t isNHWC;
84 
85  /**
86  * to avoid possible memory leak, do not use char *name
87  */
88  char name[128];
89 
90  /**
91  * data pointer with data length in bytes.
92  * usedNumbersLeft is only valid for intermediate operand,
93  * it means how many layers still depend on this operand,
94  * todo: the memory can be reused when usedNumbersLeft is zero.
95  */
96  void *data;
99 }DnnOperand;
100 
101 typedef struct InputParams{
103 } InputParams;
104 
105 // Represents simple feed-forward convolutional network.
106 typedef struct ConvolutionalNetwork{
112  uint32_t nb_output;
114 
115 DNNModel *ff_dnn_load_model_native(const char *model_filename);
116 
117 DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *outputs, uint32_t nb_output);
118 
119 void ff_dnn_free_model_native(DNNModel **model);
120 
123 #endif
int8_t isNHWC
NHWC if 1, otherwise NCHW.
Buffered I/O operations.
channels
Definition: aptx.c:30
DNNOperandType type
input/output/intermediate operand of the network
int32_t input_operand_indexes[4]
a layer can have multiple inputs and one output.
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...
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
DNNModel * ff_dnn_load_model_native(const char *model_filename)
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...
void * params
DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *outputs, uint32_t nb_output)
int32_t output_operand_index
const char * name
Definition: opengl_enc.c:102