Request for changes-102: Extend MachineLearningModel sample and target types

From OTBWiki
Jump to: navigation, search



The goal of this pull request is to be able to use itk::VariableLengthVector<> as Target type in otb::MachineLearningModel, so as to avoid code duplication when the following remote module will be merged in otb:


Currently, MachineLearningModel excepts scalar types TSample and TTarget and defines

TargetSampleType = itk::FixedArray<TTarget,1>
InputSampleType  = itk::VariableLenghtVector<TSample>

It is therefore impossible to use different containers for TargetSampleType and InputSampleType.

Implementation details

The main idea of this RFC is that MachineLearningModel will use MachineLearningModelTraits to define TargetSampleType and InputSampleType. The traits will then switch beween two cases: if TTarget (resp. TSample) is a scalar type, it will use the current containers typedef, and if TTarget is a container itself, it will use it instead:

Using those traits allows to reach the goal with a very limited impact on MachineLearningModel, and not a single line of code changes in derived classes.

Classes and files

New traits are defined in:


The otb::MachineLearningModel class has been updated to use the new traits:




has been extended to test that we can

typedef otb::MachineLearningModel<float,itk::VariableLengthVector<double>> MachineLearningModelType2;


Doxygen documentation is provided for MachineLearningModelTraits.