Save model/Ndarray in C++
I'm training a model in C++ .But I can't find how to save my model/Ndarray to a binary file, so I can load them if I want to use the trained model.
Now I know how to save the Ndarray,but still don't know how to save a trained model.
Use https://github.com/dmlc/mxnet/blob/master/src/ndarray/ndarray.cc#L573 And save it like
save_dict = {('arg:%s' % k) : v for k, v in arg_params.items()}
save_dict.update({('aux:%s' % k) : v for k, v in aux_params.items()})
param_name = '%s-%04d.params' % (prefix, epoch)
nd.save(param_name, save_dict)
as in model.py:save_checkpoint
@piiswrong Thanks,But when i use dmlc::Stream::Create,it will report unresolved external symbol,I think this is same with #967 ,So I just convert the NDarray to vector and save the vector to the file. And can you tell me how to save the whole trained model,I think this will be very convenient.
The whole trained model is just a dictionary of array name to ndarrays. arguments starts with 'arg:' and auxiliary states starts with 'aux:' We can make a c_api for this. You are welcome to do it if you are interested.
@piiswrong I see,Thanks for your help.I'm very glad to help c_api ,but I don't know how to write this and i was very busy with my course,fell very sorry about this.
Hi @zhubuntu @piiswrong I am facing issue with dmlc::Stream::Create
Below is what i am getting on running below code in predictor.cc class
const char* fPath = env->GetStringUTFChars(filePath, 0); const char* fFlag = env->GetStringUTFChars(fileFlag, 0); dmlc::Stream *fStream = dmlc::Stream::Create(fPath, fFlag); Issue generated is as below
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN4dmlc6Stream6CreateEPKcS2_b" referenced by "/data/app/com.happen.it.make.whatsthis-2/lib/arm/libmxnet_predict.so"...
at java.lang.Runtime.loadLibrary(Runtime.java:372)
at java.lang.System.loadLibrary(System.java:1076)
at org.dmlc.mxnet.Predictor.
Could you please help. Thanks.