Classification SVM unable to end


Context

Explain briefly what you are trying to do
Hello! I am attempting to perform an SVM classification on a high-resolution raster using Bash commands in Python (though I am experiencing the same issue with the OTB interface application). While I am able to achieve good results with RF classification, the LibSVM classification is stuck at 20%, and I do not receive any error messages or have any ideas on what the problem might be.

--------------------------Code libsvm_NotWorking --------------------
if Traitement == “SVM” or Traitement == “BOTH” :
TrainImagesClassifier = “otbcli_TrainImagesClassifier”
+" -io.il “+input_image
+” -io.vd “+learn_vector
+” -io.out “+output_folder+”\model_SVM.txt"
+" -io.imstat “+output_folder+”\input_images_stats.xml "
+" -sample.vfn “+‘“Class”’
+” -sample.mt “+“10”
+” -ram “+Ram_Value
+” -classifier “+‘“libsvm”’
+” -classifier.libsvm.k “+“linear”
+” -classifier.libsvm.m “+“csvc”
+” -classifier.libsvm.opt “+“true”
+” exit /b 1"

!{TrainImagesClassifier}

---------------------------Code RF_Working------------------------------------
if Traitement == “RF” or Traitement == “BOTH” :
TrainImagesClassifier = “otbcli_TrainImagesClassifier”
+" -io.il “+input_image
+” -io.vd “+learn_vector
+” -io.out “+output_folder+”\model_RF.txt"
+" -io.imstat “+output_folder+”\input_images_stats.xml "
+" -sample.vfn “+‘“Class”’
+” -sample.mt int “+”-1"
+" -classifier.rf.nbtrees “+“1000”
+” -ram “+Ram_Value
+” -classifier “+‘“rf”’
+” exit /b 1"

!{TrainImagesClassifier}

I believe that there is an error in my code, but I am unable to locate it, which is why I am posting this message. Thank you!

Configuration setup

My system: Windows10
Version of the OTB: 8.0
Installation with:: the binaries
QGIS version: 3.22
Python version: 3.8?

Dear @Namhc,

I don’t see why the SVM is stuck at 20%… SMV is supposed to always converge… But it can be very slow on big datasets.

For SVM, you set the parameter sample.mt to 10, it seems small for a training dataset. But I don’t think it is the problem. Did you try with classifier.libsvm.opt set to “false”?

For RF, you should remove the “int” between the parameter sample.mt and its value “-1”.

What is the size of your input image and learning vector ? What is the value of Ram_Value ?
Out of curiosity, why don’t you use the python API to call the OTB application?

Regards.
Julien :slight_smile:

1 Like

Dear @julienosman,

Thank you for your message. I will try making the changes you suggested and let you know if it worked or not. My input image size is a raster with a resolution of 25cm, but with a small coverage area of around 1Ha (for example the RF classification is done in 15/20 min).

Regarding your question about using the Python API, I have tried it yet but i’m unable to make it working correctly, i’v do all the Path correctly (obviously not because it’s not working ahah) but i’v a DLL error when i try to import otbapplication, so i used the B plan :slight_smile:

Thank you for your help and advice.

Best regards,
Namhc

Dear @julienosman,

Change classifier.libsm.opt to false was the solution, thanks a lot for your help !

Best regards

1 Like