FFmpeg
Data Structures | Macros | Functions | Variables
dnn_backend_tf.c File Reference
#include "libavformat/avio.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/cpu.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavcodec/defs.h"
#include "../internal.h"
#include "dnn_io_proc.h"
#include "dnn_backend_common.h"
#include "safe_queue.h"
#include <tensorflow/c/c_api.h>

Go to the source code of this file.

Data Structures

struct  TFModel
 
struct  TFInferRequest
 Stores execution parameters for single call to the TensorFlow C API. More...
 
struct  TFRequestItem
 

Macros

#define OFFSET(x)   offsetof(TFOptions, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM
 
#define SPACE_CHARS   " \t\r\n"
 

Functions

static int execute_model_tf (TFRequestItem *request, Queue *lltask_queue)
 
static void infer_completion_callback (void *args)
 
static void destroy_request_item (TFRequestItem **arg)
 Free the TFRequestItem completely. More...
 
static void free_buffer (void *data, size_t length)
 
static void tf_free_request (TFInferRequest *request)
 Free the contents of TensorFlow inference request. More...
 
static TFInferRequesttf_create_inference_request (void)
 Create a TensorFlow inference request. More...
 
static int tf_start_inference (void *args)
 Start synchronous inference for the TensorFlow model. More...
 
static int extract_lltask_from_task (TaskItem *task, Queue *lltask_queue)
 
static TF_Buffer * read_graph (const char *model_filename)
 
static TF_Tensor * allocate_input_tensor (const DNNData *input)
 
static int get_input_tf (void *model, DNNData *input, const char *input_name)
 
static int 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 int hex_to_data (uint8_t *data, const char *p)
 
static int load_tf_model (TFModel *tf_model, const char *model_filename)
 
static void dnn_free_model_tf (DNNModel **model)
 
static DNNModeldnn_load_model_tf (DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *filter_ctx)
 
static int fill_model_input_tf (TFModel *tf_model, TFRequestItem *request)
 
static int dnn_execute_model_tf (const DNNModel *model, DNNExecBaseParams *exec_params)
 
static DNNAsyncStatusType dnn_get_result_tf (const DNNModel *model, AVFrame **in, AVFrame **out)
 
static int dnn_flush_tf (const DNNModel *model)
 

Variables

static const AVOption dnn_tensorflow_options []
 
const DNNModule ff_dnn_backend_tf
 

Detailed Description

DNN tensorflow backend implementation.

Definition in file dnn_backend_tf.c.

Macro Definition Documentation

◆ OFFSET

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

Definition at line 68 of file dnn_backend_tf.c.

◆ FLAGS

#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM

Definition at line 69 of file dnn_backend_tf.c.

◆ SPACE_CHARS

#define SPACE_CHARS   " \t\r\n"

Definition at line 357 of file dnn_backend_tf.c.

Function Documentation

◆ execute_model_tf()

static int execute_model_tf ( TFRequestItem request,
Queue lltask_queue 
)
static

Definition at line 764 of file dnn_backend_tf.c.

Referenced by dnn_execute_model_tf(), and get_output_tf().

◆ infer_completion_callback()

static void infer_completion_callback ( void *  args)
static

Definition at line 701 of file dnn_backend_tf.c.

Referenced by dnn_load_model_tf(), and execute_model_tf().

◆ destroy_request_item()

static void destroy_request_item ( TFRequestItem **  arg)
inlinestatic

Free the TFRequestItem completely.

Parameters
argAddress of the TFInferRequest instance.

Definition at line 171 of file dnn_backend_tf.c.

Referenced by dnn_flush_tf(), dnn_free_model_tf(), dnn_load_model_tf(), execute_model_tf(), and infer_completion_callback().

◆ free_buffer()

static void free_buffer ( void *  data,
size_t  length 
)
static

Definition at line 80 of file dnn_backend_tf.c.

Referenced by read_graph().

◆ tf_free_request()

static void tf_free_request ( TFInferRequest request)
static

Free the contents of TensorFlow inference request.

It does not free the TFInferRequest instance.

Parameters
requestpointer to TFInferRequest instance. NULL pointer is allowed.

Definition at line 92 of file dnn_backend_tf.c.

Referenced by destroy_request_item(), execute_model_tf(), fill_model_input_tf(), and infer_completion_callback().

◆ tf_create_inference_request()

static TFInferRequest* tf_create_inference_request ( void  )
static

Create a TensorFlow inference request.

All properties are initially unallocated and set as NULL.

Returns
pointer to the allocated TFInferRequest instance.

Definition at line 120 of file dnn_backend_tf.c.

Referenced by dnn_load_model_tf().

◆ tf_start_inference()

static int tf_start_inference ( void *  args)
static

Start synchronous inference for the TensorFlow model.

Parameters
requestpointer to the TFRequestItem for inference
Return values
0if execution is successful
AVERROR(EINVAL)if request is NULL
DNN_GENERIC_ERRORif execution fails

Definition at line 141 of file dnn_backend_tf.c.

Referenced by dnn_load_model_tf(), and execute_model_tf().

◆ extract_lltask_from_task()

static int extract_lltask_from_task ( TaskItem task,
Queue lltask_queue 
)
static

Definition at line 185 of file dnn_backend_tf.c.

Referenced by dnn_execute_model_tf(), and get_output_tf().

◆ read_graph()

static TF_Buffer* read_graph ( const char *  model_filename)
static

Definition at line 205 of file dnn_backend_tf.c.

Referenced by load_tf_model().

◆ allocate_input_tensor()

static TF_Tensor* allocate_input_tensor ( const DNNData input)
static

Definition at line 238 of file dnn_backend_tf.c.

Referenced by fill_model_input_tf().

◆ get_input_tf()

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

Definition at line 265 of file dnn_backend_tf.c.

Referenced by dnn_load_model_tf(), and fill_model_input_tf().

◆ get_output_tf()

static int 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 313 of file dnn_backend_tf.c.

Referenced by dnn_load_model_tf().

◆ hex_to_data()

static int hex_to_data ( uint8_t *  data,
const char *  p 
)
static

Definition at line 358 of file dnn_backend_tf.c.

Referenced by load_tf_model().

◆ load_tf_model()

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

Definition at line 387 of file dnn_backend_tf.c.

Referenced by dnn_load_model_tf().

◆ dnn_free_model_tf()

static void dnn_free_model_tf ( DNNModel **  model)
static

Definition at line 482 of file dnn_backend_tf.c.

Referenced by dnn_load_model_tf(), and execute_model_tf().

◆ dnn_load_model_tf()

static DNNModel* dnn_load_model_tf ( DnnContext ctx,
DNNFunctionType  func_type,
AVFilterContext filter_ctx 
)
static

Definition at line 523 of file dnn_backend_tf.c.

◆ fill_model_input_tf()

static int fill_model_input_tf ( TFModel tf_model,
TFRequestItem request 
)
static

Definition at line 607 of file dnn_backend_tf.c.

Referenced by dnn_flush_tf(), and execute_model_tf().

◆ dnn_execute_model_tf()

static int dnn_execute_model_tf ( const DNNModel model,
DNNExecBaseParams exec_params 
)
static

Definition at line 810 of file dnn_backend_tf.c.

◆ dnn_get_result_tf()

static DNNAsyncStatusType dnn_get_result_tf ( const DNNModel model,
AVFrame **  in,
AVFrame **  out 
)
static

Definition at line 858 of file dnn_backend_tf.c.

◆ dnn_flush_tf()

static int dnn_flush_tf ( const DNNModel model)
static

Definition at line 864 of file dnn_backend_tf.c.

Variable Documentation

◆ dnn_tensorflow_options

const AVOption dnn_tensorflow_options[]
static
Initial value:
= {
{ "sess_config", "config for SessionOptions", OFFSET(sess_config), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS },
{ NULL }
}

Definition at line 70 of file dnn_backend_tf.c.

◆ ff_dnn_backend_tf

const DNNModule ff_dnn_backend_tf
Initial value:
= {
.clazz = DNN_DEFINE_CLASS(dnn_tensorflow),
.load_model = dnn_load_model_tf,
.execute_model = dnn_execute_model_tf,
.get_result = dnn_get_result_tf,
.flush = dnn_flush_tf,
.free_model = dnn_free_model_tf,
}

Definition at line 894 of file dnn_backend_tf.c.

Referenced by ff_get_dnn_module().

FLAGS
#define FLAGS
Definition: dnn_backend_tf.c:69
OFFSET
#define OFFSET(x)
Definition: dnn_backend_tf.c:68
dnn_load_model_tf
static DNNModel * dnn_load_model_tf(DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *filter_ctx)
Definition: dnn_backend_tf.c:523
NULL
#define NULL
Definition: coverity.c:32
dnn_flush_tf
static int dnn_flush_tf(const DNNModel *model)
Definition: dnn_backend_tf.c:864
DNN_DEFINE_CLASS
#define DNN_DEFINE_CLASS(fname)
Definition: dnn_backend_common.h:39
dnn_execute_model_tf
static int dnn_execute_model_tf(const DNNModel *model, DNNExecBaseParams *exec_params)
Definition: dnn_backend_tf.c:810
dnn_get_result_tf
static DNNAsyncStatusType dnn_get_result_tf(const DNNModel *model, AVFrame **in, AVFrame **out)
Definition: dnn_backend_tf.c:858
dnn_free_model_tf
static void dnn_free_model_tf(DNNModel **model)
Definition: dnn_backend_tf.c:482
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:249