thundersvm
thundersvm copied to clipboard
Avoid freeing pointer after copy [Python]
Hello everyone,
I am actually using thundersvm with Python through Julia. During training, I would like to save the best C-SVC model encountered.
Let's say that I find such a best
model during training, I would then like to copy this python object along with the pointer on the C++ SVM object.
I am actually doing this for now :
py_model = thundersvm.SVC(params...)
.... training ....
best = thundersvm.SVC(py_model.get_params()...)
best.model = py_model.model # Keeping the c++ pointer from py_model
But If I fit again the py_model
object I would free the pointer on the c++ object since :
https://github.com/Xtra-Computing/thundersvm/blob/6e28da802e483fc741056a1768c825737c840cca/python/thundersvm/thundersvm.py#L96-L99
And consequently the pointer I have in best.model
.
Is there a way to avoid freeing this pointer if the original py_model
has been copied or safely copy this c++ pointer into a fitted clone of py_model
?
Thank you.
One way was to give None
to py_model.model
but I wont be able to use predict
on it again.
I could wrap copy options and handling cases in Julia or Python but maybe there is clean to do this with c++ or python copy procedures ?
Hi, @gdestouet,
There are two methods to save the best model during training.
-
If the model is fully trained on your training data, you can use save_to_file and load_from_file to save and load the model.
-
You can save the best configuration and train the model again.