Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Main Repositories
otb
Commits
735349bc
Commit
735349bc
authored
Mar 19, 2015
by
Christophe Palmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH: fixed TrainImagesClassifier app comp. when libsvm and opencv modules are not installed
parent
eab17f35
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
71 additions
and
12 deletions
+71
-12
Modules/Applications/AppClassification/app/otbTrainBoost.cxx
Modules/Applications/AppClassification/app/otbTrainBoost.cxx
+2
-0
Modules/Applications/AppClassification/app/otbTrainDecisionTree.cxx
...plications/AppClassification/app/otbTrainDecisionTree.cxx
+2
-1
Modules/Applications/AppClassification/app/otbTrainGradientBoostedTree.cxx
...ons/AppClassification/app/otbTrainGradientBoostedTree.cxx
+2
-1
Modules/Applications/AppClassification/app/otbTrainImagesClassifier.cxx
...ations/AppClassification/app/otbTrainImagesClassifier.cxx
+40
-2
Modules/Applications/AppClassification/app/otbTrainImagesClassifier.h
...ications/AppClassification/app/otbTrainImagesClassifier.h
+13
-2
Modules/Applications/AppClassification/app/otbTrainKNN.cxx
Modules/Applications/AppClassification/app/otbTrainKNN.cxx
+2
-1
Modules/Applications/AppClassification/app/otbTrainLibSVM.cxx
...les/Applications/AppClassification/app/otbTrainLibSVM.cxx
+2
-1
Modules/Applications/AppClassification/app/otbTrainNeuralNetwork.cxx
...lications/AppClassification/app/otbTrainNeuralNetwork.cxx
+2
-1
Modules/Applications/AppClassification/app/otbTrainNormalBayes.cxx
...pplications/AppClassification/app/otbTrainNormalBayes.cxx
+2
-1
Modules/Applications/AppClassification/app/otbTrainRandomForests.cxx
...lications/AppClassification/app/otbTrainRandomForests.cxx
+2
-1
Modules/Applications/AppClassification/app/otbTrainSVM.cxx
Modules/Applications/AppClassification/app/otbTrainSVM.cxx
+2
-1
No files found.
Modules/Applications/AppClassification/app/otbTrainBoost.cxx
View file @
735349bc
...
...
@@ -22,6 +22,7 @@ namespace otb
{
namespace
Wrapper
{
#ifdef OTB_USE_OPENCV
void
TrainImagesClassifier
::
InitBoostParams
()
{
AddChoice
(
"classifier.boost"
,
"Boost classifier"
);
...
...
@@ -68,6 +69,7 @@ namespace Wrapper
boostClassifier
->
Train
();
boostClassifier
->
Save
(
GetParameterString
(
"io.out"
));
}
#endif
}
//end namespace wrapper
}
//end namespace otb
Modules/Applications/AppClassification/app/otbTrainDecisionTree.cxx
View file @
735349bc
...
...
@@ -21,6 +21,7 @@ namespace otb
{
namespace
Wrapper
{
#ifdef OTB_USE_OPENCV
void
TrainImagesClassifier
::
InitDecisionTreeParams
()
{
AddChoice
(
"classifier.dt"
,
"Decision Tree classifier"
);
...
...
@@ -102,6 +103,6 @@ void TrainImagesClassifier::TrainDecisionTree(ListSampleType::Pointer trainingLi
classifier
->
Train
();
classifier
->
Save
(
GetParameterString
(
"io.out"
));
}
#endif
}
//end namespace wrapper
}
//end namespace otb
Modules/Applications/AppClassification/app/otbTrainGradientBoostedTree.cxx
View file @
735349bc
...
...
@@ -21,6 +21,7 @@ namespace otb
{
namespace
Wrapper
{
#ifdef OTB_USE_OPENCV
void
TrainImagesClassifier
::
InitGradientBoostedTreeParams
()
{
AddChoice
(
"classifier.gbt"
,
"Gradient Boosted Tree classifier"
);
...
...
@@ -80,6 +81,6 @@ void TrainImagesClassifier::TrainGradientBoostedTree(
classifier
->
Train
();
classifier
->
Save
(
GetParameterString
(
"io.out"
));
}
#endif
}
//end namespace wrapper
}
//end namespace otb
Modules/Applications/AppClassification/app/otbTrainImagesClassifier.cxx
View file @
735349bc
...
...
@@ -105,7 +105,9 @@ void TrainImagesClassifier::DoInit()
SetParameterDescription
(
"classifier"
,
"Choice of the classifier to use for the training."
);
//Group LibSVM
#ifdef OTB_USE_LIBSVM
InitLibSVMParams
();
#endif
#ifdef OTB_USE_OPENCV
InitSVMParams
();
...
...
@@ -395,44 +397,80 @@ void TrainImagesClassifier::DoExecute()
//--------------------------
LabelListSampleType
::
Pointer
predictedList
=
LabelListSampleType
::
New
();
const
std
::
string
classifierType
=
GetParameterString
(
"classifier"
);
if
(
classifierType
==
"libsvm"
)
{
#ifdef OTB_USE_LIBSVM
TrainLibSVM
(
trainingListSample
,
trainingLabeledListSample
);
#elseif
otbAppLogFATAL
(
"Module LIBSVM is not installed. You should consider turning OTB_USE_LIBSVM on during cmake configuration."
);
#endif
}
#ifdef OTB_USE_OPENCV
else
if
(
classifierType
==
"svm"
)
{
#ifdef OTB_USE_OPENCV
TrainSVM
(
trainingListSample
,
trainingLabeledListSample
);
#elseif
otbAppLogFATAL
(
"Module OPENCV is not installed. You should consider turning OTB_USE_OPENCV on during cmake configuration."
);
#endif
}
else
if
(
classifierType
==
"boost"
)
{
#ifdef OTB_USE_OPENCV
TrainBoost
(
trainingListSample
,
trainingLabeledListSample
);
#elseif
otbAppLogFATAL
(
"Module OPENCV is not installed. You should consider turning OTB_USE_OPENCV on during cmake configuration."
);
#endif
}
else
if
(
classifierType
==
"dt"
)
{
#ifdef OTB_USE_OPENCV
TrainDecisionTree
(
trainingListSample
,
trainingLabeledListSample
);
#elseif
otbAppLogFATAL
(
"Module OPENCV is not installed. You should consider turning OTB_USE_OPENCV on during cmake configuration."
);
#endif
}
else
if
(
classifierType
==
"gbt"
)
{
#ifdef OTB_USE_OPENCV
TrainGradientBoostedTree
(
trainingListSample
,
trainingLabeledListSample
);
#elseif
otbAppLogFATAL
(
"Module OPENCV is not installed. You should consider turning OTB_USE_OPENCV on during cmake configuration."
);
#endif
}
else
if
(
classifierType
==
"ann"
)
{
#ifdef OTB_USE_OPENCV
TrainNeuralNetwork
(
trainingListSample
,
trainingLabeledListSample
);
#elseif
otbAppLogFATAL
(
"Module OPENCV is not installed. You should consider turning OTB_USE_OPENCV on during cmake configuration."
);
#endif
}
else
if
(
classifierType
==
"bayes"
)
{
#ifdef OTB_USE_OPENCV
TrainNormalBayes
(
trainingListSample
,
trainingLabeledListSample
);
#elseif
otbAppLogFATAL
(
"Module OPENCV is not installed. You should consider turning OTB_USE_OPENCV on during cmake configuration."
);
#endif
}
else
if
(
classifierType
==
"rf"
)
{
#ifdef OTB_USE_OPENCV
TrainRandomForests
(
trainingListSample
,
trainingLabeledListSample
);
#elseif
otbAppLogFATAL
(
"Module OPENCV is not installed. You should consider turning OTB_USE_OPENCV on during cmake configuration."
);
#endif
}
else
if
(
classifierType
==
"knn"
)
{
#ifdef OTB_USE_OPENCV
TrainKNN
(
trainingListSample
,
trainingLabeledListSample
);
#elseif
otbAppLogFATAL
(
"Module OPENCV is not installed. You should consider turning OTB_USE_OPENCV on during cmake configuration."
);
#endif
}
#endif
//--------------------------
// Performances estimation
...
...
Modules/Applications/AppClassification/app/otbTrainImagesClassifier.h
View file @
735349bc
...
...
@@ -42,7 +42,9 @@
# include "otbNeuralNetworkMachineLearningModel.h"
#endif
#ifdef OTB_USE_LIBSVM
#include "otbLibSVMMachineLearningModel.h"
#endif
// Statistic XML Reader
#include "otbStatisticsXMLFileReader.h"
...
...
@@ -124,8 +126,11 @@ public:
typedef
otb
::
NeuralNetworkMachineLearningModel
<
InternalPixelType
,
ListSampleGeneratorType
::
ClassLabelType
>
NeuralNetworkType
;
typedef
otb
::
NormalBayesMachineLearningModel
<
InternalPixelType
,
ListSampleGeneratorType
::
ClassLabelType
>
NormalBayesType
;
#endif
#ifdef OTB_USE_LIBSVM
typedef
otb
::
LibSVMMachineLearningModel
<
InternalPixelType
,
ListSampleGeneratorType
::
ClassLabelType
>
LibSVMType
;
#endif
// Estimate performance on validation sample
typedef
otb
::
ConfusionMatrixCalculator
<
LabelListSampleType
,
LabelListSampleType
>
ConfusionMatrixCalculatorType
;
typedef
ConfusionMatrixCalculatorType
::
ConfusionMatrixType
ConfusionMatrixType
;
...
...
@@ -150,7 +155,10 @@ private:
void
LogConfusionMatrix
(
ConfusionMatrixCalculatorType
*
confMatCalc
);
#ifdef OTB_USE_LIBSVM
void
InitLibSVMParams
();
#endif
#ifdef OTB_USE_OPENCV
void
InitBoostParams
();
void
InitSVMParams
();
...
...
@@ -161,8 +169,11 @@ private:
void
InitRandomForestsParams
();
void
InitKNNParams
();
#endif
#ifdef OTB_USE_LIBSVM
void
TrainLibSVM
(
ListSampleType
::
Pointer
trainingListSample
,
LabelListSampleType
::
Pointer
trainingLabeledListSample
);
#endif
#ifdef OTB_USE_OPENCV
void
TrainBoost
(
ListSampleType
::
Pointer
trainingListSample
,
LabelListSampleType
::
Pointer
trainingLabeledListSample
);
void
TrainSVM
(
ListSampleType
::
Pointer
trainingListSample
,
LabelListSampleType
::
Pointer
trainingLabeledListSample
);
...
...
Modules/Applications/AppClassification/app/otbTrainKNN.cxx
View file @
735349bc
...
...
@@ -22,6 +22,7 @@ namespace otb
{
namespace
Wrapper
{
#ifdef OTB_USE_OPENCV
void
TrainImagesClassifier
::
InitKNNParams
()
{
AddChoice
(
"classifier.knn"
,
"KNN classifier"
);
...
...
@@ -46,6 +47,6 @@ namespace Wrapper
knnClassifier
->
Train
();
knnClassifier
->
Save
(
GetParameterString
(
"io.out"
));
}
#endif
}
//end namespace wrapper
}
//end namespace otb
Modules/Applications/AppClassification/app/otbTrainLibSVM.cxx
View file @
735349bc
...
...
@@ -22,6 +22,7 @@ namespace otb
{
namespace
Wrapper
{
#ifdef OTB_USE_LIBSVM
void
TrainImagesClassifier
::
InitLibSVMParams
()
{
AddChoice
(
"classifier.libsvm"
,
"LibSVM classifier"
);
...
...
@@ -78,6 +79,6 @@ namespace Wrapper
libSVMClassifier
->
Train
();
libSVMClassifier
->
Save
(
GetParameterString
(
"io.out"
));
}
#endif
}
//end namespace wrapper
}
//end namespace otb
Modules/Applications/AppClassification/app/otbTrainNeuralNetwork.cxx
View file @
735349bc
...
...
@@ -22,6 +22,7 @@ namespace otb
{
namespace
Wrapper
{
#ifdef OTB_USE_OPENCV
void
TrainImagesClassifier
::
InitNeuralNetworkParams
()
{
AddChoice
(
"classifier.ann"
,
"Artificial Neural Network classifier"
);
...
...
@@ -209,6 +210,6 @@ void TrainImagesClassifier::TrainNeuralNetwork(ListSampleType::Pointer trainingL
classifier
->
Train
();
classifier
->
Save
(
GetParameterString
(
"io.out"
));
}
#endif
}
//end namespace wrapper
}
//end namespace otb
Modules/Applications/AppClassification/app/otbTrainNormalBayes.cxx
View file @
735349bc
...
...
@@ -22,6 +22,7 @@ namespace otb
{
namespace
Wrapper
{
#ifdef OTB_USE_OPENCV
void
TrainImagesClassifier
::
InitNormalBayesParams
()
{
AddChoice
(
"classifier.bayes"
,
"Normal Bayes classifier"
);
...
...
@@ -39,6 +40,6 @@ namespace Wrapper
classifier
->
Train
();
classifier
->
Save
(
GetParameterString
(
"io.out"
));
}
#endif
}
//end namespace wrapper
}
//end namespace otb
Modules/Applications/AppClassification/app/otbTrainRandomForests.cxx
View file @
735349bc
...
...
@@ -21,6 +21,7 @@ namespace otb
{
namespace
Wrapper
{
#ifdef OTB_USE_OPENCV
void
TrainImagesClassifier
::
InitRandomForestsParams
()
{
AddChoice
(
"classifier.rf"
,
"Random forests classifier"
);
...
...
@@ -111,6 +112,6 @@ void TrainImagesClassifier::TrainRandomForests(ListSampleType::Pointer trainingL
classifier
->
Train
();
classifier
->
Save
(
GetParameterString
(
"io.out"
));
}
#endif
}
//end namespace wrapper
}
//end namespace otb
Modules/Applications/AppClassification/app/otbTrainSVM.cxx
View file @
735349bc
...
...
@@ -22,6 +22,7 @@ namespace otb
{
namespace
Wrapper
{
#ifdef OTB_USE_OPENCV
void
TrainImagesClassifier
::
InitSVMParams
()
{
AddChoice
(
"classifier.svm"
,
"SVM classifier (OpenCV)"
);
...
...
@@ -75,7 +76,6 @@ namespace Wrapper
"because the samples are not identically processed within OpenCV."
);
}
void
TrainImagesClassifier
::
TrainSVM
(
ListSampleType
::
Pointer
trainingListSample
,
LabelListSampleType
::
Pointer
trainingLabeledListSample
)
{
SVMType
::
Pointer
SVMClassifier
=
SVMType
::
New
();
...
...
@@ -152,6 +152,7 @@ namespace Wrapper
SetParameterFloat
(
"classifier.svm.gamma"
,
static_cast
<
float
>
(
SVMClassifier
->
GetOutputGamma
()));
SetParameterFloat
(
"classifier.svm.degree"
,
static_cast
<
float
>
(
SVMClassifier
->
GetOutputDegree
()));
}
#endif
}
//end namespace wrapper
}
//end namespace otb
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment