diff --git a/app/cbDimensionalityReductionTrainer.cxx b/app/cbDimensionalityReductionTrainer.cxx index dd245a44e5134d07fd4d710f3dd2b8ea71c605b3..0f085d4c498a9d59cf0ff4d763561523771c0afb 100644 --- a/app/cbDimensionalityReductionTrainer.cxx +++ b/app/cbDimensionalityReductionTrainer.cxx @@ -9,7 +9,7 @@ #include "otbShiftScaleSampleListFilter.h" #include "otbStatisticsXMLFileReader.h" -#include "otbSharkUtils.h" +//#include "otbSharkUtils.h" #include <fstream> // write the model file diff --git a/include/AutoencoderModel.txx b/include/AutoencoderModel.txx index b415e3d1d07a171f5c3ba0f307331a433ca8c4d8..a23adb9ba219bd0140cf531796a4267f1eeb58ad 100644 --- a/include/AutoencoderModel.txx +++ b/include/AutoencoderModel.txx @@ -1,4 +1,3 @@ - #ifndef AutoencoderModel_txx #define AutoencoderModel_txx diff --git a/include/DimensionalityReductionModelFactory.h b/include/DimensionalityReductionModelFactory.h index e7a913cc07d89c379a4939e69203d4358bc50fdb..791199b5e8d976ae16655c5de48b2d12ee4c666e 100644 --- a/include/DimensionalityReductionModelFactory.h +++ b/include/DimensionalityReductionModelFactory.h @@ -20,7 +20,7 @@ #include "DimensionalityReductionModel.h" #include "otbMachineLearningModelFactoryBase.h" - + namespace otb { /** \class MachineLearningModelFactory diff --git a/include/DimensionalityReductionModelFactory.txx b/include/DimensionalityReductionModelFactory.txx index 5ccf34a3889b0c625f993ebf995aa639de8c87b8..a546978fb789ff69762d8dffea815090dd688240 100644 --- a/include/DimensionalityReductionModelFactory.txx +++ b/include/DimensionalityReductionModelFactory.txx @@ -22,25 +22,25 @@ #include "otbConfigure.h" #include "SOMModelFactory.h" - +/* #ifdef OTB_USE_SHARK #include "AutoencoderModelFactory.h" #include "PCAModelFactory.h" #endif - +*/ #include "itkMutexLockHolder.h" namespace otb { - +/* template <class TInputValue, class TTargetValue> using AutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::Autoencoder<shark::TanhNeuron, shark::LinearNeuron>> ; template <class TInputValue, class TTargetValue> using TiedAutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::TiedAutoencoder< shark::TanhNeuron, shark::LinearNeuron>> ; - +*/ template <class TInputValue, class TTargetValue> using SOM2DModelFactory = SOMModelFactory<TInputValue, TTargetValue, 2> ; @@ -115,13 +115,13 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue> RegisterFactory(SOM3DModelFactory<TInputValue,TOutputValue>::New()); RegisterFactory(SOM4DModelFactory<TInputValue,TOutputValue>::New()); RegisterFactory(SOM5DModelFactory<TInputValue,TOutputValue>::New()); - + /* #ifdef OTB_USE_SHARK RegisterFactory(PCAModelFactory<TInputValue,TOutputValue>::New()); RegisterFactory(AutoencoderModelFactory<TInputValue,TOutputValue>::New()); RegisterFactory(TiedAutoencoderModelFactory<TInputValue,TOutputValue>::New()); #endif - + */ } template <class TInputValue, class TOutputValue> @@ -182,6 +182,7 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue> itk::ObjectFactoryBase::UnRegisterFactory(som2dFactory); continue; } + /* #ifdef OTB_USE_SHARK // Autoencoder @@ -210,7 +211,7 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue> continue; } #endif - +*/ } } diff --git a/include/SOMModel.h b/include/SOMModel.h index 290ee45c6050e28c7c6f4169c3f723ede44e6c75..846b0f2a2eb4c7f4112117019261cb870890fb5b 100644 --- a/include/SOMModel.h +++ b/include/SOMModel.h @@ -1,7 +1,7 @@ #ifndef SOMModel_h #define SOMModel_h -#include "DimensionalityReductionModel.h" +//#include "DimensionalityReductionModel.h" #include "otbSOMMap.h" #include "otbSOM.h" @@ -11,38 +11,45 @@ #include "otbCzihoSOMLearningBehaviorFunctor.h" #include "otbCzihoSOMNeighborhoodBehaviorFunctor.h" - +#include "otbMachineLearningModelTraits.h" +#include "otbMachineLearningModel.h" namespace otb { template <class TInputValue, unsigned int MapDimension> -class ITK_EXPORT SOMModel: public DimensionalityReductionModel<TInputValue,TInputValue> +class ITK_EXPORT SOMModel: public MachineLearningModel<itk::VariableLengthVector< TInputValue> , itk::VariableLengthVector< TInputValue>> { public: typedef SOMModel Self; - typedef DimensionalityReductionModel<TInputValue,TInputValue> Superclass; + typedef MachineLearningModel<itk::VariableLengthVector< TInputValue> , itk::VariableLengthVector< TInputValue>> Superclass; typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; - typedef typename Superclass::InputValueType InputValueType; - typedef typename Superclass::InputSampleType InputSampleType; - typedef typename Superclass::InputListSampleType InputListSampleType; - typedef typename InputListSampleType::Pointer ListSamplePointerType; - typedef typename Superclass::TargetValueType TargetValueType; - typedef typename Superclass::TargetSampleType TargetSampleType; - typedef typename Superclass::TargetListSampleType TargetListSampleType; + typedef typename Superclass::InputValueType InputValueType; + typedef typename Superclass::InputSampleType InputSampleType; + typedef typename Superclass::InputListSampleType InputListSampleType; + typedef typename InputListSampleType::Pointer ListSamplePointerType; + typedef typename Superclass::TargetValueType TargetValueType; + typedef typename Superclass::TargetSampleType TargetSampleType; + typedef typename Superclass::TargetListSampleType TargetListSampleType; - typedef SOMMap<itk::VariableLengthVector<TInputValue>,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, MapDimension> MapType; - typedef typename MapType::SizeType SizeType; - typedef typename MapType::SpacingType SpacingType; + /// Confidence map related typedefs - typedef otb::SOM<InputListSampleType, MapType> EstimatorType; + typedef typename Superclass::ConfidenceValueType ConfidenceValueType; + typedef typename Superclass::ConfidenceSampleType ConfidenceSampleType; + typedef typename Superclass::ConfidenceListSampleType ConfidenceListSampleType; - - typedef Functor::CzihoSOMLearningBehaviorFunctor SOMLearningBehaviorFunctorType; - typedef Functor::CzihoSOMNeighborhoodBehaviorFunctor SOMNeighborhoodBehaviorFunctorType; + + + typedef SOMMap<itk::VariableLengthVector<TInputValue>,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, MapDimension> MapType; + typedef typename MapType::SizeType SizeType; + typedef typename MapType::SpacingType SpacingType; + typedef otb::SOM<InputListSampleType, MapType> EstimatorType; + + typedef Functor::CzihoSOMLearningBehaviorFunctor SOMLearningBehaviorFunctorType; + typedef Functor::CzihoSOMNeighborhoodBehaviorFunctor SOMNeighborhoodBehaviorFunctorType; itkNewMacro(Self); itkTypeMacro(SOMModel, DimensionalityReductionModel); @@ -72,8 +79,8 @@ public: bool CanReadFile(const std::string & filename); bool CanWriteFile(const std::string & filename); - void Save(const std::string & filename, const std::string & name="") ITK_OVERRIDE; - void Load(const std::string & filename, const std::string & name="") ITK_OVERRIDE; + void Save(const std::string & filename, const std::string & name="") ; + void Load(const std::string & filename, const std::string & name="") ; void Train() ITK_OVERRIDE; //void Dimensionality_reduction() {}; // Dimensionality reduction is done by DoPredict @@ -83,11 +90,10 @@ protected: SOMModel(); ~SOMModel() ITK_OVERRIDE; - virtual TargetSampleType DoPredict(const InputSampleType& input) const ITK_OVERRIDE; - private: typename MapType::Pointer m_SOMMap; - + + virtual TargetSampleType DoPredict(const InputSampleType& input, ConfidenceValueType * quality = ITK_NULLPTR) const; /** Map Parameters used for training */ diff --git a/include/SOMModel.txx b/include/SOMModel.txx index 13765ccbfb0ea26c4ae8435ae00e8c6244ca5c3c..29e226f4dab4cc39c59ca0af02e90a25a4c3e65c 100644 --- a/include/SOMModel.txx +++ b/include/SOMModel.txx @@ -1,4 +1,3 @@ - #ifndef SOMModel_txx #define SOMModel_txx @@ -177,7 +176,7 @@ void SOMModel<TInputValue, MapDimension>::Load(const std::string & filename, con template <class TInputValue, unsigned int MapDimension> typename SOMModel<TInputValue, MapDimension>::TargetSampleType -SOMModel<TInputValue, MapDimension>::DoPredict(const InputSampleType & value) const +SOMModel<TInputValue, MapDimension>::DoPredict(const InputSampleType & value, ConfidenceValueType * quality) const { unsigned int dimension =MapType::ImageDimension; TargetSampleType target; diff --git a/include/cbLearningApplicationBaseDR.h b/include/cbLearningApplicationBaseDR.h index a45024aa47562da1e9cf3ae306d3a2f9dbd8616a..71c31f40fe02224cb96acdd74753fb1d8c94553a 100644 --- a/include/cbLearningApplicationBaseDR.h +++ b/include/cbLearningApplicationBaseDR.h @@ -15,12 +15,12 @@ #include "DimensionalityReductionModelFactory.h" #include "SOMModel.h" - +/* #ifdef OTB_USE_SHARK #include "AutoencoderModel.h" #include "PCAModel.h" #endif - +*/ namespace otb { namespace Wrapper @@ -99,7 +99,7 @@ public: typedef SOMMap<itk::VariableLengthVector<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 otb::AutoencoderModel<InputValueType, AutoencoderType> AutoencoderModelType; @@ -109,7 +109,7 @@ public: typedef otb::PCAModel<InputValueType> PCAModelType; #endif - + */ protected: cbLearningApplicationBaseDR(); @@ -131,11 +131,15 @@ 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 InitSOMParams(); void BeforeTrainAutoencoder(typename ListSampleType::Pointer trainingListSample, std::string modelPath); template <class autoencoderchoice> @@ -143,10 +147,8 @@ private: void TrainPCA(typename ListSampleType::Pointer trainingListSample, std::string modelPath); - template <class somchoice> - void TrainSOM(typename ListSampleType::Pointer trainingListSample, std::string modelPath); - void BeforeTrainSOM(typename ListSampleType::Pointer trainingListSample, std::string modelPath); -#endif + +#endif */ //@} }; @@ -156,10 +158,11 @@ private: #ifndef OTB_MANUAL_INSTANTIATION #include "cbLearningApplicationBaseDR.txx" #include "cbTrainSOM.txx" +/* #ifdef OTB_USE_SHARK #include "cbTrainAutoencoder.txx" #include "cbTrainPCA.txx" -#endif +#endif*/ #endif #endif diff --git a/include/cbLearningApplicationBaseDR.txx b/include/cbLearningApplicationBaseDR.txx index 5603cca4f612fa44e6d203d778d541e0b1c06056..2befe3e396123375b3db1f30b979e3c7c78cfd60 100644 --- a/include/cbLearningApplicationBaseDR.txx +++ b/include/cbLearningApplicationBaseDR.txx @@ -50,11 +50,12 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue> InitSOMParams(); + /* #ifdef OTB_USE_SHARK InitAutoencoderParams(); InitPCAParams(); #endif - + */ } template <class TInputValue, class TOutputValue> @@ -79,7 +80,7 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue> { BeforeTrainSOM(trainingListSample,modelPath); } - + /* if(modelName == "autoencoder") { #ifdef OTB_USE_SHARK @@ -104,7 +105,7 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue> #else otbAppLogFATAL("Module SharkLearning is not installed. You should consider turning OTB_USE_SHARK on during cmake configuration."); #endif - } + }*/ } } diff --git a/otb-module.cmake b/otb-module.cmake index f4a7c8f8cab47d1b8ab0ec5a3a9af4f91e07bdd7..258fdf1c4476abcf4626b043c0c9c8c78db847c8 100644 --- a/otb-module.cmake +++ b/otb-module.cmake @@ -6,9 +6,9 @@ otb_module(CbDimensionalityReduction OTBITK OTBShark OTBBoost - OTBSupervised OTBAppClassification OTBSOM + OTBLearningBase DESCRIPTION "${DOCUMENTATION}" )