Commit a30fb6f2 authored by Cédric Traizet's avatar Cédric Traizet
Browse files

som is now a machine learning model, ae and pca have been deactiveted

No related merge requests found
Showing with 59 additions and 50 deletions
+59 -50
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "otbShiftScaleSampleListFilter.h" #include "otbShiftScaleSampleListFilter.h"
#include "otbStatisticsXMLFileReader.h" #include "otbStatisticsXMLFileReader.h"
#include "otbSharkUtils.h" //#include "otbSharkUtils.h"
#include <fstream> // write the model file #include <fstream> // write the model file
......
#ifndef AutoencoderModel_txx #ifndef AutoencoderModel_txx
#define AutoencoderModel_txx #define AutoencoderModel_txx
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "DimensionalityReductionModel.h" #include "DimensionalityReductionModel.h"
#include "otbMachineLearningModelFactoryBase.h" #include "otbMachineLearningModelFactoryBase.h"
namespace otb namespace otb
{ {
/** \class MachineLearningModelFactory /** \class MachineLearningModelFactory
......
...@@ -22,25 +22,25 @@ ...@@ -22,25 +22,25 @@
#include "otbConfigure.h" #include "otbConfigure.h"
#include "SOMModelFactory.h" #include "SOMModelFactory.h"
/*
#ifdef OTB_USE_SHARK #ifdef OTB_USE_SHARK
#include "AutoencoderModelFactory.h" #include "AutoencoderModelFactory.h"
#include "PCAModelFactory.h" #include "PCAModelFactory.h"
#endif #endif
*/
#include "itkMutexLockHolder.h" #include "itkMutexLockHolder.h"
namespace otb namespace otb
{ {
/*
template <class TInputValue, class TTargetValue> 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::LinearNeuron>> ;
template <class TInputValue, class TTargetValue> 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::LinearNeuron>> ;
*/
template <class TInputValue, class TTargetValue> template <class TInputValue, class TTargetValue>
using SOM2DModelFactory = SOMModelFactory<TInputValue, TTargetValue, 2> ; using SOM2DModelFactory = SOMModelFactory<TInputValue, TTargetValue, 2> ;
...@@ -115,13 +115,13 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue> ...@@ -115,13 +115,13 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue>
RegisterFactory(SOM3DModelFactory<TInputValue,TOutputValue>::New()); RegisterFactory(SOM3DModelFactory<TInputValue,TOutputValue>::New());
RegisterFactory(SOM4DModelFactory<TInputValue,TOutputValue>::New()); RegisterFactory(SOM4DModelFactory<TInputValue,TOutputValue>::New());
RegisterFactory(SOM5DModelFactory<TInputValue,TOutputValue>::New()); RegisterFactory(SOM5DModelFactory<TInputValue,TOutputValue>::New());
/*
#ifdef OTB_USE_SHARK #ifdef OTB_USE_SHARK
RegisterFactory(PCAModelFactory<TInputValue,TOutputValue>::New()); RegisterFactory(PCAModelFactory<TInputValue,TOutputValue>::New());
RegisterFactory(AutoencoderModelFactory<TInputValue,TOutputValue>::New()); RegisterFactory(AutoencoderModelFactory<TInputValue,TOutputValue>::New());
RegisterFactory(TiedAutoencoderModelFactory<TInputValue,TOutputValue>::New()); RegisterFactory(TiedAutoencoderModelFactory<TInputValue,TOutputValue>::New());
#endif #endif
*/
} }
template <class TInputValue, class TOutputValue> template <class TInputValue, class TOutputValue>
...@@ -182,6 +182,7 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue> ...@@ -182,6 +182,7 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue>
itk::ObjectFactoryBase::UnRegisterFactory(som2dFactory); itk::ObjectFactoryBase::UnRegisterFactory(som2dFactory);
continue; continue;
} }
/*
#ifdef OTB_USE_SHARK #ifdef OTB_USE_SHARK
// Autoencoder // Autoencoder
...@@ -210,7 +211,7 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue> ...@@ -210,7 +211,7 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue>
continue; continue;
} }
#endif #endif
*/
} }
} }
......
#ifndef SOMModel_h #ifndef SOMModel_h
#define SOMModel_h #define SOMModel_h
#include "DimensionalityReductionModel.h" //#include "DimensionalityReductionModel.h"
#include "otbSOMMap.h" #include "otbSOMMap.h"
#include "otbSOM.h" #include "otbSOM.h"
...@@ -11,38 +11,45 @@ ...@@ -11,38 +11,45 @@
#include "otbCzihoSOMLearningBehaviorFunctor.h" #include "otbCzihoSOMLearningBehaviorFunctor.h"
#include "otbCzihoSOMNeighborhoodBehaviorFunctor.h" #include "otbCzihoSOMNeighborhoodBehaviorFunctor.h"
#include "otbMachineLearningModelTraits.h"
#include "otbMachineLearningModel.h"
namespace otb namespace otb
{ {
template <class TInputValue, unsigned int MapDimension> 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: public:
typedef SOMModel Self; 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<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer; typedef itk::SmartPointer<const Self> ConstPointer;
typedef typename Superclass::InputValueType InputValueType; typedef typename Superclass::InputValueType InputValueType;
typedef typename Superclass::InputSampleType InputSampleType; typedef typename Superclass::InputSampleType InputSampleType;
typedef typename Superclass::InputListSampleType InputListSampleType; typedef typename Superclass::InputListSampleType InputListSampleType;
typedef typename InputListSampleType::Pointer ListSamplePointerType; typedef typename InputListSampleType::Pointer ListSamplePointerType;
typedef typename Superclass::TargetValueType TargetValueType; typedef typename Superclass::TargetValueType TargetValueType;
typedef typename Superclass::TargetSampleType TargetSampleType; typedef typename Superclass::TargetSampleType TargetSampleType;
typedef typename Superclass::TargetListSampleType TargetListSampleType; typedef typename Superclass::TargetListSampleType TargetListSampleType;
typedef SOMMap<itk::VariableLengthVector<TInputValue>,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, MapDimension> MapType; /// Confidence map related typedefs
typedef typename MapType::SizeType SizeType;
typedef typename MapType::SpacingType SpacingType;
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); itkNewMacro(Self);
itkTypeMacro(SOMModel, DimensionalityReductionModel); itkTypeMacro(SOMModel, DimensionalityReductionModel);
...@@ -72,8 +79,8 @@ public: ...@@ -72,8 +79,8 @@ public:
bool CanReadFile(const std::string & filename); bool CanReadFile(const std::string & filename);
bool CanWriteFile(const std::string & filename); bool CanWriteFile(const std::string & filename);
void Save(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="") ITK_OVERRIDE; void Load(const std::string & filename, const std::string & name="") ;
void Train() ITK_OVERRIDE; void Train() ITK_OVERRIDE;
//void Dimensionality_reduction() {}; // Dimensionality reduction is done by DoPredict //void Dimensionality_reduction() {}; // Dimensionality reduction is done by DoPredict
...@@ -83,11 +90,10 @@ protected: ...@@ -83,11 +90,10 @@ protected:
SOMModel(); SOMModel();
~SOMModel() ITK_OVERRIDE; ~SOMModel() ITK_OVERRIDE;
virtual TargetSampleType DoPredict(const InputSampleType& input) const ITK_OVERRIDE;
private: private:
typename MapType::Pointer m_SOMMap; typename MapType::Pointer m_SOMMap;
virtual TargetSampleType DoPredict(const InputSampleType& input, ConfidenceValueType * quality = ITK_NULLPTR) const;
/** Map Parameters used for training */ /** Map Parameters used for training */
......
#ifndef SOMModel_txx #ifndef SOMModel_txx
#define SOMModel_txx #define SOMModel_txx
...@@ -177,7 +176,7 @@ void SOMModel<TInputValue, MapDimension>::Load(const std::string & filename, con ...@@ -177,7 +176,7 @@ void SOMModel<TInputValue, MapDimension>::Load(const std::string & filename, con
template <class TInputValue, unsigned int MapDimension> template <class TInputValue, unsigned int MapDimension>
typename SOMModel<TInputValue, MapDimension>::TargetSampleType 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; unsigned int dimension =MapType::ImageDimension;
TargetSampleType target; TargetSampleType target;
......
...@@ -15,12 +15,12 @@ ...@@ -15,12 +15,12 @@
#include "DimensionalityReductionModelFactory.h" #include "DimensionalityReductionModelFactory.h"
#include "SOMModel.h" #include "SOMModel.h"
/*
#ifdef OTB_USE_SHARK #ifdef OTB_USE_SHARK
#include "AutoencoderModel.h" #include "AutoencoderModel.h"
#include "PCAModel.h" #include "PCAModel.h"
#endif #endif
*/
namespace otb namespace otb
{ {
namespace Wrapper namespace Wrapper
...@@ -99,7 +99,7 @@ public: ...@@ -99,7 +99,7 @@ public:
typedef SOMMap<itk::VariableLengthVector<TInputValue>,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 5> Map5DType; typedef SOMMap<itk::VariableLengthVector<TInputValue>,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 5> Map5DType;
typedef otb::SOMModel<InputValueType, 5> SOM5DModelType; typedef otb::SOMModel<InputValueType, 5> SOM5DModelType;
/*
#ifdef OTB_USE_SHARK #ifdef OTB_USE_SHARK
typedef shark::Autoencoder< shark::TanhNeuron, shark::LinearNeuron> AutoencoderType; typedef shark::Autoencoder< shark::TanhNeuron, shark::LinearNeuron> AutoencoderType;
typedef otb::AutoencoderModel<InputValueType, AutoencoderType> AutoencoderModelType; typedef otb::AutoencoderModel<InputValueType, AutoencoderType> AutoencoderModelType;
...@@ -109,7 +109,7 @@ public: ...@@ -109,7 +109,7 @@ public:
typedef otb::PCAModel<InputValueType> PCAModelType; typedef otb::PCAModel<InputValueType> PCAModelType;
#endif #endif
*/
protected: protected:
cbLearningApplicationBaseDR(); cbLearningApplicationBaseDR();
...@@ -131,11 +131,15 @@ private: ...@@ -131,11 +131,15 @@ private:
/** Specific Init and Train methods for each machine learning model */ /** 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 #ifdef OTB_USE_SHARK
void InitAutoencoderParams(); void InitAutoencoderParams();
void InitPCAParams(); void InitPCAParams();
void InitSOMParams();
void BeforeTrainAutoencoder(typename ListSampleType::Pointer trainingListSample, std::string modelPath); void BeforeTrainAutoencoder(typename ListSampleType::Pointer trainingListSample, std::string modelPath);
template <class autoencoderchoice> template <class autoencoderchoice>
...@@ -143,10 +147,8 @@ private: ...@@ -143,10 +147,8 @@ private:
void TrainPCA(typename ListSampleType::Pointer trainingListSample, std::string modelPath); void TrainPCA(typename ListSampleType::Pointer trainingListSample, std::string modelPath);
template <class somchoice>
void TrainSOM(typename ListSampleType::Pointer trainingListSample, std::string modelPath); #endif */
void BeforeTrainSOM(typename ListSampleType::Pointer trainingListSample, std::string modelPath);
#endif
//@} //@}
}; };
...@@ -156,10 +158,11 @@ private: ...@@ -156,10 +158,11 @@ private:
#ifndef OTB_MANUAL_INSTANTIATION #ifndef OTB_MANUAL_INSTANTIATION
#include "cbLearningApplicationBaseDR.txx" #include "cbLearningApplicationBaseDR.txx"
#include "cbTrainSOM.txx" #include "cbTrainSOM.txx"
/*
#ifdef OTB_USE_SHARK #ifdef OTB_USE_SHARK
#include "cbTrainAutoencoder.txx" #include "cbTrainAutoencoder.txx"
#include "cbTrainPCA.txx" #include "cbTrainPCA.txx"
#endif #endif*/
#endif #endif
#endif #endif
...@@ -50,11 +50,12 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue> ...@@ -50,11 +50,12 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue>
InitSOMParams(); InitSOMParams();
/*
#ifdef OTB_USE_SHARK #ifdef OTB_USE_SHARK
InitAutoencoderParams(); InitAutoencoderParams();
InitPCAParams(); InitPCAParams();
#endif #endif
*/
} }
template <class TInputValue, class TOutputValue> template <class TInputValue, class TOutputValue>
...@@ -79,7 +80,7 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue> ...@@ -79,7 +80,7 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue>
{ {
BeforeTrainSOM(trainingListSample,modelPath); BeforeTrainSOM(trainingListSample,modelPath);
} }
/*
if(modelName == "autoencoder") if(modelName == "autoencoder")
{ {
#ifdef OTB_USE_SHARK #ifdef OTB_USE_SHARK
...@@ -104,7 +105,7 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue> ...@@ -104,7 +105,7 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue>
#else #else
otbAppLogFATAL("Module SharkLearning is not installed. You should consider turning OTB_USE_SHARK on during cmake configuration."); otbAppLogFATAL("Module SharkLearning is not installed. You should consider turning OTB_USE_SHARK on during cmake configuration.");
#endif #endif
} }*/
} }
} }
......
...@@ -6,9 +6,9 @@ otb_module(CbDimensionalityReduction ...@@ -6,9 +6,9 @@ otb_module(CbDimensionalityReduction
OTBITK OTBITK
OTBShark OTBShark
OTBBoost OTBBoost
OTBSupervised
OTBAppClassification OTBAppClassification
OTBSOM OTBSOM
OTBLearningBase
DESCRIPTION DESCRIPTION
"${DOCUMENTATION}" "${DOCUMENTATION}"
) )
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment