patrikhuber / superviseddescent

C++11 implementation of the supervised descent optimisation method
http://patrikhuber.github.io/superviseddescent/
Apache License 2.0
402 stars 188 forks source link

save trained model with non-C++11 syntax #42

Closed ardeal closed 7 years ago

ardeal commented 7 years ago

Hi patrikhuber,

I noticed that you used C++11 lib cereal to serialize the trained model and save it to binary file. you use the following code to save the model: void save_detection_model(detection_model model, std::string filename) { std::ofstream file(filename, std::ios::binary); cereal::BinaryOutputArchive output_archive(file); output_archive(model); };

My question is: do you have any other substitute solution that doesn't use C++11 syntax about how to save/load the model to/from files? can you share non-C++11 code about how to save/load the model?

patrikhuber commented 7 years ago

Hi,

You can change it to boost::serialization if you want (the syntax is nearly identical to cereal), or whatever manual load/save routine you'd like.

ardeal commented 7 years ago

Hi Patrikhuber,

I don't like boost as well. I want to manually load/save it, but I don't know what should be loaded/saved. Do you have any example code or detailed solution?

patrikhuber commented 7 years ago

Just look at the code of the detection_model class and its serialize() function to see which members are saved.

ardeal commented 7 years ago

Yes, I read the code today.

using model_type = superviseddescent::SupervisedDescentOptimiser<superviseddescent::LinearRegressor<superviseddescent::VerbosePartialPivLUSolver>, InterEyeDistanceNormalisation>;
template<class Archive>
void serialize(Archive& archive)
{
    archive(optimised_model, mean, landmark_ids, hog_params, right_eye_ids, left_eye_ids);
};

My problem is optimised_model is a template class. what will be saved in this class?

patrikhuber commented 7 years ago

Well you posted it by yourself, using model_type = ....

ardeal commented 7 years ago

using model_type = superviseddescent::SupervisedDescentOptimiser<superviseddescent::LinearRegressor, InterEyeDistanceNormalisation>; do you mean that all the data in all the serialize funcitons in all the upper template class should be saved/loaded?

patrikhuber commented 7 years ago

Yes. That's in fact the power of a serialisation library. But in essence it's mainly just a bunch of regressor matrices and parameters.

ardeal commented 7 years ago

I got it! Thanks!

One more question to confirm my understanding:

all the data in all the serialize funcitons in all the upper template class should be saved/loaded. No other data needs to be saved/loaded, right? I am afraid I might miss something, and I migth not able to run the test funciton corrrectly.

patrikhuber commented 7 years ago

I think that should be correct yes - everything in all required serialize() functions.

ardeal commented 7 years ago

Thanks Patrikhuber!