Skip to content

Commit 6095372

Browse files
committed
avfilter/dnn: use batch_size in DnnContext instead of ov_option
batch_size in DnnContext is a common variable for all dnn backends
1 parent 2f20933 commit 6095372

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

libavfilter/dnn/dnn_backend_openvino.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ typedef struct OVRequestItem {
8484
#define OFFSET(x) offsetof(OVOptions, x)
8585
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM
8686
static const AVOption dnn_openvino_options[] = {
87-
{ "batch_size", "batch size per request", OFFSET(batch_size), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 1000, FLAGS},
8887
{ "input_resizable", "can input be resizable or not", OFFSET(input_resizable), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
8988
{ "layout", "input layout of model", OFFSET(layout), AV_OPT_TYPE_INT, { .i64 = DL_NONE}, DL_NONE, DL_NHWC, FLAGS, .unit = "layout" },
9089
{ "none", "none", 0, AV_OPT_TYPE_CONST, { .i64 = DL_NONE }, 0, 0, FLAGS, .unit = "layout"},
@@ -271,7 +270,7 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request)
271270
input.scale = 1;
272271
input.mean = 0;
273272

274-
for (int i = 0; i < ctx->ov_option.batch_size; ++i) {
273+
for (int i = 0; i < ctx->batch_size; ++i) {
275274
lltask = ff_queue_pop_front(ov_model->lltask_queue);
276275
if (!lltask) {
277276
break;
@@ -599,14 +598,14 @@ static int init_model_ov(OVModel *ov_model, const char *input_name, const char *
599598
if (fabsf(ctx->ov_option.scale) < 1e-6f)
600599
ctx->ov_option.scale = ov_model->model.func_type == DFT_PROCESS_FRAME ? 255 : 1;
601600
// batch size
602-
if (ctx->ov_option.batch_size <= 0) {
603-
ctx->ov_option.batch_size = 1;
601+
if (ctx->batch_size <= 0) {
602+
ctx->batch_size = 1;
604603
}
605604
#if HAVE_OPENVINO2
606-
if (ctx->ov_option.batch_size > 1) {
605+
if (ctx->batch_size > 1) {
607606
avpriv_report_missing_feature(ctx, "Do not support batch_size > 1 for now,"
608607
"change batch_size to 1.\n");
609-
ctx->ov_option.batch_size = 1;
608+
ctx->batch_size = 1;
610609
}
611610

612611
status = ov_preprocess_prepostprocessor_create(ov_model->ov_model, &ov_model->preprocess);
@@ -802,15 +801,15 @@ static int init_model_ov(OVModel *ov_model, const char *input_name, const char *
802801
ov_layout_free(NCHW_layout);
803802
ov_layout_free(NHWC_layout);
804803
#else
805-
if (ctx->ov_option.batch_size > 1) {
804+
if (ctx->batch_size > 1) {
806805
input_shapes_t input_shapes;
807806
status = ie_network_get_input_shapes(ov_model->network, &input_shapes);
808807
if (status != OK) {
809808
ret = DNN_GENERIC_ERROR;
810809
goto err;
811810
}
812811
for (int i = 0; i < input_shapes.shape_num; i++)
813-
input_shapes.shapes[i].shape.dims[0] = ctx->ov_option.batch_size;
812+
input_shapes.shapes[i].shape.dims[0] = ctx->batch_size;
814813
status = ie_network_reshape(ov_model->network, input_shapes);
815814
ie_network_input_shapes_free(&input_shapes);
816815
if (status != OK) {
@@ -923,7 +922,7 @@ static int init_model_ov(OVModel *ov_model, const char *input_name, const char *
923922
}
924923
#endif
925924

926-
item->lltasks = av_malloc_array(ctx->ov_option.batch_size, sizeof(*item->lltasks));
925+
item->lltasks = av_malloc_array(ctx->batch_size, sizeof(*item->lltasks));
927926
if (!item->lltasks) {
928927
ret = AVERROR(ENOMEM);
929928
goto err;
@@ -1517,7 +1516,7 @@ static int dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams *exec_p
15171516
}
15181517

15191518
if (ctx->async) {
1520-
while (ff_queue_size(ov_model->lltask_queue) >= ctx->ov_option.batch_size) {
1519+
while (ff_queue_size(ov_model->lltask_queue) >= ctx->batch_size) {
15211520
request = ff_safe_queue_pop_front(ov_model->request_queue);
15221521
if (!request) {
15231522
av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n");
@@ -1540,7 +1539,7 @@ static int dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams *exec_p
15401539
return AVERROR(ENOSYS);
15411540
}
15421541

1543-
if (ctx->ov_option.batch_size > 1) {
1542+
if (ctx->batch_size > 1) {
15441543
avpriv_report_missing_feature(ctx, "batch mode for sync execution");
15451544
return AVERROR(ENOSYS);
15461545
}

libavfilter/dnn_interface.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ typedef struct TFOptions{
127127
typedef struct OVOptions {
128128
const AVClass *clazz;
129129

130-
int batch_size;
131130
int input_resizable;
132131
DNNLayout layout;
133132
float scale;

0 commit comments

Comments
 (0)