From 7b2217e93f1820fefd3e9669eb9519228fd136dd Mon Sep 17 00:00:00 2001 From: Ludovic Hussonnois <ludovic.hussonnois@c-s.fr> Date: Mon, 20 Feb 2017 16:31:44 +0100 Subject: [PATCH] BUG: Add check on load function for KNN machine learning model. --- .../otbKNearestNeighborsMachineLearningModel.txx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Modules/Learning/Supervised/include/otbKNearestNeighborsMachineLearningModel.txx b/Modules/Learning/Supervised/include/otbKNearestNeighborsMachineLearningModel.txx index 040a0ea7ba..b440dc532d 100644 --- a/Modules/Learning/Supervised/include/otbKNearestNeighborsMachineLearningModel.txx +++ b/Modules/Learning/Supervised/include/otbKNearestNeighborsMachineLearningModel.txx @@ -185,11 +185,21 @@ KNearestNeighborsMachineLearningModel<TInputValue,TTargetValue> //first line is the K parameter of this algorithm. std::string line; std::getline(ifs, line); + std::istringstream iss(line); + if( line.find( "K" ) == std::string::npos ) + { + itkExceptionMacro( <<"Could not read file "<<filename ); + } std::string::size_type pos = line.find_first_of("=", 0); std::string::size_type nextpos = line.find_first_of(" \n\r", pos+1); this->SetK(boost::lexical_cast<int>(line.substr(pos+1, nextpos-pos-1))); + //second line is the IsRegression parameter std::getline(ifs, line); + if( line.find( "IsRegression" ) == std::string::npos ) + { + itkExceptionMacro( <<"Could not read file "<<filename ); + } pos = line.find_first_of("=", 0); nextpos = line.find_first_of(" \n\r", pos+1); this->SetRegressionMode(boost::lexical_cast<bool>(line.substr(pos+1, nextpos-pos-1))); -- GitLab