From f52ef084cedbdd4bed5a742d2887d15e197269c0 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero <guillaume.pasero@c-s.fr> Date: Tue, 28 Nov 2017 17:43:07 +0100 Subject: [PATCH] ENH: move specific code for each DR algorithm --- ...imensionalityReductionTrainAutoencoder.txx | 11 +++++- .../otbDimensionalityReductionTrainPCA.txx | 2 + .../otbDimensionalityReductionTrainSOM.txx | 12 +++++- ...inDimensionalityReductionApplicationBase.h | 37 ------------------- 4 files changed, 23 insertions(+), 39 deletions(-) diff --git a/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainAutoencoder.txx b/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainAutoencoder.txx index a4b8d72d83..01123fcdb7 100644 --- a/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainAutoencoder.txx +++ b/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainAutoencoder.txx @@ -3,6 +3,7 @@ #define cbTrainAutoencoder_txx #include "otbTrainDimensionalityReductionApplicationBase.h" +#include "otbAutoencoderModel.h" namespace otb { @@ -106,7 +107,15 @@ void TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue> ::BeforeTrainAutoencoder(typename ListSampleType::Pointer trainingListSample, std::string modelPath) -{ +{ + // typedef shark::Autoencoder< shark::TanhNeuron, shark::LinearNeuron> AutoencoderType; + typedef shark::LogisticNeuron NeuronType; + typedef otb::AutoencoderModel<InputValueType, NeuronType> AutoencoderModelType; + /* + // typedef shark::TiedAutoencoder< shark::TanhNeuron, shark::LinearNeuron> TiedAutoencoderType; + typedef shark::TiedAutoencoder< shark::TanhNeuron, shark::TanhNeuron> TiedAutoencoderType; + typedef otb::AutoencoderModel<InputValueType, TiedAutoencoderType> TiedAutoencoderModelType; + */ std::string TiedWeigth = GetParameterString("algorithm.autoencoder.istied"); std::cout << TiedWeigth << std::endl; diff --git a/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainPCA.txx b/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainPCA.txx index 66a87aaade..4426e103b2 100644 --- a/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainPCA.txx +++ b/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainPCA.txx @@ -3,6 +3,7 @@ #define cbTrainPCA_txx #include "otbTrainDimensionalityReductionApplicationBase.h" +#include "otbPCAModel.h" namespace otb { @@ -37,6 +38,7 @@ template <class TInputValue, class TOutputValue> void TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue> ::TrainPCA(typename ListSampleType::Pointer trainingListSample,std::string modelPath) { + typedef otb::PCAModel<InputValueType> PCAModelType; typename PCAModelType::Pointer dimredTrainer = PCAModelType::New(); dimredTrainer->SetDimension(GetParameterInt("algorithm.pca.dim")); dimredTrainer->SetInputListSample(trainingListSample); diff --git a/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainSOM.txx b/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainSOM.txx index e9c22f3c85..b437723066 100644 --- a/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainSOM.txx +++ b/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainSOM.txx @@ -2,6 +2,7 @@ #ifndef cbTrainSOM_txx #define cbTrainSOM_txx #include "otbTrainDimensionalityReductionApplicationBase.h" +#include "otbSOMModel.h" namespace otb { @@ -79,7 +80,16 @@ void TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue> ::BeforeTrainSOM(typename ListSampleType::Pointer trainingListSample, std::string modelPath) -{ +{ + //typedef SOMMap<TInputValue,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 2> Map2DType; + //typedef SOMMap<TInputValue,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 3> Map3DType; + //typedef SOMMap<TInputValue,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 4> Map4DType; + //typedef SOMMap<TInputValue,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 5> Map5DType; + typedef otb::SOMModel<InputValueType, 2> SOM2DModelType; + typedef otb::SOMModel<InputValueType, 3> SOM3DModelType; + typedef otb::SOMModel<InputValueType, 4> SOM4DModelType; + typedef otb::SOMModel<InputValueType, 5> SOM5DModelType; + int SomDim = GetParameterInt("algorithm.som.dim"); std::cout << SomDim << std::endl; diff --git a/Modules/Applications/AppDimensionalityReduction/include/otbTrainDimensionalityReductionApplicationBase.h b/Modules/Applications/AppDimensionalityReduction/include/otbTrainDimensionalityReductionApplicationBase.h index c14bfd8ca0..0dff279698 100644 --- a/Modules/Applications/AppDimensionalityReduction/include/otbTrainDimensionalityReductionApplicationBase.h +++ b/Modules/Applications/AppDimensionalityReduction/include/otbTrainDimensionalityReductionApplicationBase.h @@ -14,13 +14,6 @@ //Estimator #include "otbDimensionalityReductionModelFactory.h" -#include "otbSOMModel.h" - -#ifdef OTB_USE_SHARK -#include "otbAutoencoderModel.h" -#include "otbPCAModel.h" -#endif - namespace otb { namespace Wrapper @@ -84,34 +77,6 @@ public: typedef typename ModelType::InputSampleType SampleType; typedef typename ModelType::InputListSampleType ListSampleType; - -// Dimensionality reduction models - -//typedef SOMMap<TInputValue,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 2> Map2DType; - typedef otb::SOMModel<InputValueType, 2> SOM2DModelType; - -//typedef SOMMap<TInputValue,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 3> Map3DType; - typedef otb::SOMModel<InputValueType, 3> SOM3DModelType; - -//typedef SOMMap<TInputValue,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 4> Map4DType; - typedef otb::SOMModel<InputValueType, 4> SOM4DModelType; - -//typedef SOMMap<TInputValue,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 5> Map5DType; - typedef otb::SOMModel<InputValueType, 5> SOM5DModelType; - - -#ifdef OTB_USE_SHARK - -// typedef shark::Autoencoder< shark::TanhNeuron, shark::LinearNeuron> AutoencoderType; - typedef shark::LogisticNeuron NeuronType; - typedef otb::AutoencoderModel<InputValueType, NeuronType> AutoencoderModelType; -/* - // typedef shark::TiedAutoencoder< shark::TanhNeuron, shark::LinearNeuron> TiedAutoencoderType; - typedef shark::TiedAutoencoder< shark::TanhNeuron, shark::TanhNeuron> TiedAutoencoderType; - typedef otb::AutoencoderModel<InputValueType, TiedAutoencoderType> TiedAutoencoderModelType; - */ - typedef otb::PCAModel<InputValueType> PCAModelType; -#endif protected: TrainDimensionalityReductionApplicationBase(); @@ -148,8 +113,6 @@ void BeforeTrainSOM(typename ListSampleType::Pointer trainingListSample, std::st void TrainAutoencoder(typename ListSampleType::Pointer trainingListSample, std::string modelPath); void TrainPCA(typename ListSampleType::Pointer trainingListSample, std::string modelPath); - - #endif //@} }; -- GitLab