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.
Unified · Split
| @@ -56,6 +56,23 @@ typedef struct TFModel{ · 55 unmodified lines | ||
| 56 | 56 | Queue *inference_queue; |
| 57 | 57 | } TFModel; |
| 58 | 58 | |
| 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 | + | |
| 59 | 76 | #define OFFSET(x) offsetof(TFContext, x) |
| 60 | 77 | #define FLAGS AV_OPT_FLAG_FILTERING_PARAM |
| 61 | 78 | static const AVOption dnn_tensorflow_options[] = { |
| @@ -72,6 +89,38 @@ static void free_buffer(void *data, size_t length) · 10 unmodified lines | ||
| 72 | 89 | av_freep(&data); |
| 73 | 90 | } |
| 74 | 91 | |
| 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 | + | |
| 75 | 124 | static DNNReturnType extract_inference_from_task(TaskItem *task, Queue *inference_queue) |
| 76 | 125 | { |
| 77 | 126 | InferenceItem *inference = av_malloc(sizeof(*inference)); |