Hello,

I would like to use orfeo for a libsvm oneclass classification. However, I 
get error messages that don't really help to see my mistake. Maybe someone 
encountered a similar error.

Before I list my questions, I will explain what I did:

   1. Generate training samples 
   - I created a polygone shapefile layer in QGIS and manually drew 
      polygons with class label 1 for the features, I would like to extract.
      - result: Train_Samples_1Class.shp
      2. Compute image second order statistics
      - *otbcli_ComputeImagesStatistics -il namibia_orthoimage.tif -out 
      namibia_orthoimage_statistics.xml*
   3. Train SVM classifier
      - otbcli_TrainImagesClassifier -io.il namibia_orthoimage.tif -io.vd 
      Train_Samples_1Class.shp -io.imstat namibia_orthoimage_statistics.xml 
      -sample.mv 100 -sample.mt 100 -sample.vtr 0.5 -sample.vfn Class 
-classifier 
      libsvm -classifier.libsvm.k linear -classifier.libsvm.c 1 
*-classifier.libsvm.m 
      oneclass* -classifier.libsvm.opt 1 -io.out SVM_Model.txt 
      -io.confmatout SVM_ConfusionMatrix.csv

      - This gives the error "*could not find paramter m*" when run as a 
         Pyhton script in the OSGeo4W Shell and "*option 
         -classifier.libsvm.m does not exist in the application*" when run 
         directly as the command-line listed above.
         - Therefore, I tried it without the oneclass option and created 
         training samples with two classes (1: feature to be detected, 0 for 
all 
         remaining polygons --> result: Train_Samples.shp) and changed the 
above 
         code as follows:
         - *otbcli_TrainImagesClassifier -io.il namibia_orthoimage.tif 
         -io.vd Train_Samples.shp -io.imstat namibia_orthoimage_statistics.xml 
         -sample.mv 100 -sample.mt 100 -sample.vtr 0.5 -sample.vfn Class 
-classifier 
         libsvm -classifier.libsvm.k linear -classifier.libsvm.c 1 
         -classifier.libsvm.opt 1 -io.out SVM_Model.txt -io.confmatout 
         SVM_ConfusionMatrix.csv*
         - This gives the error "*Input primary is required but not set*" 
         (ErrorI attached), when run as a Pyhton script in the OSGeo4W Shell 
and "*Inconsistent 
         measurement vector size: Input Sample List size 3 Scale measurement 
vector 
         size 0 Shift measurement vector size 0*" (Error II) when run 
         directly as the command-line listed above.
         - I also attached the Python script, I refer to, to make it 
         clearer.
         - When I alternatively try to do train the SVM classifier via the 
         Orfeo GUI in QGIS, I don't get any output or error message.
      
Questions:

   - How do I correctly use the oneclass SVM classifier?
   - Where is my error for training the two class SVM classifier?
   - Does the output model file need to be .svm or .txt? I found different 
   versions in 
   https://www.orfeo-toolbox.org//CookBook/CookBooksu39.html#x58-910003.4.1 
   and in 
   https://www.orfeo-toolbox.org/CookBook/CookBooksu123.html#x154-9080004.8.10


Thanks a lot!


Sophie

-- 
-- 
Check the OTB FAQ at
http://www.orfeo-toolbox.org/FAQ.html

You received this message because you are subscribed to the Google
Groups "otb-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/otb-users?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"otb-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
#### Train SVM Classifier ####

# Execute in OSGeo4W Shell:
#	python Train_SVM.py namibia_orthoimage.tif Train_Samples.shp namibia_orthoimage_statistics.xml SVM_Model.txt SVM_ConfusionMatrix.csv
#	otbcli_TrainImagesClassifier -io.il namibia_orthoimage.tif -io.vd Train_Samples.shp -io.imstat namibia_orthoimage_statistics.xml -sample.mv 100 -sample.mt 100 -sample.vtr 0.5 -sample.vfn Class -classifier libsvm -classifier.libsvm.k linear -classifier.libsvm.c 1 -classifier.libsvm.opt 1 -io.out SVM_Model.txt -io.confmatout SVM_ConfusionMatrix.csv

# Import required modules
#!/usr/bin/python
# -*- coding: utf-8 -*-
import otbApplication
from sys import argv

#### Main Part ####
 
# The following line creates an instance of the TrainImagesClassifier application 
TrainImagesClassifier = otbApplication.Registry.CreateApplication("TrainImagesClassifier") 
 
# The following lines set all the application parameters: 
# Input Image List 
TrainImagesClassifier.SetParameterStringList("io.il", argv[1]) 

# Input Vector Data List 
TrainImagesClassifier.SetParameterStringList("io.vd", argv[2]) 

# Input XML image statistics file 
TrainImagesClassifier.SetParameterString("io.imstat", argv[3]) 

TrainImagesClassifier.SetParameterInt("sample.mv", 100) 
 
TrainImagesClassifier.SetParameterInt("sample.mt", 100) 

# Training and validation sample ratio 
TrainImagesClassifier.SetParameterFloat("sample.vtr", 0.5) 
 
# Name of the discrimination field  
TrainImagesClassifier.SetParameterString("sample.vfn", "Class") 

# Classifier to use for the training  
TrainImagesClassifier.SetParameterString("classifier","libsvm") 

# SVM Kernel Type: Linear
TrainImagesClassifier.SetParameterString("classifier.libsvm.k","linear") 

# Possible to change Kernel type later, then adapt gamma as well
# SVM Kernel Type: Gaussian radial basis function
# TrainImagesClassifier.SetParameterString("classifier.libsvm.k","rbf") 

# SVM Model Type: Distribution estimation (One Class SVM) 
# TrainImagesClassifier.SetParameterString("classifier.libsvm.m","oneclass") 

# Cost parameter C 
TrainImagesClassifier.SetParameterFloat("classifier.libsvm.c", 1) 

# Parameters optimization 
TrainImagesClassifier.SetParameterString("classifier.libsvm.opt","1") 

# Output model 
TrainImagesClassifier.SetParameterString("io.out", argv[4]) 

# Output confusion matrix 
TrainImagesClassifier.SetParameterString("io.confmatout", argv[5]) 
 
# The following line execute the application 
TrainImagesClassifier.ExecuteAndWriteOutput() 

Reply via email to