> -----Original Message----- > From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of > Pedro Arthur > Sent: Tuesday, August 27, 2019 10:46 PM > To: FFmpeg development discussions and patches <ffmpeg-devel@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....@intel.com> > escreveu: > > > > Signed-off-by: Guo, Yejun <yejun....@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; > > } _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".