Skip to content
Snippets Groups Projects
Commit 7b2217e9 authored by Ludovic Hussonnois's avatar Ludovic Hussonnois
Browse files

BUG: Add check on load function for KNN machine learning model.

parent 2c5d5b81
No related branches found
No related tags found
No related merge requests found
......@@ -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)));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment