Message ID | 1597369770-7504-1-git-send-email-yejun.guo@intel.com |
---|---|
State | Superseded |
Headers | show |
Series | [FFmpeg-devel,V2] dnn_backend_openvino.c: parse options in openvino backend | expand |
Context | Check | Description |
---|---|---|
andriy/default | pending | |
andriy/make | success | Make finished |
andriy/make_fate | success | Make fate finished |
> -----Original Message----- > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Guo, > Yejun > Sent: Friday, August 14, 2020 9:50 AM > To: ffmpeg-devel@ffmpeg.org > Subject: [FFmpeg-devel] [PATCH V2] dnn_backend_openvino.c: parse options > in openvino backend > > Signed-off-by: Guo, Yejun <yejun.guo@intel.com> > --- > libavfilter/dnn/dnn_backend_openvino.c | 37 > +++++++++++++++++++++++++++++++++- > 1 file changed, 36 insertions(+), 1 deletion(-) > > diff --git a/libavfilter/dnn/dnn_backend_openvino.c > b/libavfilter/dnn/dnn_backend_openvino.c > index d343bf2..478e151 100644 > --- a/libavfilter/dnn/dnn_backend_openvino.c > +++ b/libavfilter/dnn/dnn_backend_openvino.c > @@ -26,8 +26,14 @@ > #include "dnn_backend_openvino.h" > #include "libavformat/avio.h" > #include "libavutil/avassert.h" > +#include "libavutil/avstring.h" > #include <c_api/ie_c_api.h> > > +typedef struct OVOptions{ > + uint32_t batch_size; > + uint32_t req_num; > +} OVOptions; > + > typedef struct OVModel{ > ie_core_t *core; > ie_network_t *network; > @@ -36,6 +42,7 @@ typedef struct OVModel{ > ie_blob_t *input_blob; > ie_blob_t **output_blobs; > uint32_t nb_output; > + OVOptions options; > } OVModel; > > static DNNDataType precision_to_datatype(precision_e precision) @@ -50,6 > +57,32 @@ static DNNDataType precision_to_datatype(precision_e precision) > } > } > > +static int parse_options_ov(OVOptions *to, const char *from) { > + AVDictionary *dict = NULL; > + AVDictionaryEntry *opt = NULL; > + int err = av_dict_parse_string(&dict, from, "=", "&", 0); > + if (err < 0) { > + av_dict_free(&dict); This may not needed. > + return err; > + } > + > + opt = av_dict_get(dict, "nireq", opt, AV_DICT_MATCH_CASE); > + if (opt != NULL) > + to->req_num = atoi(opt->value); > + else > + to->req_num = 1; > + > + opt = av_dict_get(dict, "batch", opt, AV_DICT_MATCH_CASE); > + if (opt != NULL) > + to->batch_size = atoi(opt->value); > + else > + to->batch_size = 1; How about a function like this. Int dict_get_int(const AVDictionary *m, const char *key, int default_value) > + > + av_dict_free(&dict); > + return 0; > +} > + > static DNNReturnType get_input_ov(void *model, DNNData *input, const char > *input_name) { > OVModel *ov_model = (OVModel *)model; @@ -171,6 +204,9 @@ > DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char > *options) > if (!ov_model) > goto err; > > + model->options = options; > + parse_options_ov(&ov_model->options, model->options); Check error? > + > status = ie_core_create("", &ov_model->core); > if (status != OK) > goto err; > @@ -186,7 +222,6 @@ DNNModel *ff_dnn_load_model_ov(const char > *model_filename, const char *options) > model->model = (void *)ov_model; > model->set_input_output = &set_input_output_ov; > model->get_input = &get_input_ov; > - model->options = options; > > return model; > > -- > 2.7.4 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org > with subject "unsubscribe".
Am 14. August 2020 14:07:23 MESZ schrieb "Xu, Guangxin" <guangxin.xu@intel.com>: > > >> -----Original Message----- >> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of >Guo, >> Yejun >> Sent: Friday, August 14, 2020 9:50 AM >> To: ffmpeg-devel@ffmpeg.org >> Subject: [FFmpeg-devel] [PATCH V2] dnn_backend_openvino.c: parse >options >> in openvino backend >> >> Signed-off-by: Guo, Yejun <yejun.guo@intel.com> >> --- >> libavfilter/dnn/dnn_backend_openvino.c | 37 >> +++++++++++++++++++++++++++++++++- >> 1 file changed, 36 insertions(+), 1 deletion(-) >> >> diff --git a/libavfilter/dnn/dnn_backend_openvino.c >> b/libavfilter/dnn/dnn_backend_openvino.c >> index d343bf2..478e151 100644 >> --- a/libavfilter/dnn/dnn_backend_openvino.c >> +++ b/libavfilter/dnn/dnn_backend_openvino.c >> @@ -26,8 +26,14 @@ >> #include "dnn_backend_openvino.h" >> #include "libavformat/avio.h" >> #include "libavutil/avassert.h" >> +#include "libavutil/avstring.h" >> #include <c_api/ie_c_api.h> >> >> +typedef struct OVOptions{ >> + uint32_t batch_size; >> + uint32_t req_num; >> +} OVOptions; >> + >> typedef struct OVModel{ >> ie_core_t *core; >> ie_network_t *network; >> @@ -36,6 +42,7 @@ typedef struct OVModel{ >> ie_blob_t *input_blob; >> ie_blob_t **output_blobs; >> uint32_t nb_output; >> + OVOptions options; >> } OVModel; >> >> static DNNDataType precision_to_datatype(precision_e precision) @@ >-50,6 >> +57,32 @@ static DNNDataType precision_to_datatype(precision_e >precision) >> } >> } >> >> +static int parse_options_ov(OVOptions *to, const char *from) { >> + AVDictionary *dict = NULL; >> + AVDictionaryEntry *opt = NULL; >> + int err = av_dict_parse_string(&dict, from, "=", "&", 0); >> + if (err < 0) { >> + av_dict_free(&dict); >This may not needed. > >> + return err; >> + } >> + >> + opt = av_dict_get(dict, "nireq", opt, AV_DICT_MATCH_CASE); >> + if (opt != NULL) >> + to->req_num = atoi(opt->value); >> + else >> + to->req_num = 1; >> + >> + opt = av_dict_get(dict, "batch", opt, AV_DICT_MATCH_CASE); >> + if (opt != NULL) >> + to->batch_size = atoi(opt->value); >> + else >> + to->batch_size = 1; >How about a function like this. >Int dict_get_int(const AVDictionary *m, const char *key, int >default_value) If we parse the options ourselves (as opposed to pass a string into an external library function) we should look into using AVOptions. Else we will slowly but for sure create a usability nightmare. Can't look into the code right now, but I think it should be possible to use AVOptions somehow. Other opinions in this? [...] Alexander
> -----Original Message----- > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Xu, > Guangxin > Sent: 2020年8月14日 20:07 > To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> > Subject: Re: [FFmpeg-devel] [PATCH V2] dnn_backend_openvino.c: parse options > in openvino backend > > > > > -----Original Message----- > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Guo, > > Yejun > > Sent: Friday, August 14, 2020 9:50 AM > > To: ffmpeg-devel@ffmpeg.org > > Subject: [FFmpeg-devel] [PATCH V2] dnn_backend_openvino.c: parse > > options in openvino backend > > > > Signed-off-by: Guo, Yejun <yejun.guo@intel.com> > > --- > > libavfilter/dnn/dnn_backend_openvino.c | 37 > > +++++++++++++++++++++++++++++++++- > > 1 file changed, 36 insertions(+), 1 deletion(-) > > > > diff --git a/libavfilter/dnn/dnn_backend_openvino.c > > b/libavfilter/dnn/dnn_backend_openvino.c > > index d343bf2..478e151 100644 > > --- a/libavfilter/dnn/dnn_backend_openvino.c > > +++ b/libavfilter/dnn/dnn_backend_openvino.c > > @@ -26,8 +26,14 @@ > > #include "dnn_backend_openvino.h" > > #include "libavformat/avio.h" > > #include "libavutil/avassert.h" > > +#include "libavutil/avstring.h" > > #include <c_api/ie_c_api.h> > > > > +typedef struct OVOptions{ > > + uint32_t batch_size; > > + uint32_t req_num; > > +} OVOptions; > > + > > typedef struct OVModel{ > > ie_core_t *core; > > ie_network_t *network; > > @@ -36,6 +42,7 @@ typedef struct OVModel{ > > ie_blob_t *input_blob; > > ie_blob_t **output_blobs; > > uint32_t nb_output; > > + OVOptions options; > > } OVModel; > > > > static DNNDataType precision_to_datatype(precision_e precision) @@ > > -50,6 > > +57,32 @@ static DNNDataType precision_to_datatype(precision_e > > +precision) > > } > > } > > > > +static int parse_options_ov(OVOptions *to, const char *from) { > > + AVDictionary *dict = NULL; > > + AVDictionaryEntry *opt = NULL; > > + int err = av_dict_parse_string(&dict, from, "=", "&", 0); > > + if (err < 0) { > > + av_dict_free(&dict); > This may not needed. any more detail? thanks. I think it is better to always free it. > > > + return err; > > + } > > + > > + opt = av_dict_get(dict, "nireq", opt, AV_DICT_MATCH_CASE); > > + if (opt != NULL) > > + to->req_num = atoi(opt->value); > > + else > > + to->req_num = 1; > > + > > + opt = av_dict_get(dict, "batch", opt, AV_DICT_MATCH_CASE); > > + if (opt != NULL) > > + to->batch_size = atoi(opt->value); > > + else > > + to->batch_size = 1; > How about a function like this. > Int dict_get_int(const AVDictionary *m, const char *key, int default_value) good point, we can add such function for dict. > > > + > > + av_dict_free(&dict); > > + return 0; > > +} > > + > > static DNNReturnType get_input_ov(void *model, DNNData *input, const > > char > > *input_name) { > > OVModel *ov_model = (OVModel *)model; @@ -171,6 +204,9 @@ > > DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char > > *options) > > if (!ov_model) > > goto err; > > > > + model->options = options; > > + parse_options_ov(&ov_model->options, model->options); > Check error? yes, error checking is needed, anyway, I'll first try method with AVOption as Alexander mentioned. > > > + > > status = ie_core_create("", &ov_model->core); > > if (status != OK) > > goto err; > > @@ -186,7 +222,6 @@ DNNModel *ff_dnn_load_model_ov(const char > > *model_filename, const char *options) > > model->model = (void *)ov_model; > > model->set_input_output = &set_input_output_ov; > > model->get_input = &get_input_ov; > > - model->options = options; > > > > return model; > > > > -- > > 2.7.4 > > > > _______________________________________________ > > ffmpeg-devel mailing list > > ffmpeg-devel@ffmpeg.org > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > > > To unsubscribe, visit link above, or email > > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with > subject "unsubscribe".
> -----Original Message----- > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of > Alexander Strasser > Sent: 2020年8月14日 20:47 > To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> > Subject: Re: [FFmpeg-devel] [PATCH V2] dnn_backend_openvino.c: parse options > in openvino backend > > > > Am 14. August 2020 14:07:23 MESZ schrieb "Xu, Guangxin" > <guangxin.xu@intel.com>: > > > > > >> -----Original Message----- > >> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of > >Guo, > >> Yejun > >> Sent: Friday, August 14, 2020 9:50 AM > >> To: ffmpeg-devel@ffmpeg.org > >> Subject: [FFmpeg-devel] [PATCH V2] dnn_backend_openvino.c: parse > >options > >> in openvino backend > >> > >> Signed-off-by: Guo, Yejun <yejun.guo@intel.com> > >> --- > >> libavfilter/dnn/dnn_backend_openvino.c | 37 > >> +++++++++++++++++++++++++++++++++- > >> 1 file changed, 36 insertions(+), 1 deletion(-) > >> > >> diff --git a/libavfilter/dnn/dnn_backend_openvino.c > >> b/libavfilter/dnn/dnn_backend_openvino.c > >> index d343bf2..478e151 100644 > >> --- a/libavfilter/dnn/dnn_backend_openvino.c > >> +++ b/libavfilter/dnn/dnn_backend_openvino.c > >> @@ -26,8 +26,14 @@ > >> #include "dnn_backend_openvino.h" > >> #include "libavformat/avio.h" > >> #include "libavutil/avassert.h" > >> +#include "libavutil/avstring.h" > >> #include <c_api/ie_c_api.h> > >> > >> +typedef struct OVOptions{ > >> + uint32_t batch_size; > >> + uint32_t req_num; > >> +} OVOptions; > >> + > >> typedef struct OVModel{ > >> ie_core_t *core; > >> ie_network_t *network; > >> @@ -36,6 +42,7 @@ typedef struct OVModel{ > >> ie_blob_t *input_blob; > >> ie_blob_t **output_blobs; > >> uint32_t nb_output; > >> + OVOptions options; > >> } OVModel; > >> > >> static DNNDataType precision_to_datatype(precision_e precision) @@ > >-50,6 > >> +57,32 @@ static DNNDataType precision_to_datatype(precision_e > >precision) > >> } > >> } > >> > >> +static int parse_options_ov(OVOptions *to, const char *from) { > >> + AVDictionary *dict = NULL; > >> + AVDictionaryEntry *opt = NULL; > >> + int err = av_dict_parse_string(&dict, from, "=", "&", 0); > >> + if (err < 0) { > >> + av_dict_free(&dict); > >This may not needed. > > > >> + return err; > >> + } > >> + > >> + opt = av_dict_get(dict, "nireq", opt, AV_DICT_MATCH_CASE); > >> + if (opt != NULL) > >> + to->req_num = atoi(opt->value); > >> + else > >> + to->req_num = 1; > >> + > >> + opt = av_dict_get(dict, "batch", opt, AV_DICT_MATCH_CASE); > >> + if (opt != NULL) > >> + to->batch_size = atoi(opt->value); > >> + else > >> + to->batch_size = 1; > >How about a function like this. > >Int dict_get_int(const AVDictionary *m, const char *key, int > >default_value) > > If we parse the options ourselves (as opposed to pass a string into an external > library function) we should look into using AVOptions. Else we will slowly but for > sure create a usability nightmare. > > Can't look into the code right now, but I think it should be possible to use > AVOptions somehow. yes, it's possible to use AVOptions with function int av_opt_set_dict(void *obj, AVDictionary **options) if 'obj' contains ' AVClass *class;' which has 'AVOption *option'. will change to this method in v3. > > Other opinions in this? > > > [...] > > Alexander > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with > subject "unsubscribe".
diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c index d343bf2..478e151 100644 --- a/libavfilter/dnn/dnn_backend_openvino.c +++ b/libavfilter/dnn/dnn_backend_openvino.c @@ -26,8 +26,14 @@ #include "dnn_backend_openvino.h" #include "libavformat/avio.h" #include "libavutil/avassert.h" +#include "libavutil/avstring.h" #include <c_api/ie_c_api.h> +typedef struct OVOptions{ + uint32_t batch_size; + uint32_t req_num; +} OVOptions; + typedef struct OVModel{ ie_core_t *core; ie_network_t *network; @@ -36,6 +42,7 @@ typedef struct OVModel{ ie_blob_t *input_blob; ie_blob_t **output_blobs; uint32_t nb_output; + OVOptions options; } OVModel; static DNNDataType precision_to_datatype(precision_e precision) @@ -50,6 +57,32 @@ static DNNDataType precision_to_datatype(precision_e precision) } } +static int parse_options_ov(OVOptions *to, const char *from) +{ + AVDictionary *dict = NULL; + AVDictionaryEntry *opt = NULL; + int err = av_dict_parse_string(&dict, from, "=", "&", 0); + if (err < 0) { + av_dict_free(&dict); + return err; + } + + opt = av_dict_get(dict, "nireq", opt, AV_DICT_MATCH_CASE); + if (opt != NULL) + to->req_num = atoi(opt->value); + else + to->req_num = 1; + + opt = av_dict_get(dict, "batch", opt, AV_DICT_MATCH_CASE); + if (opt != NULL) + to->batch_size = atoi(opt->value); + else + to->batch_size = 1; + + av_dict_free(&dict); + return 0; +} + static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input_name) { OVModel *ov_model = (OVModel *)model; @@ -171,6 +204,9 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options) if (!ov_model) goto err; + model->options = options; + parse_options_ov(&ov_model->options, model->options); + status = ie_core_create("", &ov_model->core); if (status != OK) goto err; @@ -186,7 +222,6 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options) model->model = (void *)ov_model; model->set_input_output = &set_input_output_ov; model->get_input = &get_input_ov; - model->options = options; return model;
Signed-off-by: Guo, Yejun <yejun.guo@intel.com> --- libavfilter/dnn/dnn_backend_openvino.c | 37 +++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-)