History

libavfilter/dnn_interface: use dims to represent shapes

For detect and classify output, width and height make no sence, so change width, height to dims to represent the shape of tensor. Use layout and dims to get width, height and channel.

Wenbin Chen committed 2 years ago

Commit 3de38b91 parent c695de57 files · +146 −90Browse files

Unified · Split

7 files
  1. libavfilter/dnn/dnn_backend_openvino.c +44 −36
  2. libavfilter/dnn/dnn_backend_tf.c +21 −11
  3. libavfilter/dnn/dnn_io_proc.c +21 −9
  4. libavfilter/dnn_interface.h +16 −1
  5. libavfilter/vf_dnn_classify.c +3 −3
  6. libavfilter/vf_dnn_detect.c +27 −23
  7. libavfilter/vf_dnn_processing.c +14 −7
libavfilter/dnn/dnn_backend_openvino.c+44−36
@@ -253,9 +253,9 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) · 252 unmodified lines
253253 ov_shape_free(&input_shape);
254254 return ov2_map_error(status, NULL);
255255 }
256− input.height = dims[1];
257− input.width = dims[2];
258− input.channels = dims[3];
256+ for (int i = 0; i < input_shape.rank; i++)
257+ input.dims[i] = dims[i];
258+ input.layout = DL_NHWC;
259259 input.dt = precision_to_datatype(precision);
260260 #else
261261 status = ie_infer_request_get_blob(request->infer_request, task->input_name, &input_blob);
@@ -278,9 +278,9 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) · 16 unmodified lines
278278 av_log(ctx, AV_LOG_ERROR, "Failed to get input blob buffer\n");
279279 return DNN_GENERIC_ERROR;
280280 }
281− input.height = dims.dims[2];
282− input.width = dims.dims[3];
283− input.channels = dims.dims[1];
281+ for (int i = 0; i < input_shape.rank; i++)
282+ input.dims[i] = dims[i];
283+ input.layout = DL_NCHW;
284284 input.data = blob_buffer.buffer;
285285 input.dt = precision_to_datatype(precision);
286286 #endif
@@ -339,8 +339,8 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) · 52 unmodified lines
339339 av_assert0(!"should not reach here");
340340 break;
341341 }
342− input.data = (uint8_t *)input.data
343− + input.width * input.height * input.channels * get_datatype_size(input.dt);
342+ input.data = (uint8_t *)input.data +
343+ input.dims[1] * input.dims[2] * input.dims[3] * get_datatype_size(input.dt);
344344 }
345345 #if HAVE_OPENVINO2
346346 ov_tensor_free(tensor);
@@ -403,10 +403,11 @@ static void infer_completion_callback(void *args) · 56 unmodified lines
403403 goto end;
404404 }
405405 outputs[i].dt = precision_to_datatype(precision);
406−
407− outputs[i].channels = output_shape.rank > 2 ? dims[output_shape.rank - 3] : 1;
408− outputs[i].height = output_shape.rank > 1 ? dims[output_shape.rank - 2] : 1;
409− outputs[i].width = output_shape.rank > 0 ? dims[output_shape.rank - 1] : 1;
406+ outputs[i].layout = DL_NCHW;
407+ outputs[i].dims[0] = 1;
408+ outputs[i].dims[1] = output_shape.rank > 2 ? dims[output_shape.rank - 3] : 1;
409+ outputs[i].dims[2] = output_shape.rank > 1 ? dims[output_shape.rank - 2] : 1;
410+ outputs[i].dims[3] = output_shape.rank > 0 ? dims[output_shape.rank - 1] : 1;
410411 av_assert0(request->lltask_count <= dims[0]);
411412 outputs[i].layout = ctx->options.layout;
412413 outputs[i].scale = ctx->options.scale;
@@ -445,9 +446,9 @@ static void infer_completion_callback(void *args) · 32 unmodified lines
445446 return;
446447 }
447448 output.data = blob_buffer.buffer;
448− output.channels = dims.dims[1];
449− output.height = dims.dims[2];
450− output.width = dims.dims[3];
449+ output.layout = DL_NCHW;
450+ for (int i = 0; i < 4; i++)
451+ output.dims[i] = dims.dims[i];
451452 av_assert0(request->lltask_count <= dims.dims[0]);
452453 output.dt = precision_to_datatype(precision);
453454 output.layout = ctx->options.layout;
@@ -469,8 +470,10 @@ static void infer_completion_callback(void *args) · 15 unmodified lines
469470 ff_proc_from_dnn_to_frame(task->out_frame, outputs, ctx);
470471 }
471472 } else {
472− task->out_frame->width = outputs[0].width;
473− task->out_frame->height = outputs[0].height;
473+ task->out_frame->width =
474+ outputs[0].dims[dnn_get_width_idx_by_layout(outputs[0].layout)];
475+ task->out_frame->height =
476+ outputs[0].dims[dnn_get_height_idx_by_layout(outputs[0].layout)];
474477 }
475478 break;
476479 case DFT_ANALYTICS_DETECT:
@@ -501,7 +504,8 @@ static void infer_completion_callback(void *args) · 24 unmodified lines
501504 av_freep(&request->lltasks[i]);
502505 for (int i = 0; i < ov_model->nb_outputs; i++)
503506 outputs[i].data = (uint8_t *)outputs[i].data +
504− outputs[i].width * outputs[i].height * outputs[i].channels * get_datatype_size(outputs[i].dt);
507+ outputs[i].dims[1] * outputs[i].dims[2] * outputs[i].dims[3] *
508+ get_datatype_size(outputs[i].dt);
505509 }
506510 end:
507511 #if HAVE_OPENVINO2
@@ -1085,7 +1089,6 @@ static int get_input_ov(void *model, DNNData *input, const char *input_name) · 577 unmodified lines
10851089 #if HAVE_OPENVINO2
10861090 ov_shape_t input_shape = {0};
10871091 ov_element_type_e precision;
1088− int64_t* dims;
10891092 ov_status_e status;
10901093 if (input_name)
10911094 status = ov_model_const_input_by_name(ov_model->ov_model, input_name, &ov_model->input_port);
@@ -1105,16 +1108,18 @@ static int get_input_ov(void *model, DNNData *input, const char *input_name) · 13 unmodified lines
11051108 av_log(ctx, AV_LOG_ERROR, "Failed to get input port shape.\n");
11061109 return ov2_map_error(status, NULL);
11071110 }
1108− dims = input_shape.dims;
1109− if (dims[1] <= 3) { // NCHW
1110− input->channels = dims[1];
1111− input->height = input_resizable ? -1 : dims[2];
1112− input->width = input_resizable ? -1 : dims[3];
1113− } else { // NHWC
1114− input->height = input_resizable ? -1 : dims[1];
1115− input->width = input_resizable ? -1 : dims[2];
1116− input->channels = dims[3];
1111+ for (int i = 0; i < 4; i++)
1112+ input->dims[i] = input_shape.dims[i];
1113+ if (input_resizable) {
1114+ input->dims[dnn_get_width_idx_by_layout(input->layout)] = -1;
1115+ input->dims[dnn_get_height_idx_by_layout(input->layout)] = -1;
11171116 }
1117+
1118+ if (input_shape.dims[1] <= 3) // NCHW
1119+ input->layout = DL_NCHW;
1120+ else // NHWC
1121+ input->layout = DL_NHWC;
1122+
11181123 input->dt = precision_to_datatype(precision);
11191124 ov_shape_free(&input_shape);
11201125 return 0;
@@ -1144,15 +1149,18 @@ static int get_input_ov(void *model, DNNData *input, const char *input_name) · 23 unmodified lines
11441149 return DNN_GENERIC_ERROR;
11451150 }
11461151
1147− if (dims[1] <= 3) { // NCHW
1148− input->channels = dims[1];
1149− input->height = input_resizable ? -1 : dims[2];
1150− input->width = input_resizable ? -1 : dims[3];
1151− } else { // NHWC
1152− input->height = input_resizable ? -1 : dims[1];
1153− input->width = input_resizable ? -1 : dims[2];
1154− input->channels = dims[3];
1152+ for (int i = 0; i < 4; i++)
1153+ input->dims[i] = input_shape.dims[i];
1154+ if (input_resizable) {
1155+ input->dims[dnn_get_width_idx_by_layout(input->layout)] = -1;
1156+ input->dims[dnn_get_height_idx_by_layout(input->layout)] = -1;
11551157 }
1158+
1159+ if (input_shape.dims[1] <= 3) // NCHW
1160+ input->layout = DL_NCHW;
1161+ else // NHWC
1162+ input->layout = DL_NHWC;
1163+
11561164 input->dt = precision_to_datatype(precision);
11571165 return 0;
11581166 }
libavfilter/dnn/dnn_backend_tf.c+21−11
@@ -251,7 +251,12 @@ static TF_Tensor *allocate_input_tensor(const DNNData *input) · 250 unmodified lines
251251 {
252252 TF_DataType dt;
253253 size_t size;
254− int64_t input_dims[] = {1, input->height, input->width, input->channels};
254+ int64_t input_dims[4] = { 0 };
255+
256+ input_dims[0] = 1;
257+ input_dims[1] = input->dims[dnn_get_height_idx_by_layout(input->layout)];
258+ input_dims[2] = input->dims[dnn_get_width_idx_by_layout(input->layout)];
259+ input_dims[3] = input->dims[dnn_get_channel_idx_by_layout(input->layout)];
255260 switch (input->dt) {
256261 case DNN_FLOAT:
257262 dt = TF_FLOAT;
@@ -310,9 +315,9 @@ static int get_input_tf(void *model, DNNData *input, const char *input_name) · 52 unmodified lines
310315
311316 // currently only NHWC is supported
312317 av_assert0(dims[0] == 1 || dims[0] == -1);
313− input->height = dims[1];
314− input->width = dims[2];
315− input->channels = dims[3];
318+ for (int i = 0; i < 4; i++)
319+ input->dims[i] = dims[i];
320+ input->layout = DL_NHWC;
316321
317322 return 0;
318323 }
@@ -640,8 +645,8 @@ static int fill_model_input_tf(TFModel *tf_model, TFRequestItem *request) { · 321 unmodified lines
640645 }
641646
642647 infer_request = request->infer_request;
643− input.height = task->in_frame->height;
644− input.width = task->in_frame->width;
648+ input.dims[1] = task->in_frame->height;
649+ input.dims[2] = task->in_frame->width;
645650
646651 infer_request->tf_input = av_malloc(sizeof(TF_Output));
647652 if (!infer_request->tf_input) {
@@ -731,9 +736,12 @@ static void infer_completion_callback(void *args) { · 83 unmodified lines
731736 }
732737
733738 for (uint32_t i = 0; i < task->nb_output; ++i) {
734− outputs[i].height = TF_Dim(infer_request->output_tensors[i], 1);
735− outputs[i].width = TF_Dim(infer_request->output_tensors[i], 2);
736− outputs[i].channels = TF_Dim(infer_request->output_tensors[i], 3);
739+ outputs[i].dims[dnn_get_height_idx_by_layout(outputs[i].layout)] =
740+ TF_Dim(infer_request->output_tensors[i], 1);
741+ outputs[i].dims[dnn_get_width_idx_by_layout(outputs[i].layout)] =
742+ TF_Dim(infer_request->output_tensors[i], 2);
743+ outputs[i].dims[dnn_get_channel_idx_by_layout(outputs[i].layout)] =
744+ TF_Dim(infer_request->output_tensors[i], 3);
737745 outputs[i].data = TF_TensorData(infer_request->output_tensors[i]);
738746 outputs[i].dt = (DNNDataType)TF_TensorType(infer_request->output_tensors[i]);
739747 }
@@ -747,8 +755,10 @@ static void infer_completion_callback(void *args) { · 7 unmodified lines
747755 ff_proc_from_dnn_to_frame(task->out_frame, outputs, ctx);
748756 }
749757 } else {
750− task->out_frame->width = outputs[0].width;
751− task->out_frame->height = outputs[0].height;
758+ task->out_frame->width =
759+ outputs[0].dims[dnn_get_width_idx_by_layout(outputs[0].layout)];
760+ task->out_frame->height =
761+ outputs[0].dims[dnn_get_height_idx_by_layout(outputs[0].layout)];
752762 }
753763 break;
754764 case DFT_ANALYTICS_DETECT:
libavfilter/dnn/dnn_io_proc.c+21−9
@@ -70,7 +70,7 @@ int ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx) · 69 unmodified lines
7070 dst_data = (void **)frame->data;
7171 linesize[0] = frame->linesize[0];
7272 if (output->layout == DL_NCHW) {
73− middle_data = av_malloc(plane_size * output->channels);
73+ middle_data = av_malloc(plane_size * output->dims[1]);
7474 if (!middle_data) {
7575 ret = AVERROR(ENOMEM);
7676 goto err;
@@ -209,7 +209,7 @@ int ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx) · 132 unmodified lines
209209 src_data = (void **)frame->data;
210210 linesize[0] = frame->linesize[0];
211211 if (input->layout == DL_NCHW) {
212− middle_data = av_malloc(plane_size * input->channels);
212+ middle_data = av_malloc(plane_size * input->dims[1]);
213213 if (!middle_data) {
214214 ret = AVERROR(ENOMEM);
215215 goto err;
@@ -346,6 +346,7 @@ int ff_frame_to_dnn_classify(AVFrame *frame, DNNData *input, uint32_t bbox_index · 130 unmodified lines
346346 int ret = 0;
347347 enum AVPixelFormat fmt;
348348 int left, top, width, height;
349+ int width_idx, height_idx;
349350 const AVDetectionBBoxHeader *header;
350351 const AVDetectionBBox *bbox;
351352 AVFrameSideData *sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DETECTION_BBOXES);
@@ -364,6 +365,9 @@ int ff_frame_to_dnn_classify(AVFrame *frame, DNNData *input, uint32_t bbox_index · 12 unmodified lines
364365 return AVERROR(ENOSYS);
365366 }
366367
368+ width_idx = dnn_get_width_idx_by_layout(input->layout);
369+ height_idx = dnn_get_height_idx_by_layout(input->layout);
370+
367371 header = (const AVDetectionBBoxHeader *)sd->data;
368372 bbox = av_get_detection_bbox(header, bbox_index);
369373
@@ -374,17 +378,20 @@ int ff_frame_to_dnn_classify(AVFrame *frame, DNNData *input, uint32_t bbox_index · 4 unmodified lines
374378
375379 fmt = get_pixel_format(input);
376380 sws_ctx = sws_getContext(width, height, frame->format,
377− input->width, input->height, fmt,
381+ input->dims[width_idx],
382+ input->dims[height_idx], fmt,
378383 SWS_FAST_BILINEAR, NULL, NULL, NULL);
379384 if (!sws_ctx) {
380385 av_log(log_ctx, AV_LOG_ERROR, "Failed to create scale context for the conversion "
381386 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
382387 av_get_pix_fmt_name(frame->format), width, height,
383− av_get_pix_fmt_name(fmt), input->width, input->height);
388+ av_get_pix_fmt_name(fmt),
389+ input->dims[width_idx],
390+ input->dims[height_idx]);
384391 return AVERROR(EINVAL);
385392 }
386393
387− ret = av_image_fill_linesizes(linesizes, fmt, input->width);
394+ ret = av_image_fill_linesizes(linesizes, fmt, input->dims[width_idx]);
388395 if (ret < 0) {
389396 av_log(log_ctx, AV_LOG_ERROR, "unable to get linesizes with av_image_fill_linesizes");
390397 sws_freeContext(sws_ctx);
@@ -414,7 +421,7 @@ int ff_frame_to_dnn_detect(AVFrame *frame, DNNData *input, void *log_ctx) · 23 unmodified lines
414421 {
415422 struct SwsContext *sws_ctx;
416423 int linesizes[4];
417− int ret = 0;
424+ int ret = 0, width_idx, height_idx;
418425 enum AVPixelFormat fmt = get_pixel_format(input);
419426
420427 /* (scale != 1 and scale != 0) or mean != 0 */
@@ -430,18 +437,23 @@ int ff_frame_to_dnn_detect(AVFrame *frame, DNNData *input, void *log_ctx) · 9 unmodified lines
430437 return AVERROR(ENOSYS);
431438 }
432439
440+ width_idx = dnn_get_width_idx_by_layout(input->layout);
441+ height_idx = dnn_get_height_idx_by_layout(input->layout);
442+
433443 sws_ctx = sws_getContext(frame->width, frame->height, frame->format,
434− input->width, input->height, fmt,
444+ input->dims[width_idx],
445+ input->dims[height_idx], fmt,
435446 SWS_FAST_BILINEAR, NULL, NULL, NULL);
436447 if (!sws_ctx) {
437448 av_log(log_ctx, AV_LOG_ERROR, "Impossible to create scale context for the conversion "
438449 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
439450 av_get_pix_fmt_name(frame->format), frame->width, frame->height,
440− av_get_pix_fmt_name(fmt), input->width, input->height);
451+ av_get_pix_fmt_name(fmt), input->dims[width_idx],
452+ input->dims[height_idx]);
441453 return AVERROR(EINVAL);
442454 }
443455
444− ret = av_image_fill_linesizes(linesizes, fmt, input->width);
456+ ret = av_image_fill_linesizes(linesizes, fmt, input->dims[width_idx]);
445457 if (ret < 0) {
446458 av_log(log_ctx, AV_LOG_ERROR, "unable to get linesizes with av_image_fill_linesizes");
447459 sws_freeContext(sws_ctx);
libavfilter/dnn_interface.h+16−1
@@ -64,7 +64,7 @@ typedef enum { · 63 unmodified lines
6464
6565 typedef struct DNNData{
6666 void *data;
67− int width, height, channels;
67+ int dims[4];
6868 // dt and order together decide the color format
6969 DNNDataType dt;
7070 DNNColorOrder order;
@@ -134,4 +134,19 @@ typedef struct DNNModule{ · 63 unmodified lines
134134 // Initializes DNNModule depending on chosen backend.
135135 const DNNModule *ff_get_dnn_module(DNNBackendType backend_type, void *log_ctx);
136136
137+static inline int dnn_get_width_idx_by_layout(DNNLayout layout)
138+{
139+ return layout == DL_NHWC ? 2 : 3;
140+}
141+
142+static inline int dnn_get_height_idx_by_layout(DNNLayout layout)
143+{
144+ return layout == DL_NHWC ? 1 : 2;
145+}
146+
147+static inline int dnn_get_channel_idx_by_layout(DNNLayout layout)
148+{
149+ return layout == DL_NHWC ? 3 : 1;
150+}
151+
137152 #endif
libavfilter/vf_dnn_classify.c+3−3
@@ -68,8 +68,8 @@ static int dnn_classify_post_proc(AVFrame *frame, DNNData *output, uint32_t bbox · 67 unmodified lines
6868 uint32_t label_id;
6969 float confidence;
7070 AVFrameSideData *sd;
71−
72− if (output->channels <= 0) {
71+ int output_size = output->dims[3] * output->dims[2] * output->dims[1];
72+ if (output_size <= 0) {
7373 return -1;
7474 }
7575
@@ -88,7 +88,7 @@ static int dnn_classify_post_proc(AVFrame *frame, DNNData *output, uint32_t bbox · 12 unmodified lines
8888 classifications = output->data;
8989 label_id = 0;
9090 confidence= classifications[0];
91− for (int i = 1; i < output->channels; i++) {
91+ for (int i = 1; i < output_size; i++) {
9292 if (classifications[i] > confidence) {
9393 label_id = i;
9494 confidence= classifications[i];
libavfilter/vf_dnn_detect.c+27−23
@@ -166,14 +166,14 @@ static int dnn_detect_parse_yolo_output(AVFrame *frame, DNNData *output, int out · 165 unmodified lines
166166 scale_w = cell_w;
167167 scale_h = cell_h;
168168 } else {
169− if (output[output_index].height != output[output_index].width &&
170− output[output_index].height == output[output_index].channels) {
169+ if (output[output_index].dims[2] != output[output_index].dims[3] &&
170+ output[output_index].dims[2] == output[output_index].dims[1]) {
171171 is_NHWC = 1;
172− cell_w = output[output_index].height;
173− cell_h = output[output_index].channels;
172+ cell_w = output[output_index].dims[2];
173+ cell_h = output[output_index].dims[1];
174174 } else {
175− cell_w = output[output_index].width;
176− cell_h = output[output_index].height;
175+ cell_w = output[output_index].dims[3];
176+ cell_h = output[output_index].dims[2];
177177 }
178178 scale_w = ctx->scale_width;
179179 scale_h = ctx->scale_height;
@@ -205,14 +205,14 @@ static int dnn_detect_parse_yolo_output(AVFrame *frame, DNNData *output, int out · 25 unmodified lines
205205 return AVERROR(EINVAL);
206206 }
207207
208− if (output[output_index].channels * output[output_index].width *
209− output[output_index].height % (box_size * cell_w * cell_h)) {
208+ if (output[output_index].dims[1] * output[output_index].dims[2] *
209+ output[output_index].dims[3] % (box_size * cell_w * cell_h)) {
210210 av_log(filter_ctx, AV_LOG_ERROR, "wrong cell_w, cell_h or nb_classes\n");
211211 return AVERROR(EINVAL);
212212 }
213− detection_boxes = output[output_index].channels *
214− output[output_index].height *
215− output[output_index].width / box_size / cell_w / cell_h;
213+ detection_boxes = output[output_index].dims[1] *
214+ output[output_index].dims[2] *
215+ output[output_index].dims[3] / box_size / cell_w / cell_h;
216216
217217 anchors = anchors + (detection_boxes * output_index * 2);
218218 /**
@@ -373,18 +373,18 @@ static int dnn_detect_post_proc_ssd(AVFrame *frame, DNNData *output, int nb_outp · 154 unmodified lines
373373 int scale_w = ctx->scale_width;
374374 int scale_h = ctx->scale_height;
375375
376− if (nb_outputs == 1 && output->width == 7) {
377− proposal_count = output->height;
378− detect_size = output->width;
376+ if (nb_outputs == 1 && output->dims[3] == 7) {
377+ proposal_count = output->dims[2];
378+ detect_size = output->dims[3];
379379 detections = output->data;
380− } else if (nb_outputs == 2 && output[0].width == 5) {
381− proposal_count = output[0].height;
382− detect_size = output[0].width;
380+ } else if (nb_outputs == 2 && output[0].dims[3] == 5) {
381+ proposal_count = output[0].dims[2];
382+ detect_size = output[0].dims[3];
383383 detections = output[0].data;
384384 labels = output[1].data;
385− } else if (nb_outputs == 2 && output[1].width == 5) {
386− proposal_count = output[1].height;
387− detect_size = output[1].width;
385+ } else if (nb_outputs == 2 && output[1].dims[3] == 5) {
386+ proposal_count = output[1].dims[2];
387+ detect_size = output[1].dims[3];
388388 detections = output[1].data;
389389 labels = output[0].data;
390390 } else {
@@ -821,15 +821,19 @@ static int config_input(AVFilterLink *inlink) · 430 unmodified lines
821821 AVFilterContext *context = inlink->dst;
822822 DnnDetectContext *ctx = context->priv;
823823 DNNData model_input;
824− int ret;
824+ int ret, width_idx, height_idx;
825825
826826 ret = ff_dnn_get_input(&ctx->dnnctx, &model_input);
827827 if (ret != 0) {
828828 av_log(ctx, AV_LOG_ERROR, "could not get input from the model\n");
829829 return ret;
830830 }
831− ctx->scale_width = model_input.width == -1 ? inlink->w : model_input.width;
832− ctx->scale_height = model_input.height == -1 ? inlink->h : model_input.height;
831+ width_idx = dnn_get_width_idx_by_layout(model_input.layout);
832+ height_idx = dnn_get_height_idx_by_layout(model_input.layout);
833+ ctx->scale_width = model_input.dims[width_idx] == -1 ? inlink->w :
834+ model_input.dims[width_idx];
835+ ctx->scale_height = model_input.dims[height_idx] == -1 ? inlink->h :
836+ model_input.dims[height_idx];
833837
834838 return 0;
835839 }
libavfilter/vf_dnn_processing.c+14−7
@@ -77,22 +77,29 @@ static const enum AVPixelFormat pix_fmts[] = { · 76 unmodified lines
7777 "the frame's format %s does not match " \
7878 "the model input channel %d\n", \
7979 av_get_pix_fmt_name(fmt), \
80− model_input->channels);
80+ model_input->dims[dnn_get_channel_idx_by_layout(model_input->layout)]);
8181
8282 static int check_modelinput_inlink(const DNNData *model_input, const AVFilterLink *inlink)
8383 {
8484 AVFilterContext *ctx = inlink->dst;
8585 enum AVPixelFormat fmt = inlink->format;
86+ int width_idx, height_idx;
8687
88+ width_idx = dnn_get_width_idx_by_layout(model_input->layout);
89+ height_idx = dnn_get_height_idx_by_layout(model_input->layout);
8790 // the design is to add explicit scale filter before this filter
88− if (model_input->height != -1 && model_input->height != inlink->h) {
91+ if (model_input->dims[height_idx] != -1 &&
92+ model_input->dims[height_idx] != inlink->h) {
8993 av_log(ctx, AV_LOG_ERROR, "the model requires frame height %d but got %d\n",
90− model_input->height, inlink->h);
94+ model_input->dims[height_idx],
95+ inlink->h);
9196 return AVERROR(EIO);
9297 }
93− if (model_input->width != -1 && model_input->width != inlink->w) {
98+ if (model_input->dims[width_idx] != -1 &&
99+ model_input->dims[width_idx] != inlink->w) {
94100 av_log(ctx, AV_LOG_ERROR, "the model requires frame width %d but got %d\n",
95− model_input->width, inlink->w);
101+ model_input->dims[width_idx],
102+ inlink->w);
96103 return AVERROR(EIO);
97104 }
98105 if (model_input->dt != DNN_FLOAT) {
@@ -103,7 +110,7 @@ static int check_modelinput_inlink(const DNNData *model_input, const AVFilterLin · 4 unmodified lines
103110 switch (fmt) {
104111 case AV_PIX_FMT_RGB24:
105112 case AV_PIX_FMT_BGR24:
106− if (model_input->channels != 3) {
113+ if (model_input->dims[dnn_get_channel_idx_by_layout(model_input->layout)] != 3) {
107114 LOG_FORMAT_CHANNEL_MISMATCH();
108115 return AVERROR(EIO);
109116 }
@@ -116,7 +123,7 @@ static int check_modelinput_inlink(const DNNData *model_input, const AVFilterLin · 6 unmodified lines
116123 case AV_PIX_FMT_YUV410P:
117124 case AV_PIX_FMT_YUV411P:
118125 case AV_PIX_FMT_NV12:
119− if (model_input->channels != 1) {
126+ if (model_input->dims[dnn_get_channel_idx_by_layout(model_input->layout)] != 1) {
120127 LOG_FORMAT_CHANNEL_MISMATCH();
121128 return AVERROR(EIO);
122129 }

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