leovandriel / caffe2_cpp_tutorial

C++ transcripts of the Caffe2 Python tutorials and other C++ example code
BSD 2-Clause "Simplified" License
431 stars 94 forks source link

Saving model #60

Open edubois opened 6 years ago

edubois commented 6 years ago

Hi,

I am trying to use the write function of the ModelUtil, but I suspect it's not saving the weights of my neural net.

First question is: using your code, how do you save a net with its trained weights? Second question is: how to see if the weights are saved in the pb file?

Thanks

leovandriel commented 6 years ago

Hi, it's not that easy to inspect the pb file directly, but simply writing and reading it back in should give you the exact same weights. workspace.GetBlob("nameofparameter")).data<float>() should give you a vector with the float weights in that parameter. Make sure to save the full model, including init and predict net. I recently added ModelUtil.WriteBundle(..), which writes both to a single file.