|
OTB
9.0.0
Orfeo Toolbox
|
Go to the documentation of this file.
21 #ifndef otbTrainImagesBase_hxx
22 #define otbTrainImagesBase_hxx
43 SetParameterDescription(
"cleanup",
"If activated, the application will try to clean all temporary files it created");
49 AddApplication(
"PolygonClassStatistics",
"polystat",
"Polygon analysis");
50 AddApplication(
"MultiImageSamplingRate",
"rates",
"Sampling rates");
52 AddApplication(
"SampleExtraction",
"extraction",
"Sample extraction");
56 SetParameterDescription(
"sample",
"This group of parameters allows you to set training and validation sample lists parameters.");
60 "Maximum size per class (in pixels) of "
61 "the training sample list (default = 1000) (no limit = -1). If equal to -1,"
62 " then the maximal size of the available training sample list per class "
63 "will be equal to the surface area of the smallest class multiplied by the"
64 " training sample ratio.");
68 "Maximum size per class (in pixels) of "
69 "the validation sample list (default = 1000) (no limit = -1). If equal to -1,"
70 " then the maximal size of the available validation sample list per class "
71 "will be equal to the surface area of the smallest class multiplied by the "
72 "validation sample ratio.");
76 "Bound the number of samples for each "
77 "class by the number of available samples by the smaller class. Proportions "
78 "between training and validation are respected. Default is true (=1).");
81 "Ratio between training and validation samples (0.0 = all training, 1.0 = "
82 "all validation) (default = 0.5).");
105 ShareParameter(
"sample.vfn",
"polystat.field",
"Field containing the class integer label for supervision",
106 "Field containing the class id for supervision. "
107 "The values in this field shall be cast into integers.");
113 Connect(
"extraction.field",
"polystat.field");
114 Connect(
"extraction.layer",
"polystat.layer");
116 Connect(
"select.ram",
"polystat.ram");
117 Connect(
"extraction.ram",
"polystat.ram");
119 Connect(
"select.field",
"polystat.field");
120 Connect(
"select.layer",
"polystat.layer");
121 Connect(
"select.elev",
"polystat.elev");
123 Connect(
"extraction.in",
"select.in");
124 Connect(
"extraction.vec",
"select.out");
129 AddApplication(
"TrainVectorClassifier",
"training",
"Model training");
152 Connect(
"select.rand",
"training.rand");
156 const std::vector<std::string>& statisticsFileNames)
158 unsigned int nbImages =
static_cast<unsigned int>(imageList->
Size());
159 for (
unsigned int i = 0; i < nbImages; i++)
182 if (dedicatedValidation)
187 if (mt > -1 && mv <= -1 && vtr < 0.99999)
189 rates.
fmv =
static_cast<long>((double)mt * vtr / (1.0 - vtr));
191 if (mt <= -1 && mv > -1 && vtr > 0.00001)
193 rates.
fmt =
static_cast<long>((double)mv * (1.0 - vtr) / vtr);
201 if (mt > -1 && vtr < 0.99999)
203 rates.
fmt =
static_cast<long>((double)mt / (1.0 - vtr));
205 if (mv > -1 && vtr > 0.00001)
209 rates.
fmt = std::min(rates.
fmt,
static_cast<long>((
double)mv / vtr));
213 rates.
fmt =
static_cast<long>((double)mv / vtr);
235 std::ostringstream oss;
249 const std::vector<std::string>& sampleValidationFileNames)
252 if (!sampleValidationFileNames.empty())
258 unsigned int nbBands = image->GetNumberOfComponentsPerPixel();
259 std::vector<std::string> selectedNames;
260 for (
unsigned int i = 0; i < nbBands; i++)
262 std::ostringstream oss;
264 selectedNames.push_back(
"value_" + oss.str());
277 std::string statisticsFileName, std::string ratesFileName,
SamplingStrategy strategy, std::string selectedField)
307 if (!selectedField.empty())
319 std::vector<std::string> vectorFileNames,
SamplingStrategy strategy, std::string selectedFieldName)
322 for (
unsigned int i = 0; i < imageList->
Size(); ++i)
324 std::string vectorFileName = vectorFileNames.empty() ?
"" : vectorFileNames[i];
332 const std::vector<std::string>& validationVectorFileList)
334 for (
unsigned int i = 0; i < imageList->
Size(); ++i)
343 for (
unsigned int i = 0; i < imageList->
Size(); ++i)
351 std::string sampleValidFileName, std::string ratesTrainFileName)
360 rateCalculator->Read(ratesTrainFileName);
362 const MapRateType& inputRates = rateCalculator->GetRatesByClass();
366 for (MapRateType::const_iterator it = inputRates.begin(); it != inputRates.end(); ++it)
369 unsigned long total = std::min(it->second.Required, it->second.Tot);
370 unsigned long neededValid =
static_cast<unsigned long>((double)total * vtr);
371 unsigned long neededTrain = total - neededValid;
373 tpt.Required = neededTrain;
374 tpt.Rate = (1.0 - vtr);
375 trainRates[it->first] = tpt;
376 tpt.Tot = neededValid;
377 tpt.Required = neededValid;
379 validRates[it->first] = tpt;
387 splitter->SetInput(image);
388 splitter->SetOGRData(source);
389 splitter->SetOutputPositionContainerAndRates(destTrain, trainRates, 0);
390 splitter->SetOutputPositionContainerAndRates(destValid, validRates, 1);
392 splitter->SetLayerIndex(0);
393 splitter->SetOriginFieldName(std::string(
""));
394 splitter->SetSamplerParameters(param);
395 splitter->GetStreamer()->SetAutomaticTiledStreaming(
static_cast<unsigned int>(this->
GetParameterInt(
"ram")));
396 AddProcess(splitter->GetStreamer(),
"Split samples between training and validation...");
void ExecuteInternal(std::string key)
bool Connect(std::string fromKey, std::string toKey)
std::vector< std::string > sampleTrainOutputs
void SetParameterInputImage(std::string const ¶meter, ImageBaseType *inputImage)
void SetVectorData(std::string const &key, std::string const &vectorData)
@ ParameterType_InputImageList
std::vector< int > GetSelectedItems(std::string const ¶mKey)
void TrainModel(FloatVectorImageListType *imageList, const std::vector< std::string > &sampleTrainFileNames, const std::vector< std::string > &sampleValidationFileNames)
void ShareClassificationParams()
void AddParameter(ParameterType type, std::string const ¶mKey, std::string const ¶mName)
ObjectPointerType GetNthElement(unsigned int index) const
std::vector< std::string > sampleOutputs
itk::SmartPointer< Self > Pointer
std::vector< std::string > GetChoiceNames(std::string const ¶mKey)
void ComputePolygonStatistics(FloatVectorImageListType *imageList, const std::vector< std::string > &vectorFileNames, const std::vector< std::string > &statisticsFileNames)
std::vector< std::string > sampleValidOutputs
void InitClassification()
void SetParameterInt(std::string const ¶meter, int value, bool hasUserValueFlag=true)
void ConnectSamplingParameters()
itk::SmartPointer< Self > Pointer
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
void SetMinimumParameterFloatValue(std::string const ¶meter, float value)
void SetParameterFloat(std::string const ¶meter, float value, bool hasUserValueFlag=true)
std::vector< std::string > GetParameterStringList(const std::string ¶meter)
void AddProcess(itk::ProcessObject *object, std::string description)
void SelectAndExtractSamples(FloatVectorImageType *image, std::string vectorFileName, std::string sampleFileName, std::string statisticsFileName, std::string ratesFileName, SamplingStrategy strategy, std::string selectedField="")
bool ShareParameter(std::string localKey, std::string internalKey, std::string name=std::string(), std::string desc=std::string())
Application * GetInternalApplication(std::string id)
void UpdateInternalParameters(std::string key)
struct OTBSampling_EXPORT otb::SamplingRateCalculator::Triplet TripletType
void SetDefaultParameterInt(std::string const ¶meter, int value)
std::vector< std::string > polyStatTrainOutputs
InternalContainerSizeType Size(void) const override
void SetParameterDescription(std::string const ¶mKey, std::string dec)
void MandatoryOn(std::string const ¶mKey)
void SetMaximumParameterFloatValue(std::string const ¶meter, float value)
void SetParameterStringList(std::string const ¶meter, std::vector< std::string > values, bool hasUserValueFlag=true)
@ ParameterType_InputVectorDataList
SamplerType::ParameterType SamplerParameterType
void SetParameterString(std::string const ¶meter, std::string value, bool hasUserValueFlag=true)
int GetParameterInt(std::string const ¶meter) const
itk::SmartPointer< Self > Pointer
itk::SmartPointer< Self > Pointer
std::vector< std::string > ratesTrainOutputs
SamplingRates ComputeFinalMaximumSamplingRates(bool dedicatedValidation)
@ Read
Open data source in read-only mode.
void SplitTrainingAndValidationSamples(FloatVectorImageType *image, std::string sampleFileName, std::string sampleTrainFileName, std::string sampleValidFileName, std::string ratesTrainFileName)
void ComputeSamplingRate(const std::vector< std::string > &statisticsFileNames, const std::string &ratesFileName, long maximum)
bool AddApplication(std::string appType, std::string key, std::string desc)
This class is a generic all-purpose wrapping around an std::vector<itk::SmartPointer<ObjectType> >.
void SplitTrainingToValidationSamples(const TrainFileNamesHandler &fileNames, FloatVectorImageListType *imageList)
void MandatoryOff(std::string const ¶mKey)
float GetParameterFloat(std::string const ¶meter) const
void ShareSamplingParameters()
std::vector< std::string > polyStatValidOutputs
void SelectAndExtractTrainSamples(const TrainFileNamesHandler &fileNames, FloatVectorImageListType *imageList, std::vector< std::string > vectorFileNames, SamplingStrategy strategy, std::string selectedFieldName="")
Creation of an "otb" vector image which contains metadata.
void SelectAndExtractValidationSamples(const TrainFileNamesHandler &fileNames, FloatVectorImageListType *imageList, const std::vector< std::string > &validationVectorFileList=std::vector< std::string >())
void ConnectClassificationParams()
std::vector< std::string > ratesValidOutputs
otb::SamplingRateCalculator::MapRateType MapRateType