This commit adds a function for execution of TFInferRequest and documentation for functions related to TFInferRequest.
Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -95,6 +95,13 @@ static void free_buffer(void *data, size_t length) · 94 unmodified lines | ||
| 95 | 95 | av_freep(&data); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | +/** | |
| 99 | + * Free the contents of TensorFlow inference request. | |
| 100 | + * It does not free the TFInferRequest instance. | |
| 101 | + * | |
| 102 | + * @param request pointer to TFInferRequest instance. | |
| 103 | + * NULL pointer is allowed. | |
| 104 | + */ | |
| 98 | 105 | static void tf_free_request(TFInferRequest *request) |
| 99 | 106 | { |
| 100 | 107 | if (!request) |
| @@ -117,6 +124,12 @@ static void tf_free_request(TFInferRequest *request) · 16 unmodified lines | ||
| 117 | 124 | } |
| 118 | 125 | } |
| 119 | 126 | |
| 127 | +/** | |
| 128 | + * Create a TensorFlow inference request. All properties | |
| 129 | + * are initially unallocated and set as NULL. | |
| 130 | + * | |
| 131 | + * @return pointer to the allocated TFInferRequest instance. | |
| 132 | + */ | |
| 120 | 133 | static TFInferRequest *tf_create_inference_request(void) |
| 121 | 134 | { |
| 122 | 135 | TFInferRequest *infer_request = av_malloc(sizeof(TFInferRequest)); |
| @@ -127,6 +140,38 @@ static TFInferRequest *tf_create_inference_request(void) · 4 unmodified lines | ||
| 127 | 140 | return infer_request; |
| 128 | 141 | } |
| 129 | 142 | |
| 143 | +/** | |
| 144 | + * Start synchronous inference for the TensorFlow model. | |
| 145 | + * | |
| 146 | + * @param request pointer to the TFRequestItem for inference | |
| 147 | + * @retval DNN_SUCCESS if execution is successful | |
| 148 | + * @retval DNN_ERROR if execution fails | |
| 149 | + */ | |
| 150 | +static DNNReturnType tf_start_inference(void *args) | |
| 151 | +{ | |
| 152 | + TFRequestItem *request = args; | |
| 153 | + TFInferRequest *infer_request = request->infer_request; | |
| 154 | + InferenceItem *inference = request->inference; | |
| 155 | + TaskItem *task = inference->task; | |
| 156 | + TFModel *tf_model = task->model; | |
| 157 | + | |
| 158 | + if (!request) { | |
| 159 | + av_log(&tf_model->ctx, AV_LOG_ERROR, "TFRequestItem is NULL\n"); | |
| 160 | + return DNN_ERROR; | |
| 161 | + } | |
| 162 | + | |
| 163 | + TF_SessionRun(tf_model->session, NULL, | |
| 164 | + infer_request->tf_input, &infer_request->input_tensor, 1, | |
| 165 | + infer_request->tf_outputs, infer_request->output_tensors, | |
| 166 | + task->nb_output, NULL, 0, NULL, | |
| 167 | + tf_model->status); | |
| 168 | + if (TF_GetCode(tf_model->status) != TF_OK) { | |
| 169 | + av_log(&tf_model->ctx, AV_LOG_ERROR, "%s", TF_Message(tf_model->status)); | |
| 170 | + return DNN_ERROR; | |
| 171 | + } | |
| 172 | + return DNN_SUCCESS; | |
| 173 | +} | |
| 174 | + | |
| 130 | 175 | static DNNReturnType extract_inference_from_task(TaskItem *task, Queue *inference_queue) |
| 131 | 176 | { |
| 132 | 177 | TFModel *tf_model = task->model; |