cppflow icon indicating copy to clipboard operation
cppflow copied to clipboard

Loading frozen model throws terminate called after throwing an instance of 'std::bad_alloc'

Open bmiftah opened this issue 1 year ago • 0 comments

Hi , I saved a trained model and frozen it . The origianl model(unfrozen one) can load with no issue and make inference. But the frozen model throw an error saying " terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc I can see it has something to do with memory. When I was loading the original model , there was no issue at all. I faced this only after trying the frozen model. The two model are nearly same in size but there could be difference in structure of the graph

Here is how I load my frozen model : cppflow::model model("Froozen_model_dir", cppflow::model::TYPE::FROZEN_GRAPH);

and here is how I call inference on it with sampple input output_tensor = model(input_1);

and I got this :

terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted (core dumped)

I try debugging to point our where exactly this issue comes from and here is where the debugger point to : (The bold part is where the issue seems to arise - )
#7 0x000000000040ff12 in std::make_unique<char []> (__num=9223372036854775807) at /usr/include/c++/7/bits/unique_ptr.h:827 #8 0x000000000040cbcc in cppflow::model::readGraph (this=0x7fffffffdcd0, filename="Froozen_model") at /home/nihao/cppflow/cppflow/include/cppflow/model.h:275

#8 0x000000000040cbcc in cppflow::model::readGraph (this=0x7fffffffdcd0, filename="Froozen_model") at /home/nihao/cppflow/cppflow/include/cppflow/model.h:275 #9 0x000000000040b9f7 in cppflow::model::model (this=0x7fffffffdcd0, filename="Froozen_model", type=cppflow::model::FROZEN_GRAPH) at /home/nihao/cppflow/cppflow/include/cppflow/model.h:129 The specific culprit of seem to be pointer related issue -- > #7 above , but I can't figure out what exactly went wrong .. here is snipt of the trace from the debugger : - image

I freez my model for better performance , specially when loading the model. I got stucked here and any tip , help is greatly appreciated and I thank in advance

@serizba @

bmiftah avatar Mar 01 '23 03:03 bmiftah