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

BUG: Correct order of use of internal application and parameter updates.

parent 078b7a5a
No related branches found
No related tags found
No related merge requests found
......@@ -38,9 +38,9 @@ public:
"training and validation when only images are provided." );
SetParameterDescription( "sample.percent", "Percentage of samples extract in images for "
"training and validation when only images are provided. This parameter is disable when vector data are provided" );
SetDefaultParameterFloat( "sample.percent", 100.0 );
SetDefaultParameterFloat( "sample.percent", 1.0 );
SetMinimumParameterFloatValue( "sample.percent", 0.0 );
SetMaximumParameterFloatValue( "sample.percent", 100.0 );
SetMaximumParameterFloatValue( "sample.percent", 1.0 );
// Doc example parameter settings
SetDocExampleParameterValue( "io.il", "QB_1_ortho.tif" );
......@@ -111,18 +111,28 @@ public:
}
else
{
SelectAndExtractTrainSamples( fileNames, imageList, vectorFileList, SamplingStrategy::GEOMETRIC );
SelectAndExtractTrainSamples( fileNames, imageList, vectorFileList, SamplingStrategy::GEOMETRIC, "fid" );
}
// Select and Extract samples for validation with computed statistics and rates
// Select and Extract samples for validation with computed statistics and rates.
// Validation samples could be empty if sample.vrt == 0 and if no dedicated validation are provided
// If no dedicated validation is provided the training is split corresponding to the sample.vtr parameter
// In this case if no vector data have been provided, the training rates and statistics are computed
// on the selection and extraction training result.
if( dedicatedValidation )
{
ComputePolygonStatistics( imageList, validationVectorFileList, fileNames.polyStatValidOutputs );
ComputeSamplingRate( fileNames.polyStatValidOutputs, fileNames.rateValidOut, rates.fmv );
}
SelectAndExtractValidationSamples( fileNames, imageList, validationVectorFileList );
else if(!HasInputVector)
{
ComputePolygonStatistics( imageList, fileNames.sampleOutputs, fileNames.polyStatTrainOutputs );
ComputeSamplingRate( fileNames.polyStatTrainOutputs, fileNames.rateTrainOut, rates.fmt );
}
// Extract or split validation vector data.
SelectAndExtractValidationSamples( fileNames, imageList, validationVectorFileList );
// Then train the model with extracted samples
TrainModel( imageList, fileNames.sampleTrainOutputs, fileNames.sampleValidOutputs );
......
......@@ -57,6 +57,7 @@ protected:
};
struct SamplingRates;
class TrainFileNamesHandler;
void InitIO()
......@@ -324,21 +325,20 @@ protected:
* \param strategy
*/
void SelectAndExtractSamples(FloatVectorImageType *image, std::string vectorFileName, std::string sampleFileName,
std::string statisticsFileName, std::string ratesFileName, SamplingStrategy strategy)
std::string statisticsFileName, std::string ratesFileName, SamplingStrategy strategy,
std::string selectedField = "")
{
GetInternalApplication( "select" )->SetParameterInputImage( "in", image );
GetInternalApplication( "select" )->SetParameterString( "out", sampleFileName, false );
GetInternalApplication( "extraction" )->SetParameterString( "outfield", "prefix", false );
GetInternalApplication( "extraction" )->SetParameterString( "outfield.prefix.name", "value_", false );
// Change the selection strategy based on selected sampling strategy
switch( strategy )
{
case GEOMETRIC:
GetInternalApplication( "select" )->SetParameterString( "sampler", "random", false );
GetInternalApplication( "select" )->SetParameterString( "strategy", "percent", false );
GetInternalApplication( "select" )->SetParameterFloat("strategy.percent.p", GetParameterFloat("sample.percent"), false);
GetInternalApplication( "select" )->SetParameterFloat( "strategy.percent.p",
GetParameterFloat( "sample.percent" ), false );
break;
case CLASS:
default:
......@@ -353,6 +353,15 @@ protected:
// select sample positions
ExecuteInternal( "select" );
GetInternalApplication( "extraction" )->SetParameterString( "vec", sampleFileName, false );
UpdateInternalParameters( "extraction" );
if( !selectedField.empty() )
GetInternalApplication( "extraction" )->SetParameterString( "field", selectedField, false );
GetInternalApplication( "extraction" )->SetParameterString( "outfield", "prefix", false );
GetInternalApplication( "extraction" )->SetParameterString( "outfield.prefix.name", "value_", false );
// extract sample descriptors
ExecuteInternal( "extraction" );
}
......@@ -361,20 +370,22 @@ protected:
* Select and extract samples with the SampleSelection and SampleExtraction application.
*/
void SelectAndExtractTrainSamples(const TrainFileNamesHandler &fileNames, FloatVectorImageListType *imageList,
std::vector<std::string> vectorFileNames, SamplingStrategy strategy)
std::vector<std::string> vectorFileNames, SamplingStrategy strategy,
std::string selectedFieldName = "")
{
for( unsigned int i = 0; i < imageList->Size(); ++i )
{
std::string vectorFileName = vectorFileNames.empty() ? "" : vectorFileNames[i];
SelectAndExtractSamples( imageList->GetNthElement( i ), vectorFileName, fileNames.sampleOutputs[i],
fileNames.polyStatTrainOutputs[i], fileNames.ratesTrainOutputs[i], strategy );
fileNames.polyStatTrainOutputs[i], fileNames.ratesTrainOutputs[i], strategy,
selectedFieldName );
}
}
void SelectAndExtractValidationSamples(const TrainFileNamesHandler &fileNames, FloatVectorImageListType *imageList,
const std::vector<std::string> &validationVectorFileList)
const std::vector<std::string> &validationVectorFileList = std::vector<std::string>())
{
// In dedicated validation mode the by class sampling strategy and statistics are used.
// Otherwise simply split training to validation samples corresponding to sample.vtr percentage.
......
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