diff --git a/Modules/Applications/AppDimensionalityReduction/app/otbImageDimensionalityReduction.cxx b/Modules/Applications/AppDimensionalityReduction/app/otbImageDimensionalityReduction.cxx index a4d00030febf68d7e1489f637371f6474ae2fcc6..7543fffb96721624532c211f7f3433c6fe687a5c 100644 --- a/Modules/Applications/AppDimensionalityReduction/app/otbImageDimensionalityReduction.cxx +++ b/Modules/Applications/AppDimensionalityReduction/app/otbImageDimensionalityReduction.cxx @@ -23,10 +23,10 @@ #include "otbStandardWriterWatcher.h" #include "otbStatisticsXMLFileReader.h" #include "otbShiftScaleVectorImageFilter.h" -#include "ImageDimensionalityReductionFilter.h" +#include "otbImageDimensionalityReductionFilter.h" #include "otbMultiToMonoChannelExtractROI.h" #include "otbImageToVectorImageCastFilter.h" -#include "DimensionalityReductionModelFactory.h" +#include "otbDimensionalityReductionModelFactory.h" namespace otb { diff --git a/Modules/Applications/AppDimensionalityReduction/app/otbTrainDimensionalityReduction.cxx b/Modules/Applications/AppDimensionalityReduction/app/otbTrainDimensionalityReduction.cxx index 5f94e918b360dbc1cf3245ccbcc90d70ef9bfca9..dea0331ceacd22cb5966e6d86b080e5bb45b56cc 100644 --- a/Modules/Applications/AppDimensionalityReduction/app/otbTrainDimensionalityReduction.cxx +++ b/Modules/Applications/AppDimensionalityReduction/app/otbTrainDimensionalityReduction.cxx @@ -13,19 +13,19 @@ #include <fstream> // write the model file -#include "DimensionalityReductionModelFactory.h" -#include "cbLearningApplicationBaseDR.h" +#include "otbDimensionalityReductionModelFactory.h" +#include "otbTrainDimensionalityReductionApplicationBase.h" namespace otb { namespace Wrapper { -class TrainDimensionalityReduction : public cbLearningApplicationBaseDR<float,float> +class TrainDimensionalityReduction : public TrainDimensionalityReductionApplicationBase<float,float> { public: typedef TrainDimensionalityReduction Self; - typedef cbLearningApplicationBaseDR<float, float> Superclass; + typedef TrainDimensionalityReductionApplicationBase<float, float> Superclass; typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; diff --git a/Modules/Applications/AppDimensionalityReduction/app/otbVectorDimensionalityReduction.cxx b/Modules/Applications/AppDimensionalityReduction/app/otbVectorDimensionalityReduction.cxx index 8036bcb32f3d852f1d3f11a9f45f58f1e3a2853b..43638c4207951e339c8da4534512e7d22ab9a01f 100644 --- a/Modules/Applications/AppDimensionalityReduction/app/otbVectorDimensionalityReduction.cxx +++ b/Modules/Applications/AppDimensionalityReduction/app/otbVectorDimensionalityReduction.cxx @@ -26,8 +26,7 @@ #include "otbStatisticsXMLFileReader.h" #include "itkListSample.h" #include "otbShiftScaleSampleListFilter.h" -#include "DimensionalityReductionModelFactory.h" -//#include "DimensionalityReductionModel.h" +#include "otbDimensionalityReductionModelFactory.h" #include <time.h> namespace otb diff --git a/Modules/Learning/DimensionalityReductionLearning/include/cbTrainAutoencoder.txx b/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainAutoencoder.txx similarity index 94% rename from Modules/Learning/DimensionalityReductionLearning/include/cbTrainAutoencoder.txx rename to Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainAutoencoder.txx index 0da00f85eade8f7fc758b600acdefadda197c807..dc787d5d15fe012e50026adb8a3ae1e20b086dde 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/cbTrainAutoencoder.txx +++ b/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainAutoencoder.txx @@ -2,7 +2,7 @@ #ifndef cbTrainAutoencoder_txx #define cbTrainAutoencoder_txx -#include "cbLearningApplicationBaseDR.h" +#include "otbTrainDimensionalityReductionApplicationBase.h" namespace otb { @@ -11,7 +11,7 @@ namespace Wrapper template <class TInputValue, class TOutputValue> void -cbLearningApplicationBaseDR<TInputValue,TOutputValue> +TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue> ::InitAutoencoderParams() { @@ -103,9 +103,9 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue> template <class TInputValue, class TOutputValue> void -cbLearningApplicationBaseDR<TInputValue,TOutputValue> +TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue> ::BeforeTrainAutoencoder(typename ListSampleType::Pointer trainingListSample, - std::string modelPath) + std::string modelPath) { std::string TiedWeigth = GetParameterString("model.autoencoder.istied"); std::cout << TiedWeigth << std::endl; @@ -130,8 +130,7 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue> template <class TInputValue, class TOutputValue> template <typename autoencoderchoice> -void cbLearningApplicationBaseDR<TInputValue,TOutputValue> -::TrainAutoencoder(typename ListSampleType::Pointer trainingListSample,std::string modelPath) +void TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue>::TrainAutoencoder(typename ListSampleType::Pointer trainingListSample,std::string modelPath) { typename autoencoderchoice::Pointer dimredTrainer = autoencoderchoice::New(); itk::Array<unsigned int> nb_neuron; diff --git a/Modules/Learning/DimensionalityReductionLearning/include/cbTrainPCA.txx b/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainPCA.txx similarity index 85% rename from Modules/Learning/DimensionalityReductionLearning/include/cbTrainPCA.txx rename to Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainPCA.txx index d51926469b1eadea2f01edc6faacc617e6c41770..003ebb1ccf510e81c9e848452ae4a9e4a16d793b 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/cbTrainPCA.txx +++ b/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainPCA.txx @@ -2,7 +2,7 @@ #ifndef cbTrainPCA_txx #define cbTrainPCA_txx -#include "cbLearningApplicationBaseDR.h" +#include "otbTrainDimensionalityReductionApplicationBase.h" namespace otb { @@ -11,7 +11,7 @@ namespace Wrapper template <class TInputValue, class TOutputValue> void -cbLearningApplicationBaseDR<TInputValue,TOutputValue> +TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue> ::InitPCAParams() { @@ -34,7 +34,7 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue> } template <class TInputValue, class TOutputValue> -void cbLearningApplicationBaseDR<TInputValue,TOutputValue> +void TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue> ::TrainPCA(typename ListSampleType::Pointer trainingListSample,std::string modelPath) { typename PCAModelType::Pointer dimredTrainer = PCAModelType::New(); diff --git a/Modules/Learning/DimensionalityReductionLearning/include/cbTrainSOM.txx b/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainSOM.txx similarity index 94% rename from Modules/Learning/DimensionalityReductionLearning/include/cbTrainSOM.txx rename to Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainSOM.txx index 4c6f5c89f14c76c552ae13c808ada8a818d18323..61975c9708c6ef8b112e10f20882fb60b6d7da23 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/cbTrainSOM.txx +++ b/Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainSOM.txx @@ -1,7 +1,7 @@ #ifndef cbTrainSOM_txx #define cbTrainSOM_txx -#include "cbLearningApplicationBaseDR.h" +#include "otbTrainDimensionalityReductionApplicationBase.h" namespace otb { @@ -10,7 +10,7 @@ namespace Wrapper template <class TInputValue, class TOutputValue> void -cbLearningApplicationBaseDR<TInputValue,TOutputValue> +TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue> ::InitSOMParams() { @@ -76,7 +76,7 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue> template <class TInputValue, class TOutputValue> void -cbLearningApplicationBaseDR<TInputValue,TOutputValue> +TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue> ::BeforeTrainSOM(typename ListSampleType::Pointer trainingListSample, std::string modelPath) { @@ -111,7 +111,7 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue> template <class TInputValue, class TOutputValue> template <typename somchoice> -void cbLearningApplicationBaseDR<TInputValue,TOutputValue> +void TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue> ::TrainSOM(typename ListSampleType::Pointer trainingListSample,std::string modelPath) { using TemplateEstimatorType = typename somchoice::EstimatorType; diff --git a/Modules/Applications/AppDimensionalityReduction/include/otbTrainDimensionalityReductionApplicationBase.h b/Modules/Applications/AppDimensionalityReduction/include/otbTrainDimensionalityReductionApplicationBase.h new file mode 100644 index 0000000000000000000000000000000000000000..c14bfd8ca057495d5fb34fb95536cefa8d74e913 --- /dev/null +++ b/Modules/Applications/AppDimensionalityReduction/include/otbTrainDimensionalityReductionApplicationBase.h @@ -0,0 +1,170 @@ +#ifndef cbLearningApplicationBaseDR_h +#define cbLearningApplicationBaseDR_h + +#include "otbConfigure.h" + +#include "otbWrapperApplication.h" + +#include <iostream> + +// ListSample +#include "itkListSample.h" +#include "itkVariableLengthVector.h" + +//Estimator +#include "otbDimensionalityReductionModelFactory.h" + +#include "otbSOMModel.h" + +#ifdef OTB_USE_SHARK +#include "otbAutoencoderModel.h" +#include "otbPCAModel.h" +#endif + +namespace otb +{ +namespace Wrapper +{ + +/** \class LearningApplicationBase + * \brief LearningApplicationBase is the base class for application that + * use machine learning model. + * + * This base class offers a DoInit() method to initialize all the parameters + * related to machine learning models. They will all be in the choice parameter + * named "classifier". The class also offers generic Train() and Classify() + * methods. The classes derived from LearningApplicationBase only need these + * 3 methods to handle the machine learning model. + * + * There are multiple machine learning models in OTB, some imported + * from OpenCV and one imported from LibSVM. They all have + * different parameters. The purpose of this class is to handle the + * creation of all parameters related to machine learning models (in + * DoInit() ), and to dispatch the calls to specific train functions + * in function Train(). + * + * This class is templated over scalar types for input and output values. + * Typically, the input value type will be either float of double. The choice + * of an output value type depends on the learning mode. This base class + * supports both classification and regression modes. For classification + * (enabled by default), the output value type corresponds to a class + * identifier so integer types suit well. For regression, the output value + * should not be an integer type, but rather a floating point type. In addition, + * an application deriving this base class for regression should initialize + * the m_RegressionFlag to true in their constructor. + * + * \sa TrainImagesClassifier + * \sa TrainRegression + * + * \ingroup OTBAppClassification + */ +template <class TInputValue, class TOutputValue> +class TrainDimensionalityReductionApplicationBase: public Application +{ +public: + /** Standard class typedefs. */ + typedef TrainDimensionalityReductionApplicationBase Self; + typedef Application Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Standard macro */ + itkTypeMacro(TrainDimensionalityReductionApplicationBase, otb::Application) + + typedef TInputValue InputValueType; + typedef TOutputValue OutputValueType; + + typedef otb::VectorImage<InputValueType> SampleImageType; + typedef typename SampleImageType::PixelType PixelType; + + typedef otb::DimensionalityReductionModelFactory< + InputValueType, OutputValueType> ModelFactoryType; + typedef typename ModelFactoryType::DimensionalityReductionModelTypePointer ModelPointerType; + typedef typename ModelFactoryType::DimensionalityReductionModelType ModelType; + + 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(); +~TrainDimensionalityReductionApplicationBase(); + +/** Generic method to train and save the machine learning model. This method + * uses specific train methods depending on the chosen model.*/ +void Train(typename ListSampleType::Pointer trainingListSample, + std::string modelPath); + +/** Generic method to load a model file and use it to classify a sample list*/ +void Reduce(typename ListSampleType::Pointer validationListSample, + std::string modelPath); + +/** Init method that creates all the parameters for machine learning models */ +void DoInit(); + +private: + +/** Specific Init and Train methods for each machine learning model */ +//@{ + +void InitSOMParams(); +template <class somchoice> +void TrainSOM(typename ListSampleType::Pointer trainingListSample, std::string modelPath); +void BeforeTrainSOM(typename ListSampleType::Pointer trainingListSample, std::string modelPath); + +#ifdef OTB_USE_SHARK + void InitAutoencoderParams(); + void InitPCAParams(); + + void BeforeTrainAutoencoder(typename ListSampleType::Pointer trainingListSample, std::string modelPath); + template <class autoencoderchoice> + void TrainAutoencoder(typename ListSampleType::Pointer trainingListSample, std::string modelPath); + + void TrainPCA(typename ListSampleType::Pointer trainingListSample, std::string modelPath); + + +#endif +//@} +}; + +} +} + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbTrainDimensionalityReductionApplicationBase.txx" +#include "otbDimensionalityReductionTrainSOM.txx" + +#ifdef OTB_USE_SHARK +#include "otbDimensionalityReductionTrainAutoencoder.txx" +#include "otbDimensionalityReductionTrainPCA.txx" +#endif +#endif + +#endif diff --git a/Modules/Learning/DimensionalityReductionLearning/include/cbLearningApplicationBaseDR.txx b/Modules/Applications/AppDimensionalityReduction/include/otbTrainDimensionalityReductionApplicationBase.txx similarity index 77% rename from Modules/Learning/DimensionalityReductionLearning/include/cbLearningApplicationBaseDR.txx rename to Modules/Applications/AppDimensionalityReduction/include/otbTrainDimensionalityReductionApplicationBase.txx index 19b5e4e414f98c1fb49d7d62a8f08dfc1946e8ab..04065aa97c97c045f798a6bd28fb6ff496d1fbb4 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/cbLearningApplicationBaseDR.txx +++ b/Modules/Applications/AppDimensionalityReduction/include/otbTrainDimensionalityReductionApplicationBase.txx @@ -17,7 +17,7 @@ #ifndef cbLearningApplicationBaseDR_txx #define cbLearningApplicationBaseDR_txx -#include "cbLearningApplicationBaseDR.h" +#include "otbTrainDimensionalityReductionApplicationBase.h" namespace otb { @@ -25,21 +25,21 @@ namespace Wrapper { template <class TInputValue, class TOutputValue> -cbLearningApplicationBaseDR<TInputValue,TOutputValue> -::cbLearningApplicationBaseDR() +TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue> +::TrainDimensionalityReductionApplicationBase() { } template <class TInputValue, class TOutputValue> -cbLearningApplicationBaseDR<TInputValue,TOutputValue> -::~cbLearningApplicationBaseDR() +TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue> +::~TrainDimensionalityReductionApplicationBase() { ModelFactoryType::CleanFactories(); } template <class TInputValue, class TOutputValue> void -cbLearningApplicationBaseDR<TInputValue,TOutputValue> +TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue> ::DoInit() { AddDocTag(Tags::Learning); @@ -60,14 +60,14 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue> template <class TInputValue, class TOutputValue> void -cbLearningApplicationBaseDR<TInputValue,TOutputValue> +TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue> ::Reduce(typename ListSampleType::Pointer validationListSample,std::string modelPath) { } template <class TInputValue, class TOutputValue> void -cbLearningApplicationBaseDR<TInputValue,TOutputValue> +TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue> ::Train(typename ListSampleType::Pointer trainingListSample, std::string modelPath) { @@ -84,10 +84,10 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue> if(modelName == "autoencoder") { #ifdef OTB_USE_SHARK - BeforeTrainAutoencoder(trainingListSample,modelPath); - #else - otbAppLogFATAL("Module SharkLearning is not installed. You should consider turning OTB_USE_SHARK on during cmake configuration."); - #endif + BeforeTrainAutoencoder(trainingListSample,modelPath); +#else + otbAppLogFATAL("Module SharkLearning is not installed. You should consider turning OTB_USE_SHARK on during cmake configuration."); +#endif } /* if(modelName == "tiedautoencoder") diff --git a/Modules/Learning/DimensionalityReductionLearning/include/SOMModelFactory.txx b/Modules/Learning/DimensionalityReductionLearning/include/SOMModelFactory.txx index 396a5f0ac9361aa92897b2bfb6f18f0f3a6a0630..a4ea0243b9b297539084c379b8a16e584c323c60 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/SOMModelFactory.txx +++ b/Modules/Learning/DimensionalityReductionLearning/include/SOMModelFactory.txx @@ -19,11 +19,10 @@ #define SOMFactory_txx -#include "SOMModelFactory.h" +#include "otbSOMModelFactory.h" #include "itkCreateObjectFunction.h" -#include "SOMModel.h" -//#include <shark/Algorithms/Trainers/PCA.h> +#include "otbSOMModel.h" #include "itkVersion.h" namespace otb @@ -39,8 +38,8 @@ SOMModelFactory<TInputValue,TOutputValue,MapDimension>::SOMModelFactory() subclass.c_str(), "SOM DR Model", 1, - // itk::CreateObjectFunction<AutoencoderModel<TInputValue,TOutputValue> >::New()); - itk::CreateObjectFunction<SOMModel<TInputValue, MapDimension>>::New()); + + itk::CreateObjectFunction<SOMModel<TInputValue, MapDimension>>::New()); } template <class TInputValue, class TOutputValue, unsigned int MapDimension> diff --git a/Modules/Learning/DimensionalityReductionLearning/include/cbLearningApplicationBaseDR.h b/Modules/Learning/DimensionalityReductionLearning/include/cbLearningApplicationBaseDR.h deleted file mode 100644 index 281cc1866bbcc6eb3799c8aa9b8b4abbc2b90a82..0000000000000000000000000000000000000000 --- a/Modules/Learning/DimensionalityReductionLearning/include/cbLearningApplicationBaseDR.h +++ /dev/null @@ -1,171 +0,0 @@ -#ifndef cbLearningApplicationBaseDR_h -#define cbLearningApplicationBaseDR_h - -#include "otbConfigure.h" - -#include "otbWrapperApplication.h" - -#include <iostream> - -// ListSample -#include "itkListSample.h" -#include "itkVariableLengthVector.h" - -//Estimator -#include "DimensionalityReductionModelFactory.h" - -#include "SOMModel.h" - -#ifdef OTB_USE_SHARK -#include "AutoencoderModel.h" -#include "PCAModel.h" -#endif - -namespace otb -{ -namespace Wrapper -{ - -/** \class LearningApplicationBase - * \brief LearningApplicationBase is the base class for application that - * use machine learning model. - * - * This base class offers a DoInit() method to initialize all the parameters - * related to machine learning models. They will all be in the choice parameter - * named "classifier". The class also offers generic Train() and Classify() - * methods. The classes derived from LearningApplicationBase only need these - * 3 methods to handle the machine learning model. - * - * There are multiple machine learning models in OTB, some imported - * from OpenCV and one imported from LibSVM. They all have - * different parameters. The purpose of this class is to handle the - * creation of all parameters related to machine learning models (in - * DoInit() ), and to dispatch the calls to specific train functions - * in function Train(). - * - * This class is templated over scalar types for input and output values. - * Typically, the input value type will be either float of double. The choice - * of an output value type depends on the learning mode. This base class - * supports both classification and regression modes. For classification - * (enabled by default), the output value type corresponds to a class - * identifier so integer types suit well. For regression, the output value - * should not be an integer type, but rather a floating point type. In addition, - * an application deriving this base class for regression should initialize - * the m_RegressionFlag to true in their constructor. - * - * \sa TrainImagesClassifier - * \sa TrainRegression - * - * \ingroup OTBAppClassification - */ -template <class TInputValue, class TOutputValue> -class cbLearningApplicationBaseDR: public Application -{ -public: - /** Standard class typedefs. */ - typedef cbLearningApplicationBaseDR Self; - typedef Application Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - /** Standard macro */ - itkTypeMacro(cbLearningApplicationBaseDR, otb::Application) - - typedef TInputValue InputValueType; - typedef TOutputValue OutputValueType; - - typedef otb::VectorImage<InputValueType> SampleImageType; - typedef typename SampleImageType::PixelType PixelType; - - typedef otb::DimensionalityReductionModelFactory< - InputValueType, OutputValueType> ModelFactoryType; - typedef typename ModelFactoryType::DimensionalityReductionModelTypePointer ModelPointerType; - typedef typename ModelFactoryType::DimensionalityReductionModelType ModelType; - - 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: - cbLearningApplicationBaseDR(); - - ~cbLearningApplicationBaseDR() ITK_OVERRIDE; - - /** Generic method to train and save the machine learning model. This method - * uses specific train methods depending on the chosen model.*/ - void Train(typename ListSampleType::Pointer trainingListSample, - std::string modelPath); - - /** Generic method to load a model file and use it to classify a sample list*/ - void Reduce(typename ListSampleType::Pointer validationListSample, - std::string modelPath); - - /** Init method that creates all the parameters for machine learning models */ - void DoInit(); - -private: - - /** Specific Init and Train methods for each machine learning model */ - //@{ - - void InitSOMParams(); - template <class somchoice> - void TrainSOM(typename ListSampleType::Pointer trainingListSample, std::string modelPath); - void BeforeTrainSOM(typename ListSampleType::Pointer trainingListSample, std::string modelPath); - -#ifdef OTB_USE_SHARK - void InitAutoencoderParams(); - void InitPCAParams(); - - void BeforeTrainAutoencoder(typename ListSampleType::Pointer trainingListSample, std::string modelPath); - template <class autoencoderchoice> - void TrainAutoencoder(typename ListSampleType::Pointer trainingListSample, std::string modelPath); - - void TrainPCA(typename ListSampleType::Pointer trainingListSample, std::string modelPath); - - -#endif - //@} -}; - -} -} - -#ifndef OTB_MANUAL_INSTANTIATION -#include "cbLearningApplicationBaseDR.txx" -#include "cbTrainSOM.txx" - -#ifdef OTB_USE_SHARK -#include "cbTrainAutoencoder.txx" -#include "cbTrainPCA.txx" -#endif -#endif - -#endif diff --git a/Modules/Learning/DimensionalityReductionLearning/include/AutoencoderModel.h b/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModel.h similarity index 96% rename from Modules/Learning/DimensionalityReductionLearning/include/AutoencoderModel.h rename to Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModel.h index a8cbe6c0f5608b237519d2571236d4b90decbc4f..9723a5c27a482677298bdc98188c7abd741404aa 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/AutoencoderModel.h +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModel.h @@ -16,8 +16,8 @@ class ITK_EXPORT AutoencoderModel: public MachineLearningModel<itk::VariableLen public: - typedef AutoencoderModel Self; - typedef MachineLearningModel<itk::VariableLengthVector< TInputValue> , itk::VariableLengthVector< TInputValue>> Superclass; + typedef AutoencoderModel Self; + typedef MachineLearningModel<itk::VariableLengthVector< TInputValue> , itk::VariableLengthVector< TInputValue>> Superclass; typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; @@ -131,7 +131,7 @@ private: #ifndef OTB_MANUAL_INSTANTIATION -#include "AutoencoderModel.txx" +#include "otbAutoencoderModel.txx" #endif diff --git a/Modules/Learning/DimensionalityReductionLearning/include/AutoencoderModel.txx b/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModel.txx similarity index 96% rename from Modules/Learning/DimensionalityReductionLearning/include/AutoencoderModel.txx rename to Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModel.txx index 88c77dd5aee7ebbc90893fac7a9fe5a0ca55b4b2..e95748ff3cf7a67222118a853d7d49d329d781bd 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/AutoencoderModel.txx +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModel.txx @@ -73,18 +73,18 @@ void AutoencoderModel<TInputValue,NeuronType>::Train() /// Training of the first Autoencoder (first and last layer of the FF network) if (m_Epsilon > 0){ - shark::TrainingProgress<> criterion(5,m_Epsilon); + shark::TrainingProgress<> criterion(5,m_Epsilon); - OutAutoencoderType net; - if (m_Noise[0] != 0) // Shark doesn't allow to train a layer using a sparsity term AND a noisy input. (shark::SparseAutoencoderError takes an autoen - { - TrainOneLayer(criterion,net,0 , m_NumberOfHiddenNeurons[0],m_Noise[0],m_Regularization[0], inputSamples,ofs); - } - else - { - TrainOneSparseLayer( criterion, net , 0 , m_NumberOfHiddenNeurons[0],m_Rho[0],m_Beta[0],m_Regularization[0],inputSamples, ofs); - } - criterion.reset(); + OutAutoencoderType net; + if (m_Noise[0] != 0) // Shark doesn't allow to train a layer using a sparsity term AND a noisy input. (shark::SparseAutoencoderError takes an autoen + { + TrainOneLayer(criterion,net,0 , m_NumberOfHiddenNeurons[0],m_Noise[0],m_Regularization[0], inputSamples,ofs); + } + else + { + TrainOneSparseLayer( criterion, net , 0 , m_NumberOfHiddenNeurons[0],m_Rho[0],m_Beta[0],m_Regularization[0],inputSamples, ofs); + } + criterion.reset(); } else { diff --git a/Modules/Learning/DimensionalityReductionLearning/include/AutoencoderModelFactory.h b/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModelFactory.h similarity index 97% rename from Modules/Learning/DimensionalityReductionLearning/include/AutoencoderModelFactory.h rename to Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModelFactory.h index c9c993b57e7e258e4671777ae2b0e96bee4c4b34..5eb6a501ef501d9ea4cf58e0f42149312670623b 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/AutoencoderModelFactory.h +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModelFactory.h @@ -62,7 +62,7 @@ using TiedAutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTa #ifndef OTB_MANUAL_INSTANTIATION -#include "AutoencoderModelFactory.txx" +#include "otbAutoencoderModelFactory.txx" #endif #endif diff --git a/Modules/Learning/DimensionalityReductionLearning/include/AutoencoderModelFactory.txx b/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModelFactory.txx similarity index 86% rename from Modules/Learning/DimensionalityReductionLearning/include/AutoencoderModelFactory.txx rename to Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModelFactory.txx index 47b4669ab4ad2761bd3174ac71b5d96d74b9becf..73dae93bde0e7dd05cb647a6bb8cf55bf6282ffc 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/AutoencoderModelFactory.txx +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModelFactory.txx @@ -19,10 +19,10 @@ #define AutoencoderModelFactory_txx -#include "AutoencoderModelFactory.h" +#include "otbAutoencoderModelFactory.h" #include "itkCreateObjectFunction.h" -#include "AutoencoderModel.h" +#include "otbAutoencoderModel.h" #include "itkVersion.h" namespace otb @@ -38,8 +38,8 @@ AutoencoderModelFactoryBase<TInputValue,TOutputValue, NeuronType>::AutoencoderMo subclass.c_str(), "Shark AE ML Model", 1, - // itk::CreateObjectFunction<AutoencoderModel<TInputValue,TOutputValue> >::New()); - itk::CreateObjectFunction<AutoencoderModel<TInputValue,NeuronType > >::New()); + // itk::CreateObjectFunction<AutoencoderModel<TInputValue,TOutputValue> >::New()); + itk::CreateObjectFunction<AutoencoderModel<TInputValue,NeuronType > >::New()); } template <class TInputValue, class TOutputValue, class NeuronType> diff --git a/Modules/Learning/DimensionalityReductionLearning/include/DimensionalityReductionModelFactory.h b/Modules/Learning/DimensionalityReductionLearning/include/otbDimensionalityReductionModelFactory.h similarity index 98% rename from Modules/Learning/DimensionalityReductionLearning/include/DimensionalityReductionModelFactory.h rename to Modules/Learning/DimensionalityReductionLearning/include/otbDimensionalityReductionModelFactory.h index 16fa0f416d51a0e1b39465664a698d40cb1d4069..92603c710deefe05a1d51eb7fdb7f1b922cc1a11 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/DimensionalityReductionModelFactory.h +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbDimensionalityReductionModelFactory.h @@ -78,7 +78,7 @@ private: } // end namespace otb #ifndef OTB_MANUAL_INSTANTIATION -#include "DimensionalityReductionModelFactory.txx" +#include "otbDimensionalityReductionModelFactory.txx" #endif #endif diff --git a/Modules/Learning/DimensionalityReductionLearning/include/DimensionalityReductionModelFactory.txx b/Modules/Learning/DimensionalityReductionLearning/include/otbDimensionalityReductionModelFactory.txx similarity index 86% rename from Modules/Learning/DimensionalityReductionLearning/include/DimensionalityReductionModelFactory.txx rename to Modules/Learning/DimensionalityReductionLearning/include/otbDimensionalityReductionModelFactory.txx index 130dd1362663abec152086e566c76038420246a6..775c0842dc4638576af52fe7b16d6444fff1b335 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/DimensionalityReductionModelFactory.txx +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbDimensionalityReductionModelFactory.txx @@ -18,14 +18,14 @@ #ifndef DimensionalityReductionModelFactory_txx #define DimensionalityReductionFactory_txx -#include "DimensionalityReductionModelFactory.h" +#include "otbDimensionalityReductionModelFactory.h" #include "otbConfigure.h" -#include "SOMModelFactory.h" +#include "otbSOMModelFactory.h" #ifdef OTB_USE_SHARK -#include "AutoencoderModelFactory.h" -#include "PCAModelFactory.h" +#include "otbAutoencoderModelFactory.h" +#include "otbPCAModelFactory.h" #endif #include "itkMutexLockHolder.h" @@ -34,16 +34,6 @@ namespace otb { -/* -template <class TInputValue, class TTargetValue> -// using AutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::Autoencoder<shark::TanhNeuron, shark::LinearNeuron>> ; -using AutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::Autoencoder<shark::TanhNeuron, shark::TanhNeuron>> ; - - -template <class TInputValue, class TTargetValue> -// using TiedAutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::TiedAutoencoder< shark::TanhNeuron, shark::LinearNeuron>> ; -using TiedAutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::TiedAutoencoder< shark::TanhNeuron, shark::TanhNeuron>> ; -*/ template <class TInputValue, class TTargetValue> using AutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::LogisticNeuron> ; @@ -130,7 +120,7 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue> #ifdef OTB_USE_SHARK RegisterFactory(PCAModelFactory<TInputValue,TOutputValue>::New()); RegisterFactory(AutoencoderModelFactory<TInputValue,TOutputValue>::New()); - // RegisterFactory(TiedAutoencoderModelFactory<TInputValue,TOutputValue>::New()); + // RegisterFactory(TiedAutoencoderModelFactory<TInputValue,TOutputValue>::New()); #endif } @@ -196,8 +186,7 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue> #ifdef OTB_USE_SHARK - // Autoencoder - AutoencoderModelFactory<TInputValue,TOutputValue> *aeFactory = + AutoencoderModelFactory<TInputValue,TOutputValue> *aeFactory = dynamic_cast<AutoencoderModelFactory<TInputValue,TOutputValue> *>(*itFac); if (aeFactory) { diff --git a/Modules/Learning/DimensionalityReductionLearning/include/ImageDimensionalityReductionFilter.h b/Modules/Learning/DimensionalityReductionLearning/include/otbImageDimensionalityReductionFilter.h similarity index 98% rename from Modules/Learning/DimensionalityReductionLearning/include/ImageDimensionalityReductionFilter.h rename to Modules/Learning/DimensionalityReductionLearning/include/otbImageDimensionalityReductionFilter.h index 008c57d2a4c65d77b762e262a2484d441d25d766..415dda921ccba601dac3c120900ca8ecb0448545 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/ImageDimensionalityReductionFilter.h +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbImageDimensionalityReductionFilter.h @@ -139,7 +139,7 @@ private: }; } // End namespace otb #ifndef OTB_MANUAL_INSTANTIATION -#include "ImageDimensionalityReductionFilter.txx" +#include "otbImageDimensionalityReductionFilter.txx" #endif #endif diff --git a/Modules/Learning/DimensionalityReductionLearning/include/ImageDimensionalityReductionFilter.txx b/Modules/Learning/DimensionalityReductionLearning/include/otbImageDimensionalityReductionFilter.txx similarity index 99% rename from Modules/Learning/DimensionalityReductionLearning/include/ImageDimensionalityReductionFilter.txx rename to Modules/Learning/DimensionalityReductionLearning/include/otbImageDimensionalityReductionFilter.txx index e98a0b79f753624246d732d01e60a47b43f2595a..418ecb4fa24e028cf9f9873ba53c45924801901e 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/ImageDimensionalityReductionFilter.txx +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbImageDimensionalityReductionFilter.txx @@ -18,7 +18,7 @@ #ifndef otbImageClassificationFilter_txx #define otbImageClassificationFilter_txx -#include "ImageDimensionalityReductionFilter.h" +#include "otbImageDimensionalityReductionFilter.h" #include "itkImageRegionIterator.h" #include "itkProgressReporter.h" diff --git a/Modules/Learning/DimensionalityReductionLearning/include/PCAModel.h b/Modules/Learning/DimensionalityReductionLearning/include/otbPCAModel.h similarity index 99% rename from Modules/Learning/DimensionalityReductionLearning/include/PCAModel.h rename to Modules/Learning/DimensionalityReductionLearning/include/otbPCAModel.h index 82ea0f8443a4caadc49bb6e66e91928a8cbf6a7b..e39ca88341a88c10af9828c06de5b20e87b3e75c 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/PCAModel.h +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbPCAModel.h @@ -75,7 +75,7 @@ private: #ifndef OTB_MANUAL_INSTANTIATION -#include "PCAModel.txx" +#include "otbPCAModel.txx" #endif diff --git a/Modules/Learning/DimensionalityReductionLearning/include/PCAModel.txx b/Modules/Learning/DimensionalityReductionLearning/include/otbPCAModel.txx similarity index 100% rename from Modules/Learning/DimensionalityReductionLearning/include/PCAModel.txx rename to Modules/Learning/DimensionalityReductionLearning/include/otbPCAModel.txx diff --git a/Modules/Learning/DimensionalityReductionLearning/include/PCAModelFactory.h b/Modules/Learning/DimensionalityReductionLearning/include/otbPCAModelFactory.h similarity index 97% rename from Modules/Learning/DimensionalityReductionLearning/include/PCAModelFactory.h rename to Modules/Learning/DimensionalityReductionLearning/include/otbPCAModelFactory.h index 56c0b88c6c3d85414d8f0d95b93f64047d2fbd06..a7a5d104913cd48ad10af39f379b88f470e9863b 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/PCAModelFactory.h +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbPCAModelFactory.h @@ -51,7 +51,7 @@ private: #ifndef OTB_MANUAL_INSTANTIATION -#include "PCAModelFactory.txx" +#include "otbPCAModelFactory.txx" #endif #endif diff --git a/Modules/Learning/DimensionalityReductionLearning/include/PCAModelFactory.txx b/Modules/Learning/DimensionalityReductionLearning/include/otbPCAModelFactory.txx similarity index 85% rename from Modules/Learning/DimensionalityReductionLearning/include/PCAModelFactory.txx rename to Modules/Learning/DimensionalityReductionLearning/include/otbPCAModelFactory.txx index bfaa4f6f624b12d8351defb1bc52ad9a4d37253e..d7a06e94dc9803db09c2a778392281e62f59d70e 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/PCAModelFactory.txx +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbPCAModelFactory.txx @@ -19,11 +19,10 @@ #define PCAFactory_txx -#include "PCAModelFactory.h" +#include "otbPCAModelFactory.h" #include "itkCreateObjectFunction.h" -#include "PCAModel.h" -//#include <shark/Algorithms/Trainers/PCA.h> +#include "otbPCAModel.h" #include "itkVersion.h" namespace otb @@ -39,8 +38,7 @@ PCAModelFactory<TInputValue,TOutputValue>::PCAModelFactory() subclass.c_str(), "Shark PCA ML Model", 1, - // itk::CreateObjectFunction<AutoencoderModel<TInputValue,TOutputValue> >::New()); - itk::CreateObjectFunction<PCAModel<TInputValue>>::New()); + itk::CreateObjectFunction<PCAModel<TInputValue>>::New()); } template <class TInputValue, class TOutputValue> diff --git a/Modules/Learning/DimensionalityReductionLearning/include/SOMModel.h b/Modules/Learning/DimensionalityReductionLearning/include/otbSOMModel.h similarity index 99% rename from Modules/Learning/DimensionalityReductionLearning/include/SOMModel.h rename to Modules/Learning/DimensionalityReductionLearning/include/otbSOMModel.h index c9553cd9c37e76d2a9c271c72c12caa4b0bd60b3..06307b0b8da3fa1aa6e7459ed4f1806f0f0257cf 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/SOMModel.h +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbSOMModel.h @@ -132,7 +132,7 @@ private: #ifndef OTB_MANUAL_INSTANTIATION -#include "SOMModel.txx" +#include "otbSOMModel.txx" #endif diff --git a/Modules/Learning/DimensionalityReductionLearning/include/SOMModel.txx b/Modules/Learning/DimensionalityReductionLearning/include/otbSOMModel.txx similarity index 100% rename from Modules/Learning/DimensionalityReductionLearning/include/SOMModel.txx rename to Modules/Learning/DimensionalityReductionLearning/include/otbSOMModel.txx diff --git a/Modules/Learning/DimensionalityReductionLearning/include/SOMModelFactory.h b/Modules/Learning/DimensionalityReductionLearning/include/otbSOMModelFactory.h similarity index 100% rename from Modules/Learning/DimensionalityReductionLearning/include/SOMModelFactory.h rename to Modules/Learning/DimensionalityReductionLearning/include/otbSOMModelFactory.h