History

libavfilter/dnn: add layout option to openvino backend

Dnn models have different input layout (NCHW or NHWC), so a "layout" option is added Use openvino's API to do layout conversion for input data. Use swscale to do layout conversion for output data as openvino doesn't have similiar C API for output.

Wenbin Chen committed 3 years ago

Commit 74ce1d21 parent 58d9b5c3 files · +185 −20Browse files

Unified · Split

3 files
  1. libavfilter/dnn/dnn_backend_openvino.c +42 −5
  2. libavfilter/dnn/dnn_io_proc.c +136 −15
  3. libavfilter/dnn_interface.h +7 −0
libavfilter/dnn/dnn_backend_openvino.c+42−5
@@ -45,6 +45,7 @@ typedef struct OVOptions{ · 44 unmodified lines
45 uint8_t async;45 uint8_t async;
46 int batch_size;46 int batch_size;
47 int input_resizable;47 int input_resizable;
48 DNNLayout layout;
48} OVOptions;49} OVOptions;
49 50
50typedef struct OVContext {51typedef struct OVContext {
@@ -100,6 +101,10 @@ static const AVOption dnn_openvino_options[] = { · 49 unmodified lines
100 DNN_BACKEND_COMMON_OPTIONS101 DNN_BACKEND_COMMON_OPTIONS
101 { "batch_size", "batch size per request", OFFSET(options.batch_size), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 1000, FLAGS},102 { "batch_size", "batch size per request", OFFSET(options.batch_size), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 1000, FLAGS},
102 { "input_resizable", "can input be resizable or not", OFFSET(options.input_resizable), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },103 { "input_resizable", "can input be resizable or not", OFFSET(options.input_resizable), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
104 { "layout", "input layout of model", OFFSET(options.layout), AV_OPT_TYPE_INT, { .i64 = DL_NONE}, DL_NONE, DL_NHWC, FLAGS, "layout" },
105 { "none", "none", 0, AV_OPT_TYPE_CONST, { .i64 = DL_NONE }, 0, 0, FLAGS, "layout"},
106 { "nchw", "nchw", 0, AV_OPT_TYPE_CONST, { .i64 = DL_NCHW }, 0, 0, FLAGS, "layout"},
107 { "nhwc", "nhwc", 0, AV_OPT_TYPE_CONST, { .i64 = DL_NHWC }, 0, 0, FLAGS, "layout"},
103 { NULL }108 { NULL }
104};109};
105 110
@@ -235,9 +240,9 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) · 129 unmodified lines
235 avpriv_report_missing_feature(ctx, "Do not support dynamic model.");240 avpriv_report_missing_feature(ctx, "Do not support dynamic model.");
236 return AVERROR(ENOSYS);241 return AVERROR(ENOSYS);
237 }242 }
238 input.height = dims[2];243 input.height = dims[1];
239 input.width = dims[3];244 input.width = dims[2];
240 input.channels = dims[1];245 input.channels = dims[3];
241 input.dt = precision_to_datatype(precision);246 input.dt = precision_to_datatype(precision);
242 input.data = av_malloc(input.height * input.width * input.channels * get_datatype_size(input.dt));247 input.data = av_malloc(input.height * input.width * input.channels * get_datatype_size(input.dt));
243 if (!input.data) {248 if (!input.data) {
@@ -412,6 +417,7 @@ static void infer_completion_callback(void *args) · 168 unmodified lines
412 av_assert0(request->lltask_count <= dims.dims[0]);417 av_assert0(request->lltask_count <= dims.dims[0]);
413#endif418#endif
414 output.dt = precision_to_datatype(precision);419 output.dt = precision_to_datatype(precision);
420 output.layout = ctx->options.layout;
415 421
416 av_assert0(request->lltask_count >= 1);422 av_assert0(request->lltask_count >= 1);
417 for (int i = 0; i < request->lltask_count; ++i) {423 for (int i = 0; i < request->lltask_count; ++i) {
@@ -540,11 +546,14 @@ static int init_model_ov(OVModel *ov_model, const char *input_name, const char * · 122 unmodified lines
540 OVContext *ctx = &ov_model->ctx;546 OVContext *ctx = &ov_model->ctx;
541#if HAVE_OPENVINO2547#if HAVE_OPENVINO2
542 ov_status_e status;548 ov_status_e status;
543 ov_preprocess_input_tensor_info_t* input_tensor_info;549 ov_preprocess_input_tensor_info_t* input_tensor_info = NULL;
544 ov_preprocess_output_tensor_info_t* output_tensor_info;550 ov_preprocess_output_tensor_info_t* output_tensor_info = NULL;
551 ov_preprocess_input_model_info_t* input_model_info = NULL;
545 ov_model_t *tmp_ov_model;552 ov_model_t *tmp_ov_model;
546 ov_layout_t* NHWC_layout = NULL;553 ov_layout_t* NHWC_layout = NULL;
554 ov_layout_t* NCHW_layout = NULL;
547 const char* NHWC_desc = "NHWC";555 const char* NHWC_desc = "NHWC";
556 const char* NCHW_desc = "NCHW";
548 const char* device = ctx->options.device_type;557 const char* device = ctx->options.device_type;
549#else558#else
550 IEStatusCode status;559 IEStatusCode status;
@@ -589,6 +598,7 @@ static int init_model_ov(OVModel *ov_model, const char *input_name, const char * · 38 unmodified lines
589 598
590 //set input layout599 //set input layout
591 status = ov_layout_create(NHWC_desc, &NHWC_layout);600 status = ov_layout_create(NHWC_desc, &NHWC_layout);
601 status |= ov_layout_create(NCHW_desc, &NCHW_layout);
592 if (status != OK) {602 if (status != OK) {
593 av_log(ctx, AV_LOG_ERROR, "Failed to create layout for input.\n");603 av_log(ctx, AV_LOG_ERROR, "Failed to create layout for input.\n");
594 ret = ov2_map_error(status, NULL);604 ret = ov2_map_error(status, NULL);
@@ -602,6 +612,22 @@ static int init_model_ov(OVModel *ov_model, const char *input_name, const char * · 7 unmodified lines
602 goto err;612 goto err;
603 }613 }
604 614
615 status = ov_preprocess_input_info_get_model_info(ov_model->input_info, &input_model_info);
616 if (status != OK) {
617 av_log(ctx, AV_LOG_ERROR, "Failed to get input model info\n");
618 ret = ov2_map_error(status, NULL);
619 goto err;
620 }
621 if (ctx->options.layout == DL_NCHW)
622 status = ov_preprocess_input_model_info_set_layout(input_model_info, NCHW_layout);
623 else if (ctx->options.layout == DL_NHWC)
624 status = ov_preprocess_input_model_info_set_layout(input_model_info, NHWC_layout);
625 if (status != OK) {
626 av_log(ctx, AV_LOG_ERROR, "Failed to get set input model layout\n");
627 ret = ov2_map_error(status, NULL);
628 goto err;
629 }
630
605 if (ov_model->model->func_type != DFT_PROCESS_FRAME)631 if (ov_model->model->func_type != DFT_PROCESS_FRAME)
606 //set precision only for detect and classify632 //set precision only for detect and classify
607 status = ov_preprocess_input_tensor_info_set_element_type(input_tensor_info, U8);633 status = ov_preprocess_input_tensor_info_set_element_type(input_tensor_info, U8);
@@ -639,6 +665,9 @@ static int init_model_ov(OVModel *ov_model, const char *input_name, const char * · 31 unmodified lines
639 ret = ov2_map_error(status, NULL);665 ret = ov2_map_error(status, NULL);
640 goto err;666 goto err;
641 }667 }
668 ov_preprocess_input_model_info_free(input_model_info);
669 ov_layout_free(NCHW_layout);
670 ov_layout_free(NHWC_layout);
642#else671#else
643 if (ctx->options.batch_size > 1) {672 if (ctx->options.batch_size > 1) {
644 input_shapes_t input_shapes;673 input_shapes_t input_shapes;
@@ -783,6 +812,14 @@ static int init_model_ov(OVModel *ov_model, const char *input_name, const char * · 138 unmodified lines
783 return 0;812 return 0;
784 813
785err:814err:
815#if HAVE_OPENVINO2
816 if (NCHW_layout)
817 ov_layout_free(NCHW_layout);
818 if (NHWC_layout)
819 ov_layout_free(NHWC_layout);
820 if (input_model_info)
821 ov_preprocess_input_model_info_free(input_model_info);
822#endif
786 dnn_free_model_ov(&ov_model->model);823 dnn_free_model_ov(&ov_model->model);
787 return ret;824 return ret;
788}825}
libavfilter/dnn/dnn_io_proc.c+136−15
@@ -27,6 +27,12 @@ · 26 unmodified lines
27int ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx)27int ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx)
28{28{
29 struct SwsContext *sws_ctx;29 struct SwsContext *sws_ctx;
30 int ret = 0;
31 int linesize[4] = { 0 };
32 void **dst_data = NULL;
33 void *middle_data = NULL;
34 uint8_t *planar_data[4] = { 0 };
35 int plane_size = frame->width * frame->height * sizeof(uint8_t);
30 int bytewidth = av_image_get_linesize(frame->format, frame->width, 0);36 int bytewidth = av_image_get_linesize(frame->format, frame->width, 0);
31 if (bytewidth < 0) {37 if (bytewidth < 0) {
32 return AVERROR(EINVAL);38 return AVERROR(EINVAL);
@@ -35,6 +41,17 @@ int ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx) · 2 unmodified lines
35 avpriv_report_missing_feature(log_ctx, "data type rather than DNN_FLOAT");41 avpriv_report_missing_feature(log_ctx, "data type rather than DNN_FLOAT");
36 return AVERROR(ENOSYS);42 return AVERROR(ENOSYS);
37 }43 }
44 dst_data = (void **)frame->data;
45 linesize[0] = frame->linesize[0];
46 if (output->layout == DL_NCHW) {
47 middle_data = av_malloc(plane_size * output->channels);
48 if (!middle_data) {
49 ret = AVERROR(ENOMEM);
50 goto err;
51 }
52 dst_data = &middle_data;
53 linesize[0] = frame->width * 3;
54 }
38 55
39 switch (frame->format) {56 switch (frame->format) {
40 case AV_PIX_FMT_RGB24:57 case AV_PIX_FMT_RGB24:
@@ -51,18 +68,52 @@ int ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx) · 10 unmodified lines
51 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",68 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
52 av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32), frame->width * 3, frame->height,69 av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32), frame->width * 3, frame->height,
53 av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width * 3, frame->height);70 av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width * 3, frame->height);
54 return AVERROR(EINVAL);71 ret = AVERROR(EINVAL);
72 goto err;
55 }73 }
56 sws_scale(sws_ctx, (const uint8_t *[4]){(const uint8_t *)output->data, 0, 0, 0},74 sws_scale(sws_ctx, (const uint8_t *[4]){(const uint8_t *)output->data, 0, 0, 0},
57 (const int[4]){frame->width * 3 * sizeof(float), 0, 0, 0}, 0, frame->height,75 (const int[4]){frame->width * 3 * sizeof(float), 0, 0, 0}, 0, frame->height,
58 (uint8_t * const*)frame->data, frame->linesize);76 (uint8_t * const*)dst_data, linesize);
59 sws_freeContext(sws_ctx);77 sws_freeContext(sws_ctx);
60 return 0;78 // convert data from planar to packed
79 if (output->layout == DL_NCHW) {
80 sws_ctx = sws_getContext(frame->width,
81 frame->height,
82 AV_PIX_FMT_GBRP,
83 frame->width,
84 frame->height,
85 frame->format,
86 0, NULL, NULL, NULL);
87 if (!sws_ctx) {
88 av_log(log_ctx, AV_LOG_ERROR, "Impossible to create scale context for the conversion "
89 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
90 av_get_pix_fmt_name(AV_PIX_FMT_GBRP), frame->width, frame->height,
91 av_get_pix_fmt_name(frame->format),frame->width, frame->height);
92 ret = AVERROR(EINVAL);
93 goto err;
94 }
95 if (frame->format == AV_PIX_FMT_RGB24) {
96 planar_data[0] = (uint8_t *)middle_data + plane_size;
97 planar_data[1] = (uint8_t *)middle_data + plane_size * 2;
98 planar_data[2] = (uint8_t *)middle_data;
99 } else if (frame->format == AV_PIX_FMT_BGR24) {
100 planar_data[0] = (uint8_t *)middle_data + plane_size;
101 planar_data[1] = (uint8_t *)middle_data;
102 planar_data[2] = (uint8_t *)middle_data + plane_size * 2;
103 }
104 sws_scale(sws_ctx, (const uint8_t * const *)planar_data,
105 (const int [4]){frame->width * sizeof(uint8_t),
106 frame->width * sizeof(uint8_t),
107 frame->width * sizeof(uint8_t), 0},
108 0, frame->height, frame->data, frame->linesize);
109 sws_freeContext(sws_ctx);
110 }
111 break;
61 case AV_PIX_FMT_GRAYF32:112 case AV_PIX_FMT_GRAYF32:
62 av_image_copy_plane(frame->data[0], frame->linesize[0],113 av_image_copy_plane(frame->data[0], frame->linesize[0],
63 output->data, bytewidth,114 output->data, bytewidth,
64 bytewidth, frame->height);115 bytewidth, frame->height);
65 return 0;116 break;
66 case AV_PIX_FMT_YUV420P:117 case AV_PIX_FMT_YUV420P:
67 case AV_PIX_FMT_YUV422P:118 case AV_PIX_FMT_YUV422P:
68 case AV_PIX_FMT_YUV444P:119 case AV_PIX_FMT_YUV444P:
@@ -82,24 +133,34 @@ int ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx) · 13 unmodified lines
82 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",133 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
83 av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32), frame->width, frame->height,134 av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32), frame->width, frame->height,
84 av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width, frame->height);135 av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width, frame->height);
85 return AVERROR(EINVAL);136 ret = AVERROR(EINVAL);
137 goto err;
86 }138 }
87 sws_scale(sws_ctx, (const uint8_t *[4]){(const uint8_t *)output->data, 0, 0, 0},139 sws_scale(sws_ctx, (const uint8_t *[4]){(const uint8_t *)output->data, 0, 0, 0},
88 (const int[4]){frame->width * sizeof(float), 0, 0, 0}, 0, frame->height,140 (const int[4]){frame->width * sizeof(float), 0, 0, 0}, 0, frame->height,
89 (uint8_t * const*)frame->data, frame->linesize);141 (uint8_t * const*)frame->data, frame->linesize);
90 sws_freeContext(sws_ctx);142 sws_freeContext(sws_ctx);
91 return 0;143 break;
92 default:144 default:
93 avpriv_report_missing_feature(log_ctx, "%s", av_get_pix_fmt_name(frame->format));145 avpriv_report_missing_feature(log_ctx, "%s", av_get_pix_fmt_name(frame->format));
94 return AVERROR(ENOSYS);146 ret = AVERROR(ENOSYS);
147 goto err;
95 }148 }
96 149
97 return 0;150err:
151 av_free(middle_data);
152 return ret;
98}153}
99 154
100int ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx)155int ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx)
101{156{
102 struct SwsContext *sws_ctx;157 struct SwsContext *sws_ctx;
158 int ret = 0;
159 int linesize[4] = { 0 };
160 void **src_data = NULL;
161 void *middle_data = NULL;
162 uint8_t *planar_data[4] = { 0 };
163 int plane_size = frame->width * frame->height * sizeof(uint8_t);
103 int bytewidth = av_image_get_linesize(frame->format, frame->width, 0);164 int bytewidth = av_image_get_linesize(frame->format, frame->width, 0);
104 if (bytewidth < 0) {165 if (bytewidth < 0) {
105 return AVERROR(EINVAL);166 return AVERROR(EINVAL);
@@ -109,9 +170,54 @@ int ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx) · 3 unmodified lines
109 return AVERROR(ENOSYS);170 return AVERROR(ENOSYS);
110 }171 }
111 172
173 src_data = (void **)frame->data;
174 linesize[0] = frame->linesize[0];
175 if (input->layout == DL_NCHW) {
176 middle_data = av_malloc(plane_size * input->channels);
177 if (!middle_data) {
178 ret = AVERROR(ENOMEM);
179 goto err;
180 }
181 src_data = &middle_data;
182 linesize[0] = frame->width * 3;
183 }
184
112 switch (frame->format) {185 switch (frame->format) {
113 case AV_PIX_FMT_RGB24:186 case AV_PIX_FMT_RGB24:
114 case AV_PIX_FMT_BGR24:187 case AV_PIX_FMT_BGR24:
188 // convert data from planar to packed
189 if (input->layout == DL_NCHW) {
190 sws_ctx = sws_getContext(frame->width,
191 frame->height,
192 frame->format,
193 frame->width,
194 frame->height,
195 AV_PIX_FMT_GBRP,
196 0, NULL, NULL, NULL);
197 if (!sws_ctx) {
198 av_log(log_ctx, AV_LOG_ERROR, "Impossible to create scale context for the conversion "
199 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
200 av_get_pix_fmt_name(frame->format), frame->width, frame->height,
201 av_get_pix_fmt_name(AV_PIX_FMT_GBRP),frame->width, frame->height);
202 ret = AVERROR(EINVAL);
203 goto err;
204 }
205 if (frame->format == AV_PIX_FMT_RGB24) {
206 planar_data[0] = (uint8_t *)middle_data + plane_size;
207 planar_data[1] = (uint8_t *)middle_data + plane_size * 2;
208 planar_data[2] = (uint8_t *)middle_data;
209 } else if (frame->format == AV_PIX_FMT_BGR24) {
210 planar_data[0] = (uint8_t *)middle_data + plane_size;
211 planar_data[1] = (uint8_t *)middle_data;
212 planar_data[2] = (uint8_t *)middle_data + plane_size * 2;
213 }
214 sws_scale(sws_ctx, (const uint8_t * const *)frame->data,
215 frame->linesize, 0, frame->height, planar_data,
216 (const int [4]){frame->width * sizeof(uint8_t),
217 frame->width * sizeof(uint8_t),
218 frame->width * sizeof(uint8_t), 0});
219 sws_freeContext(sws_ctx);
220 }
115 sws_ctx = sws_getContext(frame->width * 3,221 sws_ctx = sws_getContext(frame->width * 3,
116 frame->height,222 frame->height,
117 AV_PIX_FMT_GRAY8,223 AV_PIX_FMT_GRAY8,
@@ -124,10 +230,11 @@ int ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx) · 6 unmodified lines
124 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",230 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
125 av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width * 3, frame->height,231 av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width * 3, frame->height,
126 av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32),frame->width * 3, frame->height);232 av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32),frame->width * 3, frame->height);
127 return AVERROR(EINVAL);233 ret = AVERROR(EINVAL);
234 goto err;
128 }235 }
129 sws_scale(sws_ctx, (const uint8_t **)frame->data,236 sws_scale(sws_ctx, (const uint8_t **)src_data,
130 frame->linesize, 0, frame->height,237 linesize, 0, frame->height,
131 (uint8_t * const [4]){input->data, 0, 0, 0},238 (uint8_t * const [4]){input->data, 0, 0, 0},
132 (const int [4]){frame->width * 3 * sizeof(float), 0, 0, 0});239 (const int [4]){frame->width * 3 * sizeof(float), 0, 0, 0});
133 sws_freeContext(sws_ctx);240 sws_freeContext(sws_ctx);
@@ -156,7 +263,8 @@ int ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx) · 22 unmodified lines
156 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",263 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
157 av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width, frame->height,264 av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width, frame->height,
158 av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32),frame->width, frame->height);265 av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32),frame->width, frame->height);
159 return AVERROR(EINVAL);266 ret = AVERROR(EINVAL);
267 goto err;
160 }268 }
161 sws_scale(sws_ctx, (const uint8_t **)frame->data,269 sws_scale(sws_ctx, (const uint8_t **)frame->data,
162 frame->linesize, 0, frame->height,270 frame->linesize, 0, frame->height,
@@ -166,10 +274,12 @@ int ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx) · 3 unmodified lines
166 break;274 break;
167 default:275 default:
168 avpriv_report_missing_feature(log_ctx, "%s", av_get_pix_fmt_name(frame->format));276 avpriv_report_missing_feature(log_ctx, "%s", av_get_pix_fmt_name(frame->format));
169 return AVERROR(ENOSYS);277 ret = AVERROR(ENOSYS);
278 goto err;
170 }279 }
171 280err:
172 return 0;281 av_free(middle_data);
282 return ret;
173}283}
174 284
175static enum AVPixelFormat get_pixel_format(DNNData *data)285static enum AVPixelFormat get_pixel_format(DNNData *data)
@@ -205,6 +315,11 @@ int ff_frame_to_dnn_classify(AVFrame *frame, DNNData *input, uint32_t bbox_index · 29 unmodified lines
205 AVFrameSideData *sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DETECTION_BBOXES);315 AVFrameSideData *sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DETECTION_BBOXES);
206 av_assert0(sd);316 av_assert0(sd);
207 317
318 if (input->layout == DL_NCHW) {
319 av_log(log_ctx, AV_LOG_ERROR, "dnn_classify input data doesn't support layout: NCHW\n");
320 return AVERROR(ENOSYS);
321 }
322
208 header = (const AVDetectionBBoxHeader *)sd->data;323 header = (const AVDetectionBBoxHeader *)sd->data;
209 bbox = av_get_detection_bbox(header, bbox_index);324 bbox = av_get_detection_bbox(header, bbox_index);
210 325
@@ -257,6 +372,12 @@ int ff_frame_to_dnn_detect(AVFrame *frame, DNNData *input, void *log_ctx) · 46 unmodified lines
257 int linesizes[4];372 int linesizes[4];
258 int ret = 0;373 int ret = 0;
259 enum AVPixelFormat fmt = get_pixel_format(input);374 enum AVPixelFormat fmt = get_pixel_format(input);
375
376 if (input->layout == DL_NCHW) {
377 av_log(log_ctx, AV_LOG_ERROR, "dnn_detect input data doesn't support layout: NCHW\n");
378 return AVERROR(ENOSYS);
379 }
380
260 sws_ctx = sws_getContext(frame->width, frame->height, frame->format,381 sws_ctx = sws_getContext(frame->width, frame->height, frame->format,
261 input->width, input->height, fmt,382 input->width, input->height, fmt,
262 SWS_FAST_BILINEAR, NULL, NULL, NULL);383 SWS_FAST_BILINEAR, NULL, NULL, NULL);
libavfilter/dnn_interface.h+7−0
@@ -56,12 +56,19 @@ typedef enum { · 55 unmodified lines
56 DFT_ANALYTICS_CLASSIFY, // classify for each bounding box56 DFT_ANALYTICS_CLASSIFY, // classify for each bounding box
57}DNNFunctionType;57}DNNFunctionType;
58 58
59typedef enum {
60 DL_NONE,
61 DL_NCHW,
62 DL_NHWC,
63} DNNLayout;
64
59typedef struct DNNData{65typedef struct DNNData{
60 void *data;66 void *data;
61 int width, height, channels;67 int width, height, channels;
62 // dt and order together decide the color format68 // dt and order together decide the color format
63 DNNDataType dt;69 DNNDataType dt;
64 DNNColorOrder order;70 DNNColorOrder order;
71 DNNLayout layout;
65} DNNData;72} DNNData;
66 73
67typedef struct DNNExecBaseParams {74typedef struct DNNExecBaseParams {

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