OTB  6.7.0
Orfeo Toolbox
otbTrainDimensionalityReductionApplicationBase.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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 #ifndef otbTrainDimensionalityReductionApplicationBase_hxx
21 #define otbTrainDimensionalityReductionApplicationBase_hxx
22 
24 
25 namespace otb
26 {
27 namespace Wrapper
28 {
29 
30 template <class TInputValue, class TOutputValue>
33 {
34 }
35 
36 template <class TInputValue, class TOutputValue>
39 {
40  ModelFactoryType::CleanFactories();
41 }
42 
43 template <class TInputValue, class TOutputValue>
44 void
47 {
48  AddDocTag(Tags::Learning);
49 
50  // main choice parameter that will contain all dimensionality reduction options
51  AddParameter(ParameterType_Choice, "algorithm", "algorithm to use for the training");
52  SetParameterDescription("algorithm", "Choice of the dimensionality reduction "
53  "algorithm to use for the training.");
54 
55  InitSOMParams();
56 
57 #ifdef OTB_USE_SHARK
58  InitAutoencoderParams();
59  InitPCAParams();
60 #endif
61 
62 }
63 
64 template <class TInputValue, class TOutputValue>
65 void
67 ::Reduce(typename ListSampleType::Pointer /*validationListSample*/,std::string /*modelPath*/)
68 {
69 }
70 
71 template <class TInputValue, class TOutputValue>
72 void
75  typename ListSampleType::Pointer trainingListSample,
76  std::string modelPath)
77 {
78  // get the name of the chosen machine learning model
79  const std::string modelName = GetParameterString("algorithm");
80  // call specific train function
81 
82  if(modelName == "som")
83  {
84  BeforeTrainSOM(trainingListSample,modelPath);
85  }
86 
87  if(modelName == "autoencoder")
88  {
89 #ifdef OTB_USE_SHARK
90  BeforeTrainAutoencoder(trainingListSample,modelPath);
91 #else
92  otbAppLogFATAL("Module SharkLearning is not installed. You should consider turning OTB_USE_SHARK on during cmake configuration.");
93 #endif
94  }
95 
96  if(modelName == "pca")
97  {
98 #ifdef OTB_USE_SHARK
99  TrainPCA(trainingListSample,modelPath);
100 #else
101  otbAppLogFATAL("Module SharkLearning is not installed. You should consider turning OTB_USE_SHARK on during cmake configuration.");
102 #endif
103  }
104 }
105 
106 } // end of namespace Wrapper
107 } // end of namespace otb
108 
109 #endif
void Train(typename ListSampleType::Pointer trainingListSample, std::string modelPath)
#define otbAppLogFATAL(x)
void Reduce(typename ListSampleType::Pointer validationListSample, std::string modelPath)
static const std::string Learning