From d5ed9ebb5054f9f451f72419bda4c35a314beece Mon Sep 17 00:00:00 2001 From: Guillaume Pasero <guillaume.pasero@c-s.fr> Date: Tue, 5 Dec 2017 12:05:07 +0100 Subject: [PATCH] STYLE: use OTB coding style --- .../include/otbAutoencoderModelFactory.h | 20 +------- .../include/otbAutoencoderModelFactory.txx | 20 ++++---- .../otbDimensionalityReductionModelFactory.h | 4 -- ...otbDimensionalityReductionModelFactory.txx | 51 +++++-------------- .../otbImageDimensionalityReductionFilter.h | 1 - .../otbImageDimensionalityReductionFilter.txx | 49 +++++++----------- 6 files changed, 41 insertions(+), 104 deletions(-) diff --git a/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModelFactory.h b/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModelFactory.h index eacd2901ef..a9b0065e8c 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModelFactory.h +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModelFactory.h @@ -20,15 +20,12 @@ #ifndef otbAutoencoderModelFactory_h #define otbAutoencoderModelFactory_h - -//#include <shark/Models/TiedAutoencoder.h> -//#include <shark/Models/Autoencoder.h> #include "itkObjectFactoryBase.h" #include "itkImageIOBase.h" namespace otb { - + template <class TInputValue, class TTargetValue, class NeuronType> class ITK_EXPORT AutoencoderModelFactory : public itk::ObjectFactoryBase { @@ -63,27 +60,12 @@ protected: private: AutoencoderModelFactory(const Self &); //purposely not implemented void operator =(const Self&); //purposely not implemented - }; - - -/* -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>> ; -*/ - } //namespace otb - #ifndef OTB_MANUAL_INSTANTIATION #include "otbAutoencoderModelFactory.txx" #endif #endif - - diff --git a/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModelFactory.txx b/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModelFactory.txx index 0d66ea86e0..c55f718a62 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModelFactory.txx +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModelFactory.txx @@ -20,7 +20,6 @@ #ifndef otbAutoencoderModelFactory_txx #define otbAutoencoderModelFactory_txx - #include "otbAutoencoderModelFactory.h" #include "otbAutoencoderModel.h" @@ -32,16 +31,15 @@ namespace otb template <class TInputValue, class TOutputValue, class NeuronType> AutoencoderModelFactory<TInputValue,TOutputValue, NeuronType>::AutoencoderModelFactory() { - std::string classOverride = std::string("DimensionalityReductionModel"); std::string subclass = std::string("AutoencoderModel"); - this->RegisterOverride(classOverride.c_str(), - subclass.c_str(), - "Shark AE ML Model", - 1, - // itk::CreateObjectFunction<AutoencoderModel<TInputValue,TOutputValue> >::New()); - itk::CreateObjectFunction<AutoencoderModel<TInputValue,NeuronType > >::New()); + this->RegisterOverride( + classOverride.c_str(), + subclass.c_str(), + "Shark AE ML Model", + 1, + itk::CreateObjectFunction<AutoencoderModel<TInputValue,NeuronType > >::New()); } template <class TInputValue, class TOutputValue, class NeuronType> @@ -50,13 +48,15 @@ AutoencoderModelFactory<TInputValue,TOutputValue, NeuronType>::~AutoencoderModel } template <class TInputValue, class TOutputValue, class NeuronType> -const char* AutoencoderModelFactory<TInputValue,TOutputValue, NeuronType>::GetITKSourceVersion(void) const +const char* +AutoencoderModelFactory<TInputValue,TOutputValue, NeuronType>::GetITKSourceVersion(void) const { return ITK_SOURCE_VERSION; } template <class TInputValue, class TOutputValue, class NeuronType> -const char* AutoencoderModelFactory<TInputValue,TOutputValue, NeuronType>::GetDescription() const +const char* +AutoencoderModelFactory<TInputValue,TOutputValue, NeuronType>::GetDescription() const { return "Autoencoder model factory"; } diff --git a/Modules/Learning/DimensionalityReductionLearning/include/otbDimensionalityReductionModelFactory.h b/Modules/Learning/DimensionalityReductionLearning/include/otbDimensionalityReductionModelFactory.h index 21c1d8a04a..a96235ccb9 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/otbDimensionalityReductionModelFactory.h +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbDimensionalityReductionModelFactory.h @@ -20,9 +20,7 @@ #ifndef otbDimensionalityReductionModelFactory_h #define otbDimensionalityReductionModelFactory_h -//#include "DimensionalityReductionModel.h" #include "otbMachineLearningModelFactoryBase.h" - #include "otbMachineLearningModel.h" namespace otb @@ -54,7 +52,6 @@ public: /** Mode in which the files is intended to be used */ typedef enum { ReadMode, WriteMode } FileModeType; - /** Create the appropriate MachineLearningModel depending on the particulars of the file. */ static DimensionalityReductionModelTypePointer CreateDimensionalityReductionModel(const std::string& path, FileModeType mode); @@ -74,7 +71,6 @@ private: /** Register a single factory, ensuring it has not been registered * twice */ static void RegisterFactory(itk::ObjectFactoryBase * factory); - }; } // end namespace otb diff --git a/Modules/Learning/DimensionalityReductionLearning/include/otbDimensionalityReductionModelFactory.txx b/Modules/Learning/DimensionalityReductionLearning/include/otbDimensionalityReductionModelFactory.txx index 65280436ca..f289ab83d9 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/otbDimensionalityReductionModelFactory.txx +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbDimensionalityReductionModelFactory.txx @@ -32,15 +32,12 @@ #include "itkMutexLockHolder.h" - namespace otb { - template <class TInputValue, class TTargetValue> using LogAutoencoderModelFactory = AutoencoderModelFactory<TInputValue, TTargetValue, shark::LogisticNeuron> ; - template <class TInputValue, class TTargetValue> using SOM2DModelFactory = SOMModelFactory<TInputValue, TTargetValue, 2> ; @@ -55,7 +52,7 @@ using SOM5DModelFactory = SOMModelFactory<TInputValue, TTargetValue, 5> ; template <class TInputValue, class TOutputValue> -typename MachineLearningModel<itk::VariableLengthVector< TInputValue> , itk::VariableLengthVector< TOutputValue>>::Pointer +typename MachineLearningModel<itk::VariableLengthVector< TInputValue>, itk::VariableLengthVector< TOutputValue> >::Pointer DimensionalityReductionModelFactory<TInputValue,TOutputValue> ::CreateDimensionalityReductionModel(const std::string& path, FileModeType mode) { @@ -64,7 +61,7 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue> std::list<DimensionalityReductionModelTypePointer> possibleDimensionalityReductionModel; std::list<LightObject::Pointer> allobjects = itk::ObjectFactoryBase::CreateAllInstance("DimensionalityReductionModel"); - + for(std::list<LightObject::Pointer>::iterator i = allobjects.begin(); i != allobjects.end(); ++i) { @@ -75,19 +72,17 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue> } else { - std::cerr << "Error DimensionalityReductionModel Factory did not return an DimensionalityReductionModel: " << (*i)->GetNameOfClass() << std::endl; } } - -for(typename std::list<DimensionalityReductionModelTypePointer>::iterator k = possibleDimensionalityReductionModel.begin(); + + for(typename std::list<DimensionalityReductionModelTypePointer>::iterator k = possibleDimensionalityReductionModel.begin(); k != possibleDimensionalityReductionModel.end(); ++k) { - if( mode == ReadMode ) + if( mode == ReadMode ) { - if((*k)->CanReadFile(path)) { return *k; @@ -99,7 +94,6 @@ for(typename std::list<DimensionalityReductionModelTypePointer>::iterator k = po { return *k; } - } } return ITK_NULLPTR; @@ -111,20 +105,16 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue> ::RegisterBuiltInFactories() { itk::MutexLockHolder<itk::SimpleMutexLock> lockHolder(mutex); - - RegisterFactory(SOM2DModelFactory<TInputValue,TOutputValue>::New()); 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(LogAutoencoderModelFactory<TInputValue,TOutputValue>::New()); - // RegisterFactory(TiedAutoencoderModelFactory<TInputValue,TOutputValue>::New()); #endif - } template <class TInputValue, class TOutputValue> @@ -151,17 +141,15 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue> for (itFac = factories.begin(); itFac != factories.end() ; ++itFac) { - - // SOM - - SOM5DModelFactory<TInputValue,TOutputValue> *som5dFactory = + // SOM 5D + SOM5DModelFactory<TInputValue,TOutputValue> *som5dFactory = dynamic_cast<SOM5DModelFactory<TInputValue,TOutputValue> *>(*itFac); if (som5dFactory) { itk::ObjectFactoryBase::UnRegisterFactory(som5dFactory); continue; } - + // SOM 4D SOM4DModelFactory<TInputValue,TOutputValue> *som4dFactory = dynamic_cast<SOM4DModelFactory<TInputValue,TOutputValue> *>(*itFac); if (som4dFactory) @@ -169,7 +157,7 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue> itk::ObjectFactoryBase::UnRegisterFactory(som4dFactory); continue; } - + // SOM 3D SOM3DModelFactory<TInputValue,TOutputValue> *som3dFactory = dynamic_cast<SOM3DModelFactory<TInputValue,TOutputValue> *>(*itFac); if (som3dFactory) @@ -177,7 +165,7 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue> itk::ObjectFactoryBase::UnRegisterFactory(som3dFactory); continue; } - + // SOM 2D SOM2DModelFactory<TInputValue,TOutputValue> *som2dFactory = dynamic_cast<SOM2DModelFactory<TInputValue,TOutputValue> *>(*itFac); if (som2dFactory) @@ -185,9 +173,8 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue> itk::ObjectFactoryBase::UnRegisterFactory(som2dFactory); continue; } - #ifdef OTB_USE_SHARK - + // Autoencoder LogAutoencoderModelFactory<TInputValue,TOutputValue> *aeFactory = dynamic_cast<LogAutoencoderModelFactory<TInputValue,TOutputValue> *>(*itFac); if (aeFactory) @@ -195,17 +182,7 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue> itk::ObjectFactoryBase::UnRegisterFactory(aeFactory); continue; } - - /* - TiedAutoencoderModelFactory<TInputValue,TOutputValue> *taeFactory = - dynamic_cast<TiedAutoencoderModelFactory<TInputValue,TOutputValue> *>(*itFac); - if (taeFactory) - { - itk::ObjectFactoryBase::UnRegisterFactory(taeFactory); - continue; - } - */ - // PCA + // PCA PCAModelFactory<TInputValue,TOutputValue> *pcaFactory = dynamic_cast<PCAModelFactory<TInputValue,TOutputValue> *>(*itFac); if (pcaFactory) @@ -214,9 +191,7 @@ DimensionalityReductionModelFactory<TInputValue,TOutputValue> continue; } #endif - } - } } // end namespace otb diff --git a/Modules/Learning/DimensionalityReductionLearning/include/otbImageDimensionalityReductionFilter.h b/Modules/Learning/DimensionalityReductionLearning/include/otbImageDimensionalityReductionFilter.h index 67bf3d2e4e..93c60cf022 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/otbImageDimensionalityReductionFilter.h +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbImageDimensionalityReductionFilter.h @@ -21,7 +21,6 @@ #define otbImageDimensionalityReduction_h #include "itkImageToImageFilter.h" -//#include "DimensionalityReductionModel.h" #include "otbMachineLearningModel.h" #include "otbImage.h" diff --git a/Modules/Learning/DimensionalityReductionLearning/include/otbImageDimensionalityReductionFilter.txx b/Modules/Learning/DimensionalityReductionLearning/include/otbImageDimensionalityReductionFilter.txx index 8f7a715621..2656e21e1f 100644 --- a/Modules/Learning/DimensionalityReductionLearning/include/otbImageDimensionalityReductionFilter.txx +++ b/Modules/Learning/DimensionalityReductionLearning/include/otbImageDimensionalityReductionFilter.txx @@ -36,8 +36,6 @@ ImageDimensionalityReductionFilter<TInputImage, TOutputImage, TMaskImage> this->SetNumberOfIndexedInputs(2); this->SetNumberOfRequiredInputs(1); - //m_DefaultLabel = itk::NumericTraits<LabelType>::ZeroValue(); - this->SetNumberOfRequiredOutputs(2); this->SetNthOutput(0,TOutputImage::New()); this->SetNthOutput(1,ConfidenceImageType::New()); @@ -113,9 +111,7 @@ ImageDimensionalityReductionFilter<TInputImage, TOutputImage, TMaskImage> // Define iterators typedef itk::ImageRegionConstIterator<InputImageType> InputIteratorType; - //typedef itk::ImageRegionConstIterator<MaskImageType> MaskIteratorType; typedef itk::ImageRegionIterator<OutputImageType> OutputIteratorType; - //typedef itk::ImageRegionIterator<ConfidenceImageType> ConfidenceMapIteratorType; InputIteratorType inIt(inputPtr, outputRegionForThread); OutputIteratorType outIt(outputPtr, outputRegionForThread); @@ -123,43 +119,36 @@ ImageDimensionalityReductionFilter<TInputImage, TOutputImage, TMaskImage> // Walk the part of the image for (inIt.GoToBegin(), outIt.GoToBegin(); !inIt.IsAtEnd() && !outIt.IsAtEnd(); ++inIt, ++outIt) { - // Classifify - - outIt.Set(m_Model->Predict(inIt.Get())); + // Classifify + outIt.Set(m_Model->Predict(inIt.Get())); progress.CompletedPixel(); } - } template <class TInputImage, class TOutputImage, class TMaskImage> void ImageDimensionalityReductionFilter<TInputImage, TOutputImage, TMaskImage>::GenerateOutputInformation() { - Superclass::GenerateOutputInformation(); + Superclass::GenerateOutputInformation(); this->GetOutput()->SetNumberOfComponentsPerPixel( m_Model->GetDimension() ); } - - template <class TInputImage, class TOutputImage, class TMaskImage> void ImageDimensionalityReductionFilter<TInputImage, TOutputImage, TMaskImage> ::BatchThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId) { - // Get the input pointers InputImageConstPointerType inputPtr = this->GetInput(); MaskImageConstPointerType inputMaskPtr = this->GetInputMask(); OutputImagePointerType outputPtr = this->GetOutput(); ConfidenceImagePointerType confidencePtr = this->GetOutputConfidence(); - + // Progress reporting itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels()); // Define iterators typedef itk::ImageRegionConstIterator<InputImageType> InputIteratorType; - //typedef itk::ImageRegionConstIterator<MaskImageType> MaskIteratorType; typedef itk::ImageRegionIterator<OutputImageType> OutputIteratorType; - //typedef itk::ImageRegionIterator<ConfidenceImageType> ConfidenceMapIteratorType; InputIteratorType inIt(inputPtr, outputRegionForThread); OutputIteratorType outIt(outputPtr, outputRegionForThread); @@ -168,45 +157,40 @@ ImageDimensionalityReductionFilter<TInputImage, TOutputImage, TMaskImage> typedef typename ModelType::InputListSampleType InputListSampleType; typedef typename ModelType::TargetValueType TargetValueType; typedef typename ModelType::TargetListSampleType TargetListSampleType; - + typename InputListSampleType::Pointer samples = InputListSampleType::New(); unsigned int num_features = inputPtr->GetNumberOfComponentsPerPixel(); samples->SetMeasurementVectorSize(num_features); InputSampleType sample(num_features); + // Fill the samples - for (inIt.GoToBegin(); !inIt.IsAtEnd(); ++inIt) { - - typename InputImageType::PixelType pix = inIt.Get(); - for(size_t feat=0; feat<num_features; ++feat) - { - sample[feat]=pix[feat]; - } - samples->PushBack(sample); - + typename InputImageType::PixelType pix = inIt.Get(); + for(size_t feat=0; feat<num_features; ++feat) + { + sample[feat]=pix[feat]; + } + samples->PushBack(sample); } //Make the batch prediction typename TargetListSampleType::Pointer labels; - + // This call is threadsafe labels = m_Model->PredictBatch(samples); // Set the output values - typename TargetListSampleType::ConstIterator labIt = labels->Begin(); - for (outIt.GoToBegin(); !outIt.IsAtEnd(); ++outIt) { - - itk::VariableLengthVector<TargetValueType> labelValue; - + itk::VariableLengthVector<TargetValueType> labelValue; labelValue = labIt.GetMeasurementVector(); ++labIt; outIt.Set(labelValue); progress.CompletedPixel(); } } + template <class TInputImage, class TOutputImage, class TMaskImage> void ImageDimensionalityReductionFilter<TInputImage, TOutputImage, TMaskImage> @@ -220,8 +204,8 @@ ImageDimensionalityReductionFilter<TInputImage, TOutputImage, TMaskImage> { this->ClassicThreadedGenerateData(outputRegionForThread, threadId); } - } + /** * PrintSelf Method */ @@ -232,5 +216,6 @@ ImageDimensionalityReductionFilter<TInputImage, TOutputImage, TMaskImage> { Superclass::PrintSelf(os, indent); } + } // End namespace otb #endif -- GitLab