From 47fc69c1c4c20c981b80769ca36dd23898360175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= <traizetc@cesbio.cnes.fr> Date: Fri, 30 Jun 2017 09:57:49 +0200 Subject: [PATCH] BUG : SOMModel now herits from MachineLearningModel<TInput,...> instead of MachineLearningModel<itk:variablelengthvector<TInput>,...> --- app/cbDimensionalityReductionTrainer.cxx | 3 ++- app/cbDimensionalityReductionVector.cxx | 19 +++++++++++++- include/cbLearningApplicationBaseDR.h | 8 +++--- include/cbLearningApplicationBaseDR.txx | 32 ++++++++++++------------ 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/app/cbDimensionalityReductionTrainer.cxx b/app/cbDimensionalityReductionTrainer.cxx index e83231428d..aee6fb3ed9 100644 --- a/app/cbDimensionalityReductionTrainer.cxx +++ b/app/cbDimensionalityReductionTrainer.cxx @@ -60,7 +60,8 @@ private: AddParameter(ParameterType_OutputFilename, "io.out", "Output model"); SetParameterDescription("io.out", "Output file containing the model estimated (.txt format)."); - + + AddParameter(ParameterType_InputFilename, "io.stats", "Input XML image statistics file"); MandatoryOff("io.stats"); SetParameterDescription("io.stats", "XML file containing mean and variance of each feature."); diff --git a/app/cbDimensionalityReductionVector.cxx b/app/cbDimensionalityReductionVector.cxx index 485f248b64..dbfd87d39a 100644 --- a/app/cbDimensionalityReductionVector.cxx +++ b/app/cbDimensionalityReductionVector.cxx @@ -116,6 +116,11 @@ class CbDimensionalityReductionVector : public Application SetParameterDescription("pcadim","This optional parameter can be set to reduce the number of eignevectors used in the PCA model file."); // MandatoryOff("pcadim"); + AddParameter(ParameterType_String, "mode", "Writting mode"); // + SetParameterString("mode","overwrite", false); + SetParameterDescription("mode","This parameter determines if the output file is overwritten or updated [overwrite/update]"); // + + // Doc example parameter settings SetDocExampleParameterValue("in", "vectorData.shp"); SetDocExampleParameterValue("instat", "meanVar.xml"); @@ -262,7 +267,19 @@ class CbDimensionalityReductionVector : public Application if (IsParameterEnabled("out") && HasValue("out")) { // Create new OGRDataSource - output = ogr::DataSource::New(GetParameterString("out"), ogr::DataSource::Modes::Overwrite); + if (GetParameterString("mode")=="overwrite") + { + output = ogr::DataSource::New(GetParameterString("out"), ogr::DataSource::Modes::Overwrite); + } + else if (GetParameterString("mode")=="update") + { + output = ogr::DataSource::New(GetParameterString("out"), ogr::DataSource::Modes::Update_LayerCreateOnly ); + } + else + { + otbAppLogFATAL(<< "Error when creating the output file" << GetParameterString("mode") << " : unsupported writting mode type [update/overwrite]"); + } + otb::ogr::Layer newLayer = output->CreateLayer(GetParameterString("out"), const_cast<OGRSpatialReference*>(layer.GetSpatialRef()), layer.GetGeomType()); diff --git a/include/cbLearningApplicationBaseDR.h b/include/cbLearningApplicationBaseDR.h index 9d0a6c6908..94c62d1b43 100644 --- a/include/cbLearningApplicationBaseDR.h +++ b/include/cbLearningApplicationBaseDR.h @@ -87,16 +87,16 @@ public: // Dimensionality reduction models - typedef SOMMap<itk::VariableLengthVector<TInputValue>,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 2> Map2DType; + typedef SOMMap<TInputValue,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 2> Map2DType; typedef otb::SOMModel<InputValueType, 2> SOM2DModelType; - typedef SOMMap<itk::VariableLengthVector<TInputValue>,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 3> Map3DType; + typedef SOMMap<TInputValue,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 3> Map3DType; typedef otb::SOMModel<InputValueType, 3> SOM3DModelType; - typedef SOMMap<itk::VariableLengthVector<TInputValue>,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 4> Map4DType; + typedef SOMMap<TInputValue,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 4> Map4DType; typedef otb::SOMModel<InputValueType, 4> SOM4DModelType; - typedef SOMMap<itk::VariableLengthVector<TInputValue>,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 5> Map5DType; + typedef SOMMap<TInputValue,itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, 5> Map5DType; typedef otb::SOMModel<InputValueType, 5> SOM5DModelType; diff --git a/include/cbLearningApplicationBaseDR.txx b/include/cbLearningApplicationBaseDR.txx index a42ad73857..6e1635e24d 100644 --- a/include/cbLearningApplicationBaseDR.txx +++ b/include/cbLearningApplicationBaseDR.txx @@ -45,7 +45,7 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue> AddDocTag(Tags::Learning); // main choice parameter that will contain all dimensionality reduction options - AddParameter(ParameterType_Choice, "model", "moddel to use for the training"); + AddParameter(ParameterType_Choice, "model", "model to use for the training"); SetParameterDescription("model", "Choice of the dimensionality reduction model to use for the training."); @@ -83,28 +83,28 @@ 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 + #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 } if(modelName == "tiedautoencoder") { - #ifdef OTB_USE_SHARK - TrainAutoencoder<TiedAutoencoderModelType>(trainingListSample,modelPath); - #else - otbAppLogFATAL("Module SharkLearning is not installed. You should consider turning OTB_USE_SHARK on during cmake configuration."); - #endif + #ifdef OTB_USE_SHARK + TrainAutoencoder<TiedAutoencoderModelType>(trainingListSample,modelPath); + #else + otbAppLogFATAL("Module SharkLearning is not installed. You should consider turning OTB_USE_SHARK on during cmake configuration."); + #endif } if(modelName == "pca") { - #ifdef OTB_USE_SHARK - TrainPCA(trainingListSample,modelPath); - #else - otbAppLogFATAL("Module SharkLearning is not installed. You should consider turning OTB_USE_SHARK on during cmake configuration."); - #endif + #ifdef OTB_USE_SHARK + TrainPCA(trainingListSample,modelPath); + #else + otbAppLogFATAL("Module SharkLearning is not installed. You should consider turning OTB_USE_SHARK on during cmake configuration."); + #endif } } -- GitLab