[FFmpeg-devel] [PATCH 3/3] dnn: export operand info in python script and load in c code
Guo, Yejun
yejun.guo at intel.com
Thu Aug 29 08:41:53 EEST 2019
> -----Original Message-----
> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces at ffmpeg.org] On Behalf Of
> Pedro Arthur
> Sent: Tuesday, August 27, 2019 10:46 PM
> To: FFmpeg development discussions and patches <ffmpeg-devel at ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 3/3] dnn: export operand info in python
> script and load in c code
>
> hi,
>
> Em ter, 20 de ago de 2019 às 05:54, Guo, Yejun <yejun.guo at intel.com>
> escreveu:
> >
> > Signed-off-by: Guo, Yejun <yejun.guo at intel.com>
> > ---
> > libavfilter/dnn/dnn_backend_native.c | 49 +++++++++++---
> > libavfilter/dnn/dnn_backend_native.h | 2 +-
> > libavfilter/dnn_interface.h | 2 +-
> > tools/python/convert_from_tensorflow.py | 111
> +++++++++++++++++++++++++++++---
> > 4 files changed, 142 insertions(+), 22 deletions(-)
> >
> > diff --git a/libavfilter/dnn/dnn_backend_native.c
> b/libavfilter/dnn/dnn_backend_native.c
> > index 0ba4e44..eeae711 100644
> > --- a/libavfilter/dnn/dnn_backend_native.c
> > +++ b/libavfilter/dnn/dnn_backend_native.c
> > @@ -72,7 +72,6 @@ DNNModel *ff_dnn_load_model_native(const char
> *model_filename)
> > ConvolutionalParams *conv_params;
> > DepthToSpaceParams *depth_to_space_params;
> > LayerPadParams *pad_params;
> > - int32_t operand_index = 0;
> >
> > model = av_malloc(sizeof(DNNModel));
> > if (!model){
> > @@ -93,9 +92,10 @@ DNNModel *ff_dnn_load_model_native(const char
> *model_filename)
> > }
> > model->model = (void *)network;
> >
> > - avio_seek(model_file_context, file_size - 4, SEEK_SET);
> > + avio_seek(model_file_context, file_size - 8, SEEK_SET);
> > network->layers_num = (int32_t)avio_rl32(model_file_context);
> > - dnn_size = 4;
> > + network->operands_num = (int32_t)avio_rl32(model_file_context);
> > + dnn_size = 8;
> > avio_seek(model_file_context, 0, SEEK_SET);
> >
> I think it is worth adding some means to assert the input file is
> indeed a dnn file, the code as is may alloc an undefined amout of
> memory if the file passed is malformed or corrupted.
> Maybe adding a magic number + the file size (or something else) at the
> beginning of the file and early skip parsing it if it does not match?
> however it may require two passes to generate the file which goes
> against your previous patch.
>
> Otherwise I can push it as is, as this behavior was already there
> before the patch.
good point, how about add "FFMPEGDNNNATIVE" + version_number at the beginning of the file,
or we can use another magic number instead of "FFMPEGDNNNATIVE". Once we change the model file
format, the version_number should be increased. I can send a new patch after this patch set is pushed.
I think it doesn't matter to put the info at the beginning or at the end of the file, avio_seek
does not alloc memory. And the layers_num and operands_num take similar effect of file_size.
>
> > network->layers = av_mallocz(network->layers_num * sizeof(Layer));
> > @@ -105,11 +105,6 @@ DNNModel *ff_dnn_load_model_native(const char
> *model_filename)
> > return NULL;
> > }
More information about the ffmpeg-devel
mailing list