FFmpeg
Data Structures | Macros | Functions | Variables
dnn_backend_tf.c File Reference

DNN tensorflow backend implementation. More...

#include "dnn_backend_tf.h"
#include "dnn_backend_native.h"
#include "dnn_backend_native_layer_conv2d.h"
#include "dnn_backend_native_layer_depth2space.h"
#include "libavformat/avio.h"
#include "libavutil/avassert.h"
#include "../internal.h"
#include "dnn_backend_native_layer_pad.h"
#include "dnn_backend_native_layer_maximum.h"
#include "dnn_io_proc.h"
#include <tensorflow/c/c_api.h>

Go to the source code of this file.

Data Structures

struct  TFOptions
 
struct  TFContext
 
struct  TFModel
 

Macros

#define OFFSET(x)   offsetof(TFContext, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM
 
#define NAME_BUFFER_SIZE   256
 
#define CLEANUP_ON_ERROR(tf_model)
 

Functions

 AVFILTER_DEFINE_CLASS (dnn_tensorflow)
 
static DNNReturnType execute_model_tf (const DNNModel *model, const char *input_name, AVFrame *in_frame, const char **output_names, uint32_t nb_output, AVFrame *out_frame, int do_ioproc)
 
static void free_buffer (void *data, size_t length)
 
static TF_Buffer * read_graph (const char *model_filename)
 
static TF_Tensor * allocate_input_tensor (const DNNData *input)
 
static DNNReturnType get_input_tf (void *model, DNNData *input, const char *input_name)
 
static DNNReturnType get_output_tf (void *model, const char *input_name, int input_width, int input_height, const char *output_name, int *output_width, int *output_height)
 
static DNNReturnType load_tf_model (TFModel *tf_model, const char *model_filename)
 
static DNNReturnType add_conv_layer (TFModel *tf_model, TF_Operation *transpose_op, TF_Operation **cur_op, ConvolutionalParams *params, const int layer)
 
static DNNReturnType add_depth_to_space_layer (TFModel *tf_model, TF_Operation **cur_op, DepthToSpaceParams *params, const int layer)
 
static DNNReturnType add_pad_layer (TFModel *tf_model, TF_Operation **cur_op, LayerPadParams *params, const int layer)
 
static DNNReturnType add_maximum_layer (TFModel *tf_model, TF_Operation **cur_op, DnnLayerMaximumParams *params, const int layer)
 
static DNNReturnType load_native_model (TFModel *tf_model, const char *model_filename)
 
DNNModelff_dnn_load_model_tf (const char *model_filename, const char *options, void *userdata)
 
DNNReturnType ff_dnn_execute_model_tf (const DNNModel *model, const char *input_name, AVFrame *in_frame, const char **output_names, uint32_t nb_output, AVFrame *out_frame)
 
void ff_dnn_free_model_tf (DNNModel **model)
 

Variables

static const AVOption dnn_tensorflow_options []
 

Detailed Description

DNN tensorflow backend implementation.

Definition in file dnn_backend_tf.c.

Macro Definition Documentation

#define OFFSET (   x)    offsetof(TFContext, x)

Definition at line 56 of file dnn_backend_tf.c.

#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM

Definition at line 57 of file dnn_backend_tf.c.

#define NAME_BUFFER_SIZE   256
#define CLEANUP_ON_ERROR (   tf_model)
Value:
{ \
TF_DeleteGraph(tf_model->graph); \
TF_DeleteStatus(tf_model->status); \
av_log(ctx, AV_LOG_ERROR, "Failed to set value or add operator to layer\n"); \
}
#define av_log(a,...)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
AVFormatContext * ctx
Definition: movenc.c:48
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a it should return

Referenced by load_native_model().

Function Documentation

AVFILTER_DEFINE_CLASS ( dnn_tensorflow  )
static DNNReturnType execute_model_tf ( const DNNModel model,
const char *  input_name,
AVFrame in_frame,
const char **  output_names,
uint32_t  nb_output,
AVFrame out_frame,
int  do_ioproc 
)
static

Definition at line 712 of file dnn_backend_tf.c.

Referenced by ff_dnn_execute_model_tf(), and get_output_tf().

static void free_buffer ( void data,
size_t  length 
)
static

Definition at line 69 of file dnn_backend_tf.c.

Referenced by read_graph().

static TF_Buffer* read_graph ( const char *  model_filename)
static

Definition at line 74 of file dnn_backend_tf.c.

Referenced by load_tf_model().

static TF_Tensor* allocate_input_tensor ( const DNNData input)
static

Definition at line 107 of file dnn_backend_tf.c.

Referenced by execute_model_tf().

static DNNReturnType get_input_tf ( void model,
DNNData input,
const char *  input_name 
)
static

Definition at line 129 of file dnn_backend_tf.c.

Referenced by execute_model_tf(), and ff_dnn_load_model_tf().

static DNNReturnType get_output_tf ( void model,
const char *  input_name,
int  input_width,
int  input_height,
const char *  output_name,
int output_width,
int output_height 
)
static

Definition at line 164 of file dnn_backend_tf.c.

Referenced by ff_dnn_load_model_tf().

static DNNReturnType load_tf_model ( TFModel tf_model,
const char *  model_filename 
)
static

Definition at line 197 of file dnn_backend_tf.c.

Referenced by ff_dnn_load_model_tf().

static DNNReturnType add_conv_layer ( TFModel tf_model,
TF_Operation *  transpose_op,
TF_Operation **  cur_op,
ConvolutionalParams params,
const int  layer 
)
static

Definition at line 317 of file dnn_backend_tf.c.

Referenced by load_native_model().

static DNNReturnType add_depth_to_space_layer ( TFModel tf_model,
TF_Operation **  cur_op,
DepthToSpaceParams params,
const int  layer 
)
static

Definition at line 442 of file dnn_backend_tf.c.

Referenced by load_native_model().

static DNNReturnType add_pad_layer ( TFModel tf_model,
TF_Operation **  cur_op,
LayerPadParams params,
const int  layer 
)
static

Definition at line 466 of file dnn_backend_tf.c.

Referenced by load_native_model().

static DNNReturnType add_maximum_layer ( TFModel tf_model,
TF_Operation **  cur_op,
DnnLayerMaximumParams params,
const int  layer 
)
static

Definition at line 521 of file dnn_backend_tf.c.

Referenced by load_native_model().

static DNNReturnType load_native_model ( TFModel tf_model,
const char *  model_filename 
)
static

Definition at line 567 of file dnn_backend_tf.c.

Referenced by ff_dnn_load_model_tf().

DNNModel* ff_dnn_load_model_tf ( const char *  model_filename,
const char *  options,
void userdata 
)

Definition at line 667 of file dnn_backend_tf.c.

Referenced by ff_get_dnn_module().

DNNReturnType ff_dnn_execute_model_tf ( const DNNModel model,
const char *  input_name,
AVFrame in_frame,
const char **  output_names,
uint32_t  nb_output,
AVFrame out_frame 
)

Definition at line 822 of file dnn_backend_tf.c.

Referenced by ff_get_dnn_module().

void ff_dnn_free_model_tf ( DNNModel **  model)

Definition at line 841 of file dnn_backend_tf.c.

Referenced by ff_get_dnn_module().

Variable Documentation

const AVOption dnn_tensorflow_options[]
static
Initial value:
= {
{ "sess_config", "config for SessionOptions", OFFSET(options.sess_config), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS },
{ NULL }
}
#define NULL
Definition: coverity.c:32
#define OFFSET(x)
const OptionDef options[]
Definition: ffmpeg_opt.c:3400
#define FLAGS

Definition at line 58 of file dnn_backend_tf.c.