OTB  9.0.0
Orfeo Toolbox
otbLearningApplicationBase.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbLearningApplicationBase_h
22 #define otbLearningApplicationBase_h
23 
24 #include "otbConfigure.h"
25 
26 #include "otbWrapperApplication.h"
27 
28 
29 // ListSample
30 #include "itkListSample.h"
31 #include "itkVariableLengthVector.h"
32 
33 // Estimator
35 #include <string>
36 
37 namespace otb
38 {
39 namespace Wrapper
40 {
41 
74 template <class TInputValue, class TOutputValue>
76 {
77 public:
81  typedef itk::SmartPointer<Self> Pointer;
82  typedef itk::SmartPointer<const Self> ConstPointer;
83 
85  itkTypeMacro(LearningApplicationBase, otb::Application);
86 
87  typedef TInputValue InputValueType;
88  typedef TOutputValue OutputValueType;
89 
92 
93  // Machine Learning models
97 
100 
104 
105  itkGetConstReferenceMacro(SupervisedClassifier, std::vector<std::string>);
106  itkGetConstReferenceMacro(UnsupervisedClassifier, std::vector<std::string>);
107 
109  {
112  };
113 
120 
121 protected:
123 
124  ~LearningApplicationBase() override;
125 
128  void Train(typename ListSampleType::Pointer trainingListSample, typename TargetListSampleType::Pointer trainingLabeledListSample, std::string modelPath);
129 
131  typename TargetListSampleType::Pointer Classify(typename ListSampleType::Pointer validationListSample, std::string modelPath);
132 
134  void DoInit() override;
135 
139 
140 private:
145  std::vector<std::string> m_SupervisedClassifier;
146 
149  std::vector<std::string> m_UnsupervisedClassifier;
150 
152 #ifdef OTB_USE_LIBSVM
153  void InitLibSVMParams();
154 
155  void TrainLibSVM(typename ListSampleType::Pointer trainingListSample, typename TargetListSampleType::Pointer trainingLabeledListSample,
156  std::string modelPath);
157 #endif
158 
159 #ifdef OTB_USE_OPENCV
160  void InitBoostParams();
161  void InitSVMParams();
162  void InitDecisionTreeParams();
163  void InitNeuralNetworkParams();
164  void InitNormalBayesParams();
165  void InitRandomForestsParams();
166  void InitKNNParams();
167 
168  void TrainBoost(typename ListSampleType::Pointer trainingListSample, typename TargetListSampleType::Pointer trainingLabeledListSample, std::string modelPath);
169  void TrainSVM(typename ListSampleType::Pointer trainingListSample, typename TargetListSampleType::Pointer trainingLabeledListSample, std::string modelPath);
170  void TrainDecisionTree(typename ListSampleType::Pointer trainingListSample, typename TargetListSampleType::Pointer trainingLabeledListSample,
171  std::string modelPath);
172  void TrainNeuralNetwork(typename ListSampleType::Pointer trainingListSample, typename TargetListSampleType::Pointer trainingLabeledListSample,
173  std::string modelPath);
174  void TrainNormalBayes(typename ListSampleType::Pointer trainingListSample, typename TargetListSampleType::Pointer trainingLabeledListSample,
175  std::string modelPath);
176  void TrainRandomForests(typename ListSampleType::Pointer trainingListSample, typename TargetListSampleType::Pointer trainingLabeledListSample,
177  std::string modelPath);
178  void TrainKNN(typename ListSampleType::Pointer trainingListSample, typename TargetListSampleType::Pointer trainingLabeledListSample, std::string modelPath);
179 #endif
180 
181 #ifdef OTB_USE_SHARK
182  void InitSharkRandomForestsParams();
183  void TrainSharkRandomForests(typename ListSampleType::Pointer trainingListSample, typename TargetListSampleType::Pointer trainingLabeledListSample,
184  std::string modelPath);
185  void InitSharkKMeansParams();
186  void TrainSharkKMeans(typename ListSampleType::Pointer trainingListSample, typename TargetListSampleType::Pointer trainingLabeledListSample,
187  std::string modelPath);
188 #endif
189 
190 };
191 }
192 }
193 
194 #ifndef OTB_MANUAL_INSTANTIATION
196 #ifdef OTB_USE_OPENCV
197 #include "otbTrainBoost.hxx"
198 #include "otbTrainDecisionTree.hxx"
199 #include "otbTrainKNN.hxx"
200 #include "otbTrainNeuralNetwork.hxx"
201 #include "otbTrainNormalBayes.hxx"
202 #include "otbTrainRandomForests.hxx"
203 #include "otbTrainSVM.hxx"
204 #endif
205 #ifdef OTB_USE_LIBSVM
206 #include "otbTrainLibSVM.hxx"
207 #endif
208 #ifdef OTB_USE_SHARK
210 #include "otbTrainSharkKMeans.hxx"
211 #endif
212 #endif
213 
214 #endif
otb::Wrapper::LearningApplicationBase::~LearningApplicationBase
~LearningApplicationBase() override
Definition: otbLearningApplicationBase.hxx:40
otb::Wrapper::LearningApplicationBase::OutputValueType
TOutputValue OutputValueType
Definition: otbLearningApplicationBase.h:88
otb::MachineLearningModel::TargetListSampleType
itk::Statistics::ListSample< TargetSampleType > TargetListSampleType
Definition: otbMachineLearningModel.h:92
otb::Wrapper::LearningApplicationBase::SampleImageType
otb::VectorImage< InputValueType > SampleImageType
Definition: otbLearningApplicationBase.h:90
otb::Wrapper::LearningApplicationBase::m_SupervisedClassifier
std::vector< std::string > m_SupervisedClassifier
Definition: otbLearningApplicationBase.h:145
otb::Wrapper::Application
This class represent an application TODO.
Definition: otbWrapperApplication.h:76
otb::MachineLearningModelFactory
Creation of object instance using object factory.
Definition: otbMachineLearningModelFactory.h:35
otbTrainSharkKMeans.hxx
otb::Wrapper::LearningApplicationBase::ClassifierCategory
ClassifierCategory
Definition: otbLearningApplicationBase.h:108
otb::Wrapper::LearningApplicationBase::InputValueType
TInputValue InputValueType
Definition: otbLearningApplicationBase.h:85
otb::Wrapper::LearningApplicationBase::ListSampleType
ModelType::InputListSampleType ListSampleType
Definition: otbLearningApplicationBase.h:99
otb::Wrapper::LearningApplicationBase
LearningApplicationBase is the base class for application that use machine learning model.
Definition: otbLearningApplicationBase.h:75
otb::Wrapper::LearningApplicationBase::InitUnsupervisedClassifierParams
void InitUnsupervisedClassifierParams()
Definition: otbLearningApplicationBase.hxx:112
otbTrainSVM.hxx
otb::Wrapper::LearningApplicationBase::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbLearningApplicationBase.h:81
otb::MachineLearningModel::InputListSampleType
itk::Statistics::ListSample< InputSampleType > InputListSampleType
Definition: otbMachineLearningModel.h:85
otb::Wrapper::LearningApplicationBase::Classify
TargetListSampleType::Pointer Classify(typename ListSampleType::Pointer validationListSample, std::string modelPath)
Definition: otbLearningApplicationBase.hxx:124
otbTrainBoost.hxx
otbWrapperApplication.h
otb::Wrapper::LearningApplicationBase::GetClassifierCategory
ClassifierCategory GetClassifierCategory()
Definition: otbLearningApplicationBase.hxx:65
otbTrainDecisionTree.hxx
otb::Wrapper::LearningApplicationBase::m_UnsupervisedClassifier
std::vector< std::string > m_UnsupervisedClassifier
Definition: otbLearningApplicationBase.h:149
otb::Wrapper::LearningApplicationBase::ModelFactoryType
otb::MachineLearningModelFactory< InputValueType, OutputValueType > ModelFactoryType
Definition: otbLearningApplicationBase.h:94
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::MachineLearningModelFactory::MachineLearningModelTypePointer
MachineLearningModelType::Pointer MachineLearningModelTypePointer
Definition: otbMachineLearningModelFactory.h:51
otb::Wrapper::LearningApplicationBase::Self
LearningApplicationBase Self
Definition: otbLearningApplicationBase.h:79
otb::Wrapper::LearningApplicationBase::Unsupervised
@ Unsupervised
Definition: otbLearningApplicationBase.h:111
otb::Wrapper::LearningApplicationBase::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbLearningApplicationBase.h:82
otb::Wrapper::LearningApplicationBase::Train
void Train(typename ListSampleType::Pointer trainingListSample, typename TargetListSampleType::Pointer trainingLabeledListSample, std::string modelPath)
Definition: otbLearningApplicationBase.hxx:153
otb::Wrapper::LearningApplicationBase::TargetListSampleType
ModelType::TargetListSampleType TargetListSampleType
Definition: otbLearningApplicationBase.h:102
otb::Wrapper::LearningApplicationBase::TargetSampleType
ModelType::TargetSampleType TargetSampleType
Definition: otbLearningApplicationBase.h:101
otbTrainRandomForests.hxx
otbTrainNeuralNetwork.hxx
otb::Wrapper::LearningApplicationBase::ModelPointerType
ModelFactoryType::MachineLearningModelTypePointer ModelPointerType
Definition: otbLearningApplicationBase.h:95
otbLearningApplicationBase.hxx
otb::Wrapper::LearningApplicationBase::Superclass
Application Superclass
Definition: otbLearningApplicationBase.h:80
otb::Wrapper::LearningApplicationBase::SampleType
ModelType::InputSampleType SampleType
Definition: otbLearningApplicationBase.h:98
otbMachineLearningModelFactory.h
otb::Wrapper::LearningApplicationBase::LearningApplicationBase
LearningApplicationBase()
Definition: otbLearningApplicationBase.hxx:34
otb::MachineLearningModel
MachineLearningModel is the base class for all classifier objects (SVM, KNN, Random Forests,...
Definition: otbMachineLearningModel.h:70
otb::Wrapper::LearningApplicationBase::DoInit
void DoInit() override
Definition: otbLearningApplicationBase.hxx:46
otb::VectorImage::PixelType
Superclass::PixelType PixelType
Definition: otbVectorImage.h:63
otb::MachineLearningModel::TargetValueType
MLMTargetTraits< TTargetValue >::ValueType TargetValueType
Definition: otbMachineLearningModel.h:90
otbTrainNormalBayes.hxx
otb::Wrapper::LearningApplicationBase::PixelType
SampleImageType::PixelType PixelType
Definition: otbLearningApplicationBase.h:91
otbTrainKNN.hxx
otb::Wrapper::LearningApplicationBase::ModelType
ModelFactoryType::MachineLearningModelType ModelType
Definition: otbLearningApplicationBase.h:96
otb::Wrapper::LearningApplicationBase::TargetValueType
ModelType::TargetValueType TargetValueType
Definition: otbLearningApplicationBase.h:103
otbTrainLibSVM.hxx
otb::Wrapper::LearningApplicationBase::Supervised
@ Supervised
Definition: otbLearningApplicationBase.h:110
otb::Wrapper::LearningApplicationBase::m_RegressionFlag
bool m_RegressionFlag
Definition: otbLearningApplicationBase.h:138
otbTrainSharkRandomForests.hxx
otb::MachineLearningModel::InputSampleType
MLMSampleTraits< TInputValue >::SampleType InputSampleType
Definition: otbMachineLearningModel.h:84
otb::MachineLearningModel::TargetSampleType
MLMTargetTraits< TTargetValue >::SampleType TargetSampleType
Definition: otbMachineLearningModel.h:91
otb::Wrapper::LearningApplicationBase::InitSupervisedClassifierParams
void InitSupervisedClassifierParams()
Definition: otbLearningApplicationBase.hxx:80
otb::VectorImage
Creation of an "otb" vector image which contains metadata.
Definition: otbVectorImage.h:45