History

lavfi/dnn_backend_tf: Add TFInferRequest and TFRequestItem

This commit introduces a typedef TFInferRequest to store execution parameters for a single call to the TensorFlow C API. This typedef is used in the TFRequestItem.

Shubhanshu Saxena committed 5 years ago

Commit a4de6051 parent 68cf14d1 file · +49 −0Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/dnn/dnn_backend_tf.c+49−0
@@ -56,6 +56,23 @@ typedef struct TFModel{ · 55 unmodified lines
5656 Queue *inference_queue;
5757 } TFModel;
5858
59+/**
60+ * Stores execution parameters for single
61+ * call to the TensorFlow C API
62+ */
63+typedef struct TFInferRequest {
64+ TF_Output *tf_outputs;
65+ TF_Tensor **output_tensors;
66+ TF_Output *tf_input;
67+ TF_Tensor *input_tensor;
68+} TFInferRequest;
69+
70+typedef struct TFRequestItem {
71+ TFInferRequest *infer_request;
72+ InferenceItem *inference;
73+ // further properties will be added later for async
74+} TFRequestItem;
75+
5976 #define OFFSET(x) offsetof(TFContext, x)
6077 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM
6178 static const AVOption dnn_tensorflow_options[] = {
@@ -72,6 +89,38 @@ static void free_buffer(void *data, size_t length) · 10 unmodified lines
7289 av_freep(&data);
7390 }
7491
92+static void tf_free_request(TFInferRequest *request)
93+{
94+ if (!request)
95+ return;
96+ if (request->input_tensor) {
97+ TF_DeleteTensor(request->input_tensor);
98+ request->input_tensor = NULL;
99+ }
100+ av_freep(&request->tf_input);
101+ av_freep(&request->tf_outputs);
102+ if (request->output_tensors) {
103+ int nb_output = sizeof(*request->output_tensors)/sizeof(request->output_tensors[0]);
104+ for (uint32_t i = 0; i < nb_output; ++i) {
105+ if (request->output_tensors[i]) {
106+ TF_DeleteTensor(request->output_tensors[i]);
107+ request->output_tensors[i] = NULL;
108+ }
109+ }
110+ av_freep(&request->output_tensors);
111+ }
112+}
113+
114+static TFInferRequest *tf_create_inference_request(void)
115+{
116+ TFInferRequest *infer_request = av_malloc(sizeof(TFInferRequest));
117+ infer_request->tf_outputs = NULL;
118+ infer_request->tf_input = NULL;
119+ infer_request->input_tensor = NULL;
120+ infer_request->output_tensors = NULL;
121+ return infer_request;
122+}
123+
75124 static DNNReturnType extract_inference_from_task(TaskItem *task, Queue *inference_queue)
76125 {
77126 InferenceItem *inference = av_malloc(sizeof(*inference));

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t