[FFmpeg-devel] [PATCH V2] dnn_backend_openvino.c: parse options in openvino backend

Guo, Yejun yejun.guo at intel.com
Mon Aug 17 15:01:44 EEST 2020



> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces at ffmpeg.org> On Behalf Of Xu,
> Guangxin
> Sent: 2020年8月14日 20:07
> To: FFmpeg development discussions and patches <ffmpeg-devel at 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 at ffmpeg.org> On Behalf Of Guo,
> > Yejun
> > Sent: Friday, August 14, 2020 9:50 AM
> > To: ffmpeg-devel at ffmpeg.org
> > Subject: [FFmpeg-devel] [PATCH V2] dnn_backend_openvino.c: parse
> > options in openvino backend
> >
> > Signed-off-by: Guo, Yejun <yejun.guo at 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 at ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email ffmpeg-devel-request at ffmpeg.org with
> subject "unsubscribe".


More information about the ffmpeg-devel mailing list