Page 1 of 1
Saving the classifier
Posted: Tue May 28, 2024 8:13 am
by sjurado
Hello,
I am having issues saving the classifier in a .yaml format. Could you please provide the code you use for this part :
"When using Python, you can also save a trained OpenCV random forest model and use it in the CloudCompare plugin (using the save function of cv2.ml.RTrees)."
Thanks !
Re: Saving the classifier
Posted: Thu May 30, 2024 11:20 pm
by paul.leroy
Could you please precise what your are trying to do and at which step it fails and how?
Re: Saving the classifier
Posted: Mon Jun 03, 2024 8:03 am
by sjurado
I train my classifier calling the following function : cc_3dmasc.get_acc_expe()
This function returns a RandomForestClassifier.
I would like to save it using the save function of cv2.ml.RTrees as advised in your documentation in order to use the classifier to classify other data.
I couldn't find online any example of how to save a classifier using the cv2.ml.RTrees save function
I have tried :
which failed wih the following error :
Code: Select all
AttributeError: 'RandomForestClassifier' object has no attribute 'save'
Thanks
Re: Saving the classifier
Posted: Mon Jun 03, 2024 1:28 pm
by paul.leroy
You should try with model=1 instead of the default value (model=0). With model=0, scikit-learn is used, with model=1, OpenCV is used. It is written in the docstring of get_acc_expe.
Re: Saving the classifier
Posted: Tue Jun 04, 2024 1:27 pm
by sjurado
Thanks ! Indeed it works with the OpenCv Model.
Although I have noticed I have significantly better results using the scikit-learn classifier.
Is there a way to save the scikit-learn classifier to the required yaml format ? Can we only use the OpenCV classifier to classifiy pointclouds in CloudCompare ?
Thanks for your help
Re: Saving the classifier
Posted: Thu Jun 13, 2024 8:53 pm
by paul.leroy
Yes, only OpenCV is accepted by CloudCompare. Anyway, the training is parallelized in Python, and not in CloudCompare. This is due to the C++ version of the random forest of OpenCV.
CloudCompare is very powerful to compute features, this is well parallelized and neighbourhood lookup is nicely coded, and it is also well adapted to work on a classifier dynamically. But in terms of computation, you can stay in Python to predict your labels if you already have your features and a classifier.