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 !
Saving the classifier
-
- Posts: 42
- Joined: Tue Dec 01, 2020 1:21 pm
Re: Saving the classifier
Could you please precise what your are trying to do and at which step it fails and how?
Re: Saving the classifier
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 :
Thanks
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 :
Code: Select all
cl.save('classifier_3dmasc.yaml')
Code: Select all
AttributeError: 'RandomForestClassifier' object has no attribute 'save'
-
- Posts: 42
- Joined: Tue Dec 01, 2020 1:21 pm
Re: Saving the classifier
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
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
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
-
- Posts: 42
- Joined: Tue Dec 01, 2020 1:21 pm
Re: Saving the classifier
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.
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.