currently, output is set both at DNNModel.set_input_output and DNNModule.execute_model, it makes sense that the output name is provided at model inference time so all the output info is set at a single place. and so DNNModel.set_input_output is renamed to DNNModel.set_input
Unified · Split
| @@ -50,7 +50,7 @@ static DNNReturnType get_input_native(void *model, DNNData *input, const char *i · 49 unmodified lines | |||
| 50 | return DNN_ERROR; | 50 | return DNN_ERROR; |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | static DNNReturnType set_input_output_native(void *model, DNNData *input, const char *input_name, const char **output_names, uint32_t nb_output) | 53 | static DNNReturnType set_input_native(void *model, DNNData *input, const char *input_name) |
| 54 | { | 54 | { |
| 55 | NativeModel *native_model = (NativeModel *)model; | 55 | NativeModel *native_model = (NativeModel *)model; |
| 56 | DnnOperand *oprd = NULL; | 56 | DnnOperand *oprd = NULL; |
| @@ -87,27 +87,6 @@ static DNNReturnType set_input_output_native(void *model, DNNData *input, const · 30 unmodified lines | |||
| 87 | 87 | ||
| 88 | input->data = oprd->data; | 88 | input->data = oprd->data; |
| 89 | 89 | ||
| 90 | /* outputs */ | ||
| 91 | native_model->nb_output = 0; | ||
| 92 | av_freep(&native_model->output_indexes); | ||
| 93 | native_model->output_indexes = av_mallocz_array(nb_output, sizeof(*native_model->output_indexes)); | ||
| 94 | if (!native_model->output_indexes) | ||
| 95 | return DNN_ERROR; | ||
| 96 | |||
| 97 | for (uint32_t i = 0; i < nb_output; ++i) { | ||
| 98 | const char *output_name = output_names[i]; | ||
| 99 | for (int j = 0; j < native_model->operands_num; ++j) { | ||
| 100 | oprd = &native_model->operands[j]; | ||
| 101 | if (strcmp(oprd->name, output_name) == 0) { | ||
| 102 | native_model->output_indexes[native_model->nb_output++] = j; | ||
| 103 | break; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | if (native_model->nb_output != nb_output) | ||
| 109 | return DNN_ERROR; | ||
| 110 | |||
| 111 | return DNN_SUCCESS; | 90 | return DNN_SUCCESS; |
| 112 | } | 91 | } |
| 113 | 92 | ||
| @@ -243,7 +222,7 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *optio · 129 unmodified lines | |||
| 243 | return NULL; | 222 | return NULL; |
| 244 | } | 223 | } |
| 245 | 224 | ||
| 246 | model->set_input_output = &set_input_output_native; | 225 | model->set_input = &set_input_native; |
| 247 | model->get_input = &get_input_native; | 226 | model->get_input = &get_input_native; |
| 248 | model->options = options; | 227 | model->options = options; |
| 249 | 228 | ||
| @@ -255,11 +234,10 @@ fail: · 5 unmodified lines | |||
| 255 | return NULL; | 234 | return NULL; |
| 256 | } | 235 | } |
| 257 | 236 | ||
| 258 | DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *outputs, uint32_t nb_output) | 237 | DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output) |
| 259 | { | 238 | { |
| 260 | NativeModel *native_model = (NativeModel *)model->model; | 239 | NativeModel *native_model = (NativeModel *)model->model; |
| 261 | int32_t layer; | 240 | int32_t layer; |
| 262 | uint32_t nb = FFMIN(nb_output, native_model->nb_output); | ||
| 263 | 241 | ||
| 264 | if (native_model->layers_num <= 0 || native_model->operands_num <= 0) | 242 | if (native_model->layers_num <= 0 || native_model->operands_num <= 0) |
| 265 | return DNN_ERROR; | 243 | return DNN_ERROR; |
| @@ -274,8 +252,19 @@ DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *output · 8 unmodified lines | |||
| 274 | native_model->layers[layer].params); | 252 | native_model->layers[layer].params); |
| 275 | } | 253 | } |
| 276 | 254 | ||
| 277 | for (uint32_t i = 0; i < nb; ++i) { | 255 | for (uint32_t i = 0; i < nb_output; ++i) { |
| 278 | DnnOperand *oprd = &native_model->operands[native_model->output_indexes[i]]; | 256 | DnnOperand *oprd = NULL; |
| 257 | const char *output_name = output_names[i]; | ||
| 258 | for (int j = 0; j < native_model->operands_num; ++j) { | ||
| 259 | if (strcmp(native_model->operands[j].name, output_name) == 0) { | ||
| 260 | oprd = &native_model->operands[j]; | ||
| 261 | break; | ||
| 262 | } | ||
| 263 | } | ||
| 264 | |||
| 265 | if (oprd == NULL) | ||
| 266 | return DNN_ERROR; | ||
| 267 | |||
| 279 | outputs[i].data = oprd->data; | 268 | outputs[i].data = oprd->data; |
| 280 | outputs[i].height = oprd->dims[1]; | 269 | outputs[i].height = oprd->dims[1]; |
| 281 | outputs[i].width = oprd->dims[2]; | 270 | outputs[i].width = oprd->dims[2]; |
| @@ -335,7 +324,6 @@ void ff_dnn_free_model_native(DNNModel **model) · 53 unmodified lines | |||
| 335 | av_freep(&native_model->operands); | 324 | av_freep(&native_model->operands); |
| 336 | } | 325 | } |
| 337 | 326 | ||
| 338 | av_freep(&native_model->output_indexes); | ||
| 339 | av_freep(&native_model); | 327 | av_freep(&native_model); |
| 340 | } | 328 | } |
| 341 | av_freep(model); | 329 | av_freep(model); |
| @@ -112,13 +112,11 @@ typedef struct NativeModel{ · 111 unmodified lines | |||
| 112 | int32_t layers_num; | 112 | int32_t layers_num; |
| 113 | DnnOperand *operands; | 113 | DnnOperand *operands; |
| 114 | int32_t operands_num; | 114 | int32_t operands_num; |
| 115 | int32_t *output_indexes; | ||
| 116 | uint32_t nb_output; | ||
| 117 | } NativeModel; | 115 | } NativeModel; |
| 118 | 116 | ||
| 119 | DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *options); | 117 | DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *options); |
| 120 | 118 | ||
| 121 | DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *outputs, uint32_t nb_output); | 119 | DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output); |
| 122 | 120 | ||
| 123 | void ff_dnn_free_model_native(DNNModel **model); | 121 | void ff_dnn_free_model_native(DNNModel **model); |
| 124 | 122 | ||
| @@ -34,8 +34,6 @@ typedef struct OVModel{ · 33 unmodified lines | |||
| 34 | ie_executable_network_t *exe_network; | 34 | ie_executable_network_t *exe_network; |
| 35 | ie_infer_request_t *infer_request; | 35 | ie_infer_request_t *infer_request; |
| 36 | ie_blob_t *input_blob; | 36 | ie_blob_t *input_blob; |
| 37 | ie_blob_t **output_blobs; | ||
| 38 | uint32_t nb_output; | ||
| 39 | } OVModel; | 37 | } OVModel; |
| 40 | 38 | ||
| 41 | static DNNDataType precision_to_datatype(precision_e precision) | 39 | static DNNDataType precision_to_datatype(precision_e precision) |
| @@ -93,7 +91,7 @@ static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input · 51 unmodified lines | |||
| 93 | return DNN_ERROR; | 91 | return DNN_ERROR; |
| 94 | } | 92 | } |
| 95 | 93 | ||
| 96 | static DNNReturnType set_input_output_ov(void *model, DNNData *input, const char *input_name, const char **output_names, uint32_t nb_output) | 94 | static DNNReturnType set_input_ov(void *model, DNNData *input, const char *input_name) |
| 97 | { | 95 | { |
| 98 | OVModel *ov_model = (OVModel *)model; | 96 | OVModel *ov_model = (OVModel *)model; |
| 99 | IEStatusCode status; | 97 | IEStatusCode status; |
| @@ -124,30 +122,9 @@ static DNNReturnType set_input_output_ov(void *model, DNNData *input, const char · 24 unmodified lines | |||
| 124 | goto err; | 122 | goto err; |
| 125 | input->data = blob_buffer.buffer; | 123 | input->data = blob_buffer.buffer; |
| 126 | 124 | ||
| 127 | // outputs | ||
| 128 | ov_model->nb_output = 0; | ||
| 129 | av_freep(&ov_model->output_blobs); | ||
| 130 | ov_model->output_blobs = av_mallocz_array(nb_output, sizeof(*ov_model->output_blobs)); | ||
| 131 | if (!ov_model->output_blobs) | ||
| 132 | goto err; | ||
| 133 | |||
| 134 | for (int i = 0; i < nb_output; i++) { | ||
| 135 | const char *output_name = output_names[i]; | ||
| 136 | status = ie_infer_request_get_blob(ov_model->infer_request, output_name, &(ov_model->output_blobs[i])); | ||
| 137 | if (status != OK) | ||
| 138 | goto err; | ||
| 139 | ov_model->nb_output++; | ||
| 140 | } | ||
| 141 | |||
| 142 | return DNN_SUCCESS; | 125 | return DNN_SUCCESS; |
| 143 | 126 | ||
| 144 | err: | 127 | err: |
| 145 | if (ov_model->output_blobs) { | ||
| 146 | for (uint32_t i = 0; i < ov_model->nb_output; i++) { | ||
| 147 | ie_blob_free(&(ov_model->output_blobs[i])); | ||
| 148 | } | ||
| 149 | av_freep(&ov_model->output_blobs); | ||
| 150 | } | ||
| 151 | if (ov_model->input_blob) | 128 | if (ov_model->input_blob) |
| 152 | ie_blob_free(&ov_model->input_blob); | 129 | ie_blob_free(&ov_model->input_blob); |
| 153 | if (ov_model->infer_request) | 130 | if (ov_model->infer_request) |
| @@ -184,7 +161,7 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options) · 30 unmodified lines | |||
| 184 | goto err; | 161 | goto err; |
| 185 | 162 | ||
| 186 | model->model = (void *)ov_model; | 163 | model->model = (void *)ov_model; |
| 187 | model->set_input_output = &set_input_output_ov; | 164 | model->set_input = &set_input_ov; |
| 188 | model->get_input = &get_input_ov; | 165 | model->get_input = &get_input_ov; |
| 189 | model->options = options; | 166 | model->options = options; |
| 190 | 167 | ||
| @@ -205,24 +182,29 @@ err: · 14 unmodified lines | |||
| 205 | return NULL; | 182 | return NULL; |
| 206 | } | 183 | } |
| 207 | 184 | ||
| 208 | DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNData *outputs, uint32_t nb_output) | 185 | DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output) |
| 209 | { | 186 | { |
| 210 | dimensions_t dims; | 187 | dimensions_t dims; |
| 211 | precision_e precision; | 188 | precision_e precision; |
| 212 | ie_blob_buffer_t blob_buffer; | 189 | ie_blob_buffer_t blob_buffer; |
| 213 | OVModel *ov_model = (OVModel *)model->model; | 190 | OVModel *ov_model = (OVModel *)model->model; |
| 214 | uint32_t nb = FFMIN(nb_output, ov_model->nb_output); | ||
| 215 | IEStatusCode status = ie_infer_request_infer(ov_model->infer_request); | 191 | IEStatusCode status = ie_infer_request_infer(ov_model->infer_request); |
| 216 | if (status != OK) | 192 | if (status != OK) |
| 217 | return DNN_ERROR; | 193 | return DNN_ERROR; |
| 218 | 194 | ||
| 219 | for (uint32_t i = 0; i < nb; ++i) { | 195 | for (uint32_t i = 0; i < nb_output; ++i) { |
| 220 | status = ie_blob_get_buffer(ov_model->output_blobs[i], &blob_buffer); | 196 | const char *output_name = output_names[i]; |
| 197 | ie_blob_t *output_blob = NULL; | ||
| 198 | status = ie_infer_request_get_blob(ov_model->infer_request, output_name, &output_blob); | ||
| 199 | if (status != OK) | ||
| 200 | return DNN_ERROR; | ||
| 201 | |||
| 202 | status = ie_blob_get_buffer(output_blob, &blob_buffer); | ||
| 221 | if (status != OK) | 203 | if (status != OK) |
| 222 | return DNN_ERROR; | 204 | return DNN_ERROR; |
| 223 | 205 | ||
| 224 | status |= ie_blob_get_dims(ov_model->output_blobs[i], &dims); | 206 | status |= ie_blob_get_dims(output_blob, &dims); |
| 225 | status |= ie_blob_get_precision(ov_model->output_blobs[i], &precision); | 207 | status |= ie_blob_get_precision(output_blob, &precision); |
| 226 | if (status != OK) | 208 | if (status != OK) |
| 227 | return DNN_ERROR; | 209 | return DNN_ERROR; |
| 228 | 210 | ||
| @@ -240,12 +222,6 @@ void ff_dnn_free_model_ov(DNNModel **model) · 11 unmodified lines | |||
| 240 | { | 222 | { |
| 241 | if (*model){ | 223 | if (*model){ |
| 242 | OVModel *ov_model = (OVModel *)(*model)->model; | 224 | OVModel *ov_model = (OVModel *)(*model)->model; |
| 243 | if (ov_model->output_blobs) { | ||
| 244 | for (uint32_t i = 0; i < ov_model->nb_output; i++) { | ||
| 245 | ie_blob_free(&(ov_model->output_blobs[i])); | ||
| 246 | } | ||
| 247 | av_freep(&ov_model->output_blobs); | ||
| 248 | } | ||
| 249 | if (ov_model->input_blob) | 225 | if (ov_model->input_blob) |
| 250 | ie_blob_free(&ov_model->input_blob); | 226 | ie_blob_free(&ov_model->input_blob); |
| 251 | if (ov_model->infer_request) | 227 | if (ov_model->infer_request) |
| @@ -31,7 +31,7 @@ · 30 unmodified lines | |||
| 31 | 31 | ||
| 32 | DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options); | 32 | DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options); |
| 33 | 33 | ||
| 34 | DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNData *outputs, uint32_t nb_output); | 34 | DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output); |
| 35 | 35 | ||
| 36 | void ff_dnn_free_model_ov(DNNModel **model); | 36 | void ff_dnn_free_model_ov(DNNModel **model); |
| 37 | 37 | ||
| @@ -40,7 +40,6 @@ typedef struct TFModel{ · 39 unmodified lines | |||
| 40 | TF_Status *status; | 40 | TF_Status *status; |
| 41 | TF_Output input; | 41 | TF_Output input; |
| 42 | TF_Tensor *input_tensor; | 42 | TF_Tensor *input_tensor; |
| 43 | TF_Output *outputs; | ||
| 44 | TF_Tensor **output_tensors; | 43 | TF_Tensor **output_tensors; |
| 45 | uint32_t nb_output; | 44 | uint32_t nb_output; |
| 46 | } TFModel; | 45 | } TFModel; |
| @@ -136,7 +135,7 @@ static DNNReturnType get_input_tf(void *model, DNNData *input, const char *input · 89 unmodified lines | |||
| 136 | return DNN_SUCCESS; | 135 | return DNN_SUCCESS; |
| 137 | } | 136 | } |
| 138 | 137 | ||
| 139 | static DNNReturnType set_input_output_tf(void *model, DNNData *input, const char *input_name, const char **output_names, uint32_t nb_output) | 138 | static DNNReturnType set_input_tf(void *model, DNNData *input, const char *input_name) |
| 140 | { | 139 | { |
| 141 | TFModel *tf_model = (TFModel *)model; | 140 | TFModel *tf_model = (TFModel *)model; |
| 142 | TF_SessionOptions *sess_opts; | 141 | TF_SessionOptions *sess_opts; |
| @@ -157,40 +156,7 @@ static DNNReturnType set_input_output_tf(void *model, DNNData *input, const char · 14 unmodified lines | |||
| 157 | } | 156 | } |
| 158 | input->data = (float *)TF_TensorData(tf_model->input_tensor); | 157 | input->data = (float *)TF_TensorData(tf_model->input_tensor); |
| 159 | 158 | ||
| 160 | // Output operation | 159 | // session |
| 161 | if (nb_output == 0) | ||
| 162 | return DNN_ERROR; | ||
| 163 | |||
| 164 | av_freep(&tf_model->outputs); | ||
| 165 | tf_model->outputs = av_malloc_array(nb_output, sizeof(*tf_model->outputs)); | ||
| 166 | if (!tf_model->outputs) | ||
| 167 | return DNN_ERROR; | ||
| 168 | for (int i = 0; i < nb_output; ++i) { | ||
| 169 | tf_model->outputs[i].oper = TF_GraphOperationByName(tf_model->graph, output_names[i]); | ||
| 170 | if (!tf_model->outputs[i].oper){ | ||
| 171 | av_freep(&tf_model->outputs); | ||
| 172 | return DNN_ERROR; | ||
| 173 | } | ||
| 174 | tf_model->outputs[i].index = 0; | ||
| 175 | } | ||
| 176 | |||
| 177 | if (tf_model->output_tensors) { | ||
| 178 | for (uint32_t i = 0; i < tf_model->nb_output; ++i) { | ||
| 179 | if (tf_model->output_tensors[i]) { | ||
| 180 | TF_DeleteTensor(tf_model->output_tensors[i]); | ||
| 181 | tf_model->output_tensors[i] = NULL; | ||
| 182 | } | ||
| 183 | } | ||
| 184 | } | ||
| 185 | av_freep(&tf_model->output_tensors); | ||
| 186 | tf_model->output_tensors = av_mallocz_array(nb_output, sizeof(*tf_model->output_tensors)); | ||
| 187 | if (!tf_model->output_tensors) { | ||
| 188 | av_freep(&tf_model->outputs); | ||
| 189 | return DNN_ERROR; | ||
| 190 | } | ||
| 191 | |||
| 192 | tf_model->nb_output = nb_output; | ||
| 193 | |||
| 194 | if (tf_model->session){ | 160 | if (tf_model->session){ |
| 195 | TF_CloseSession(tf_model->session, tf_model->status); | 161 | TF_CloseSession(tf_model->session, tf_model->status); |
| 196 | TF_DeleteSession(tf_model->session, tf_model->status); | 162 | TF_DeleteSession(tf_model->session, tf_model->status); |
| @@ -598,40 +564,57 @@ DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options) · 401 unmodified lines | |||
| 598 | } | 564 | } |
| 599 | 565 | ||
| 600 | model->model = (void *)tf_model; | 566 | model->model = (void *)tf_model; |
| 601 | model->set_input_output = &set_input_output_tf; | 567 | model->set_input = &set_input_tf; |
| 602 | model->get_input = &get_input_tf; | 568 | model->get_input = &get_input_tf; |
| 603 | model->options = options; | 569 | model->options = options; |
| 604 | 570 | ||
| 605 | return model; | 571 | return model; |
| 606 | } | 572 | } |
| 607 | 573 | ||
| 608 | 574 | DNNReturnType ff_dnn_execute_model_tf(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output) | |
| 609 | |||
| 610 | DNNReturnType ff_dnn_execute_model_tf(const DNNModel *model, DNNData *outputs, uint32_t nb_output) | ||
| 611 | { | 575 | { |
| 576 | TF_Output *tf_outputs; | ||
| 612 | TFModel *tf_model = (TFModel *)model->model; | 577 | TFModel *tf_model = (TFModel *)model->model; |
| 613 | uint32_t nb = FFMIN(nb_output, tf_model->nb_output); | 578 | |
| 614 | if (nb == 0) | 579 | tf_outputs = av_malloc_array(nb_output, sizeof(*tf_outputs)); |
| 580 | if (tf_outputs == NULL) | ||
| 615 | return DNN_ERROR; | 581 | return DNN_ERROR; |
| 616 | 582 | ||
| 617 | av_assert0(tf_model->output_tensors); | 583 | if (tf_model->output_tensors) { |
| 618 | for (uint32_t i = 0; i < tf_model->nb_output; ++i) { | 584 | for (uint32_t i = 0; i < tf_model->nb_output; ++i) { |
| 619 | if (tf_model->output_tensors[i]) { | 585 | if (tf_model->output_tensors[i]) { |
| 620 | TF_DeleteTensor(tf_model->output_tensors[i]); | 586 | TF_DeleteTensor(tf_model->output_tensors[i]); |
| 621 | tf_model->output_tensors[i] = NULL; | 587 | tf_model->output_tensors[i] = NULL; |
| 588 | } | ||
| 622 | } | 589 | } |
| 623 | } | 590 | } |
| 591 | av_freep(&tf_model->output_tensors); | ||
| 592 | tf_model->nb_output = nb_output; | ||
| 593 | tf_model->output_tensors = av_mallocz_array(nb_output, sizeof(*tf_model->output_tensors)); | ||
| 594 | if (!tf_model->output_tensors) { | ||
| 595 | av_freep(&tf_outputs); | ||
| 596 | return DNN_ERROR; | ||
| 597 | } | ||
| 598 | |||
| 599 | for (int i = 0; i < nb_output; ++i) { | ||
| 600 | tf_outputs[i].oper = TF_GraphOperationByName(tf_model->graph, output_names[i]); | ||
| 601 | if (!tf_outputs[i].oper) { | ||
| 602 | av_freep(&tf_outputs); | ||
| 603 | return DNN_ERROR; | ||
| 604 | } | ||
| 605 | tf_outputs[i].index = 0; | ||
| 606 | } | ||
| 624 | 607 | ||
| 625 | TF_SessionRun(tf_model->session, NULL, | 608 | TF_SessionRun(tf_model->session, NULL, |
| 626 | &tf_model->input, &tf_model->input_tensor, 1, | 609 | &tf_model->input, &tf_model->input_tensor, 1, |
| 627 | tf_model->outputs, tf_model->output_tensors, nb, | 610 | tf_outputs, tf_model->output_tensors, nb_output, |
| 628 | NULL, 0, NULL, tf_model->status); | 611 | NULL, 0, NULL, tf_model->status); |
| 629 | 612 | if (TF_GetCode(tf_model->status) != TF_OK) { | |
| 630 | if (TF_GetCode(tf_model->status) != TF_OK){ | 613 | av_freep(&tf_outputs); |
| 631 | return DNN_ERROR; | 614 | return DNN_ERROR; |
| 632 | } | 615 | } |
| 633 | 616 | ||
| 634 | for (uint32_t i = 0; i < nb; ++i) { | 617 | for (uint32_t i = 0; i < nb_output; ++i) { |
| 635 | outputs[i].height = TF_Dim(tf_model->output_tensors[i], 1); | 618 | outputs[i].height = TF_Dim(tf_model->output_tensors[i], 1); |
| 636 | outputs[i].width = TF_Dim(tf_model->output_tensors[i], 2); | 619 | outputs[i].width = TF_Dim(tf_model->output_tensors[i], 2); |
| 637 | outputs[i].channels = TF_Dim(tf_model->output_tensors[i], 3); | 620 | outputs[i].channels = TF_Dim(tf_model->output_tensors[i], 3); |
| @@ -639,6 +622,7 @@ DNNReturnType ff_dnn_execute_model_tf(const DNNModel *model, DNNData *outputs, u · 1 unmodified line | |||
| 639 | outputs[i].dt = TF_TensorType(tf_model->output_tensors[i]); | 622 | outputs[i].dt = TF_TensorType(tf_model->output_tensors[i]); |
| 640 | } | 623 | } |
| 641 | 624 | ||
| 625 | av_freep(&tf_outputs); | ||
| 642 | return DNN_SUCCESS; | 626 | return DNN_SUCCESS; |
| 643 | } | 627 | } |
| 644 | 628 | ||
| @@ -669,7 +653,6 @@ void ff_dnn_free_model_tf(DNNModel **model) · 24 unmodified lines | |||
| 669 | } | 653 | } |
| 670 | } | 654 | } |
| 671 | } | 655 | } |
| 672 | av_freep(&tf_model->outputs); | ||
| 673 | av_freep(&tf_model->output_tensors); | 656 | av_freep(&tf_model->output_tensors); |
| 674 | av_freep(&tf_model); | 657 | av_freep(&tf_model); |
| 675 | av_freep(model); | 658 | av_freep(model); |
| @@ -31,7 +31,7 @@ · 30 unmodified lines | |||
| 31 | 31 | ||
| 32 | DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options); | 32 | DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options); |
| 33 | 33 | ||
| 34 | DNNReturnType ff_dnn_execute_model_tf(const DNNModel *model, DNNData *outputs, uint32_t nb_output); | 34 | DNNReturnType ff_dnn_execute_model_tf(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output); |
| 35 | 35 | ||
| 36 | void ff_dnn_free_model_tf(DNNModel **model); | 36 | void ff_dnn_free_model_tf(DNNModel **model); |
| 37 | 37 | ||
| @@ -50,7 +50,7 @@ typedef struct DNNModel{ · 49 unmodified lines | |||
| 50 | DNNReturnType (*get_input)(void *model, DNNData *input, const char *input_name); | 50 | DNNReturnType (*get_input)(void *model, DNNData *input, const char *input_name); |
| 51 | // Sets model input and output. | 51 | // Sets model input and output. |
| 52 | // Should be called at least once before model execution. | 52 | // Should be called at least once before model execution. |
| 53 | DNNReturnType (*set_input_output)(void *model, DNNData *input, const char *input_name, const char **output_names, uint32_t nb_output); | 53 | DNNReturnType (*set_input)(void *model, DNNData *input, const char *input_name); |
| 54 | } DNNModel; | 54 | } DNNModel; |
| 55 | 55 | ||
| 56 | // Stores pointers to functions for loading, executing, freeing DNN models for one of the backends. | 56 | // Stores pointers to functions for loading, executing, freeing DNN models for one of the backends. |
| @@ -58,7 +58,7 @@ typedef struct DNNModule{ · 1 unmodified line | |||
| 58 | // Loads model and parameters from given file. Returns NULL if it is not possible. | 58 | // Loads model and parameters from given file. Returns NULL if it is not possible. |
| 59 | DNNModel *(*load_model)(const char *model_filename, const char *options); | 59 | DNNModel *(*load_model)(const char *model_filename, const char *options); |
| 60 | // Executes model with specified input and output. Returns DNN_ERROR otherwise. | 60 | // Executes model with specified input and output. Returns DNN_ERROR otherwise. |
| 61 | DNNReturnType (*execute_model)(const DNNModel *model, DNNData *outputs, uint32_t nb_output); | 61 | DNNReturnType (*execute_model)(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output); |
| 62 | // Frees memory allocated for model. | 62 | // Frees memory allocated for model. |
| 63 | void (*free_model)(DNNModel **model); | 63 | void (*free_model)(DNNModel **model); |
| 64 | } DNNModule; | 64 | } DNNModule; |
| @@ -78,14 +78,13 @@ static int config_inputs(AVFilterLink *inlink) · 77 unmodified lines | |||
| 78 | { | 78 | { |
| 79 | AVFilterContext *ctx = inlink->dst; | 79 | AVFilterContext *ctx = inlink->dst; |
| 80 | DRContext *dr_context = ctx->priv; | 80 | DRContext *dr_context = ctx->priv; |
| 81 | const char *model_output_name = "y"; | ||
| 82 | DNNReturnType result; | 81 | DNNReturnType result; |
| 83 | 82 | ||
| 84 | dr_context->input.width = inlink->w; | 83 | dr_context->input.width = inlink->w; |
| 85 | dr_context->input.height = inlink->h; | 84 | dr_context->input.height = inlink->h; |
| 86 | dr_context->input.channels = 3; | 85 | dr_context->input.channels = 3; |
| 87 | 86 | ||
| 88 | result = (dr_context->model->set_input_output)(dr_context->model->model, &dr_context->input, "x", &model_output_name, 1); | 87 | result = (dr_context->model->set_input)(dr_context->model->model, &dr_context->input, "x"); |
| 89 | if (result != DNN_SUCCESS) { | 88 | if (result != DNN_SUCCESS) { |
| 90 | av_log(ctx, AV_LOG_ERROR, "could not set input and output for the model\n"); | 89 | av_log(ctx, AV_LOG_ERROR, "could not set input and output for the model\n"); |
| 91 | return AVERROR(EIO); | 90 | return AVERROR(EIO); |
| @@ -100,6 +99,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 8 unmodified lines | |||
| 100 | AVFilterLink *outlink = ctx->outputs[0]; | 99 | AVFilterLink *outlink = ctx->outputs[0]; |
| 101 | DRContext *dr_context = ctx->priv; | 100 | DRContext *dr_context = ctx->priv; |
| 102 | DNNReturnType dnn_result; | 101 | DNNReturnType dnn_result; |
| 102 | const char *model_output_name = "y"; | ||
| 103 | 103 | ||
| 104 | AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h); | 104 | AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h); |
| 105 | if (!out) { | 105 | if (!out) { |
| @@ -118,7 +118,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 12 unmodified lines | |||
| 118 | } | 118 | } |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | dnn_result = (dr_context->dnn_module->execute_model)(dr_context->model, &dr_context->output, 1); | 121 | dnn_result = (dr_context->dnn_module->execute_model)(dr_context->model, &dr_context->output, &model_output_name, 1); |
| 122 | if (dnn_result != DNN_SUCCESS){ | 122 | if (dnn_result != DNN_SUCCESS){ |
| 123 | av_log(ctx, AV_LOG_ERROR, "failed to execute model\n"); | 123 | av_log(ctx, AV_LOG_ERROR, "failed to execute model\n"); |
| 124 | return AVERROR(EIO); | 124 | return AVERROR(EIO); |
| @@ -218,9 +218,8 @@ static int config_input(AVFilterLink *inlink) · 217 unmodified lines | |||
| 218 | ctx->input.channels = model_input.channels; | 218 | ctx->input.channels = model_input.channels; |
| 219 | ctx->input.dt = model_input.dt; | 219 | ctx->input.dt = model_input.dt; |
| 220 | 220 | ||
| 221 | result = (ctx->model->set_input_output)(ctx->model->model, | 221 | result = (ctx->model->set_input)(ctx->model->model, |
| 222 | &ctx->input, ctx->model_inputname, | 222 | &ctx->input, ctx->model_inputname); |
| 223 | (const char **)&ctx->model_outputname, 1); | ||
| 224 | if (result != DNN_SUCCESS) { | 223 | if (result != DNN_SUCCESS) { |
| 225 | av_log(ctx, AV_LOG_ERROR, "could not set input and output for the model\n"); | 224 | av_log(ctx, AV_LOG_ERROR, "could not set input and output for the model\n"); |
| 226 | return AVERROR(EIO); | 225 | return AVERROR(EIO); |
| @@ -309,7 +308,7 @@ static int config_output(AVFilterLink *outlink) · 82 unmodified lines | |||
| 309 | DNNReturnType result; | 308 | DNNReturnType result; |
| 310 | 309 | ||
| 311 | // have a try run in case that the dnn model resize the frame | 310 | // have a try run in case that the dnn model resize the frame |
| 312 | result = (ctx->dnn_module->execute_model)(ctx->model, &ctx->output, 1); | 311 | result = (ctx->dnn_module->execute_model)(ctx->model, &ctx->output, (const char **)&ctx->model_outputname, 1); |
| 313 | if (result != DNN_SUCCESS){ | 312 | if (result != DNN_SUCCESS){ |
| 314 | av_log(ctx, AV_LOG_ERROR, "failed to execute model\n"); | 313 | av_log(ctx, AV_LOG_ERROR, "failed to execute model\n"); |
| 315 | return AVERROR(EIO); | 314 | return AVERROR(EIO); |
| @@ -456,7 +455,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 140 unmodified lines | |||
| 456 | 455 | ||
| 457 | copy_from_frame_to_dnn(ctx, in); | 456 | copy_from_frame_to_dnn(ctx, in); |
| 458 | 457 | ||
| 459 | dnn_result = (ctx->dnn_module->execute_model)(ctx->model, &ctx->output, 1); | 458 | dnn_result = (ctx->dnn_module->execute_model)(ctx->model, &ctx->output, (const char **)&ctx->model_outputname, 1); |
| 460 | if (dnn_result != DNN_SUCCESS){ | 459 | if (dnn_result != DNN_SUCCESS){ |
| 461 | av_log(ctx, AV_LOG_ERROR, "failed to execute model\n"); | 460 | av_log(ctx, AV_LOG_ERROR, "failed to execute model\n"); |
| 462 | av_frame_free(&in); | 461 | av_frame_free(&in); |
| @@ -124,13 +124,13 @@ static int config_props(AVFilterLink *inlink) · 123 unmodified lines | |||
| 124 | sr_context->input.height = inlink->h * sr_context->scale_factor; | 124 | sr_context->input.height = inlink->h * sr_context->scale_factor; |
| 125 | sr_context->input.channels = 1; | 125 | sr_context->input.channels = 1; |
| 126 | 126 | ||
| 127 | result = (sr_context->model->set_input_output)(sr_context->model->model, &sr_context->input, "x", &model_output_name, 1); | 127 | result = (sr_context->model->set_input)(sr_context->model->model, &sr_context->input, "x"); |
| 128 | if (result != DNN_SUCCESS){ | 128 | if (result != DNN_SUCCESS){ |
| 129 | av_log(context, AV_LOG_ERROR, "could not set input and output for the model\n"); | 129 | av_log(context, AV_LOG_ERROR, "could not set input and output for the model\n"); |
| 130 | return AVERROR(EIO); | 130 | return AVERROR(EIO); |
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | result = (sr_context->dnn_module->execute_model)(sr_context->model, &sr_context->output, 1); | 133 | result = (sr_context->dnn_module->execute_model)(sr_context->model, &sr_context->output, &model_output_name, 1); |
| 134 | if (result != DNN_SUCCESS){ | 134 | if (result != DNN_SUCCESS){ |
| 135 | av_log(context, AV_LOG_ERROR, "failed to execute loaded model\n"); | 135 | av_log(context, AV_LOG_ERROR, "failed to execute loaded model\n"); |
| 136 | return AVERROR(EIO); | 136 | return AVERROR(EIO); |
| @@ -139,12 +139,12 @@ static int config_props(AVFilterLink *inlink) · 2 unmodified lines | |||
| 139 | if (sr_context->input.height != sr_context->output.height || sr_context->input.width != sr_context->output.width){ | 139 | if (sr_context->input.height != sr_context->output.height || sr_context->input.width != sr_context->output.width){ |
| 140 | sr_context->input.width = inlink->w; | 140 | sr_context->input.width = inlink->w; |
| 141 | sr_context->input.height = inlink->h; | 141 | sr_context->input.height = inlink->h; |
| 142 | result = (sr_context->model->set_input_output)(sr_context->model->model, &sr_context->input, "x", &model_output_name, 1); | 142 | result = (sr_context->model->set_input)(sr_context->model->model, &sr_context->input, "x"); |
| 143 | if (result != DNN_SUCCESS){ | 143 | if (result != DNN_SUCCESS){ |
| 144 | av_log(context, AV_LOG_ERROR, "could not set input and output for the model\n"); | 144 | av_log(context, AV_LOG_ERROR, "could not set input and output for the model\n"); |
| 145 | return AVERROR(EIO); | 145 | return AVERROR(EIO); |
| 146 | } | 146 | } |
| 147 | result = (sr_context->dnn_module->execute_model)(sr_context->model, &sr_context->output, 1); | 147 | result = (sr_context->dnn_module->execute_model)(sr_context->model, &sr_context->output, &model_output_name, 1); |
| 148 | if (result != DNN_SUCCESS){ | 148 | if (result != DNN_SUCCESS){ |
| 149 | av_log(context, AV_LOG_ERROR, "failed to execute loaded model\n"); | 149 | av_log(context, AV_LOG_ERROR, "failed to execute loaded model\n"); |
| 150 | return AVERROR(EIO); | 150 | return AVERROR(EIO); |
| @@ -203,6 +203,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 52 unmodified lines | |||
| 203 | AVFilterLink *outlink = context->outputs[0]; | 203 | AVFilterLink *outlink = context->outputs[0]; |
| 204 | AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h); | 204 | AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h); |
| 205 | DNNReturnType dnn_result; | 205 | DNNReturnType dnn_result; |
| 206 | const char *model_output_name = "y"; | ||
| 206 | 207 | ||
| 207 | if (!out){ | 208 | if (!out){ |
| 208 | av_log(context, AV_LOG_ERROR, "could not allocate memory for output frame\n"); | 209 | av_log(context, AV_LOG_ERROR, "could not allocate memory for output frame\n"); |
| @@ -233,7 +234,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 24 unmodified lines | |||
| 233 | } | 234 | } |
| 234 | av_frame_free(&in); | 235 | av_frame_free(&in); |
| 235 | 236 | ||
| 236 | dnn_result = (sr_context->dnn_module->execute_model)(sr_context->model, &sr_context->output, 1); | 237 | dnn_result = (sr_context->dnn_module->execute_model)(sr_context->model, &sr_context->output, &model_output_name, 1); |
| 237 | if (dnn_result != DNN_SUCCESS){ | 238 | if (dnn_result != DNN_SUCCESS){ |
| 238 | av_log(context, AV_LOG_ERROR, "failed to execute loaded model\n"); | 239 | av_log(context, AV_LOG_ERROR, "failed to execute loaded model\n"); |
| 239 | return AVERROR(EIO); | 240 | return AVERROR(EIO); |