OTB  9.0.0
Orfeo Toolbox
otbTrainDimensionalityReductionApplicationBase.hxx
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 #ifndef otbTrainDimensionalityReductionApplicationBase_hxx
21 #define otbTrainDimensionalityReductionApplicationBase_hxx
22 
24 
25 namespace otb
26 {
27 namespace Wrapper
28 {
29 
30 template <class TInputValue, class TOutputValue>
32 {
33 }
34 
35 template <class TInputValue, class TOutputValue>
37 {
38  ModelFactoryType::CleanFactories();
39 }
40 
41 template <class TInputValue, class TOutputValue>
43 {
44  AddDocTag(Tags::Learning);
45 
46  // main choice parameter that will contain all dimensionality reduction options
47  AddParameter(ParameterType_Choice, "algorithm", "algorithm to use for the training");
48  SetParameterDescription("algorithm",
49  "Choice of the dimensionality reduction "
50  "algorithm to use for the training.");
51 
52  InitSOMParams();
53 
54 #ifdef OTB_USE_SHARK
55  InitAutoencoderParams();
56  InitPCAParams();
57 #endif
58 }
59 
60 template <class TInputValue, class TOutputValue>
61 void TrainDimensionalityReductionApplicationBase<TInputValue, TOutputValue>::Reduce(typename ListSampleType::Pointer /*validationListSample*/,
62  std::string /*modelPath*/)
63 {
64 }
65 
66 template <class TInputValue, class TOutputValue>
67 void TrainDimensionalityReductionApplicationBase<TInputValue, TOutputValue>::Train(typename ListSampleType::Pointer trainingListSample, std::string modelPath)
68 {
69  // get the name of the chosen machine learning model
70  const std::string modelName = GetParameterString("algorithm");
71  // call specific train function
72 
73  if (modelName == "som")
74  {
75  BeforeTrainSOM(trainingListSample, modelPath);
76  }
77 
78  if (modelName == "autoencoder")
79  {
80 #ifdef OTB_USE_SHARK
81  BeforeTrainAutoencoder(trainingListSample, modelPath);
82 #else
83  otbAppLogFATAL("Module SharkLearning is not installed. You should consider turning OTB_USE_SHARK on during cmake configuration.");
84 #endif
85  }
86 
87  if (modelName == "pca")
88  {
89 #ifdef OTB_USE_SHARK
90  TrainPCA(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 
97 } // end of namespace Wrapper
98 } // end of namespace otb
99 
100 #endif
otb::Wrapper::TrainDimensionalityReductionApplicationBase::Reduce
void Reduce(typename ListSampleType::Pointer validationListSample, std::string modelPath)
Definition: otbTrainDimensionalityReductionApplicationBase.hxx:61
otb::Wrapper::TrainDimensionalityReductionApplicationBase::Train
void Train(typename ListSampleType::Pointer trainingListSample, std::string modelPath)
Definition: otbTrainDimensionalityReductionApplicationBase.hxx:67
otbAppLogFATAL
#define otbAppLogFATAL(x)
Definition: otbWrapperMacros.h:25
otb::Wrapper::ParameterType_Choice
@ ParameterType_Choice
Definition: otbWrapperTypes.h:47
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Wrapper::TrainDimensionalityReductionApplicationBase::TrainDimensionalityReductionApplicationBase
TrainDimensionalityReductionApplicationBase()
Definition: otbTrainDimensionalityReductionApplicationBase.hxx:31
otbTrainDimensionalityReductionApplicationBase.h
otb::Wrapper::Tags::Learning
static const std::string Learning
Definition: otbWrapperTags.h:42
otb::Wrapper::TrainDimensionalityReductionApplicationBase::DoInit
void DoInit() override
Definition: otbTrainDimensionalityReductionApplicationBase.hxx:42
otb::Wrapper::TrainDimensionalityReductionApplicationBase::~TrainDimensionalityReductionApplicationBase
~TrainDimensionalityReductionApplicationBase() override
Definition: otbTrainDimensionalityReductionApplicationBase.hxx:36