serizba / cppflow

Run TensorFlow models in C++ without installation and without Bazel
https://serizba.github.io/cppflow/
MIT License
787 stars 179 forks source link

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

Open bmiftah opened 1 year ago

bmiftah commented 1 year ago

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 @