ImFusion SDK 4.3
ModelConfiguration Class Reference

#include <ImFusion/ML/ModelConfiguration.h>

Configuration class for MachineLearningModel parameters. More...

+ Inheritance diagram for ModelConfiguration:

Detailed Description

Configuration class for MachineLearningModel parameters.

This class parses YAML configuration files and validates their consistency. It supports versioned configurations to maintain API compatibility.

Version Management:

  • The p_version parameter tracks the configuration format version at the time the model was created.
  • When changes to the ModelConfiguration class API are made, VERSION_COUNT is incremented.
  • Older configurations are automatically upgraded to the latest version.
  • Use the save function to convert configurations to the latest version.

Public Member Functions

 ModelConfiguration (const std::string &configFilePath, PredictionOutput defaultPredictionOutput=PredictionOutput::Unknown)
 
const std::stringconfigPath () const
 
bool save (const std::string &outputYamlPath) const
 Save model configuration to YAML file.
 
void configure (const Properties *properties) override
 Configure this object instance by de-serializing the given Properties.
 
void configuration (Properties *properties) const override
 Serialize the current object configuration into the given Properties object.
 
bool ok () const
 
Status status () const
 
bool mustSplitImage () const
 
const std::stringlogDomain () const
 
bool compareWith (const ModelConfiguration &other, bool ignoreVersion=false) const
 
bool operator== (const ModelConfiguration &other) const
 
bool operator!= (const ModelConfiguration &other) const
 
int upgradedVersion () const
 
int originalVersion () const
 
int version () const
 
const std::stringname () const
 
const std::stringdescription () const
 
const std::stringmodelPath () const
 
const std::stringengine () const
 
ModelType modelType () const
 
const std::vector< PredictionType > & predictionTypes () const
 
const std::vector< PredictionOutput > & predictionOutputTypes () const
 
const std::vector< std::string > & preprocessingInputFields () const
 
const std::vector< std::string > & engineInputFields () const
 
const std::vector< std::string > & engineOutputFields () const
 
const std::vector< std::string > & engineOutputFieldsToIgnore () const
 
const std::map< std::string, std::vector< std::string > > & labelNames () const
 
bool verbose () const
 
int maxBatchSize () const
 
std::optional< int > ringBufferSize () const
 
bool forceCPU () const
 
void setForceCPU (bool forceCPU)
 
const std::vector< Operation::Specs > & getPreProcessingOptions () const
 
const std::vector< Operation::Specs > & getPostProcessingOptions () const
 
Properties getSamplingParameters () const
 
std::vector< Operation::Specs > & getPreProcessingOptions ()
 
std::vector< Operation::Specs > & getPostProcessingOptions ()
 
Properties getEngineProperties () const
 
bool skipUnpadding () const
 
bool mustCloneInputContainer () const
 
- Public Member Functions inherited from Configurable
virtual void configureDefaults ()
 Retrieve the properties of this object, replaces values with their defaults and sets it again.
 
void registerParameter (ParameterBase *param)
 Register the given Parameter or SubProperty, so that it will be configured during configure()/configuration().
 
void unregisterParameter (const ParameterBase *param)
 Remove the given Parameter or SubProperty from the list of registered parameters.
 
 Configurable (const Configurable &rhs)
 
 Configurable (Configurable &&rhs) noexcept
 
Configurableoperator= (const Configurable &)
 
Configurableoperator= (Configurable &&) noexcept
 

Public Attributes

ModelParameter< int > p_version = {"Version", 1, this, ParamRequired::Yes}
 Version of the config yaml.
 
ModelParameter< std::stringp_name = {"Name", "", this, ParamRequired::No}
 Name of the model.
 
ModelParameter< std::stringp_description = {"Description", "", this, ParamRequired::No}
 Description of the model.
 
ModelParameter< ModelTypep_modelType
 Type of model. Parameter name: "Type", default value: "NeuralNetwork", required: Yes.
 
ModelParameter< bool > p_verbose = {"Verbose", false, this, ParamRequired::No}
 Toggle verbosity.
 
ModelParameter< int > p_maxBatchSize = {"MaxBatchSize", 1, this, ParamRequired::No}
 Control the maximum number of input items the model is processing in each forward pass.
 
ModelParameter< bool > p_cloneInputContainer = {"CloneInputContainer", false, this, ParamRequired::No}
 Whether the model must create an output with the exact same type of the input For pixelwise predictions, the output will have the same type as the input if this flag is true.
 
ModelParameter< std::optional< int > > p_ringBufferSize = {"RingBufferSize", std::optional<int>{}, this, ParamRequired::No}
 Control the number of frames the model is batching from a stream.
 
ModelParameter< bool > p_commercialUseAllowed = {"CommercialUseAllowed", true, this, ParamRequired::No}
 Commercial use flag.
 
ModelParameter< bool > p_upgradeMLModelV2 = {"UpgradeToMLModelV2", false, this, ParamRequired::No}
 Controls whether the model configuration should be upgraded to the latest version (V8).
 
std::vector< PredictionTypep_predictionTypes = {}
 Types of prediction of each model head. Yaml config keyword: "PredictionType".
 
std::vector< PredictionOutputp_predictionOutputs = {}
 Output prediction types of each model head. Yaml config keyword: "PredictionOutput".
 
ModelParameter< std::vector< std::string > > p_preprocessingInputFields
 Input fields of the preprocessing.
 
std::map< std::string, std::vector< std::string > > p_labelNames
 Label names of each model head. Yaml config keyword: "LabelNames".
 
std::vector< Operation::Specsp_preprocessing = {}
 Configuration of the preprocessing. Yaml config keyword: "PreProcessing".
 
std::vector< Operation::Specsp_postprocessing = {}
 Configuration of the postprocessing. Yaml config keyword: "PostProcessing".
 
EngineConfiguration engineConfig
 Configuration of the Engine parameters. Yaml config keyword: "Engine".
 
SamplingConfiguration samplingConfig
 Configuration of the Sampling parameters. Yaml config keyword: "Sampling".
 
Properties p_acknowledgments
 Acknowledgments. Yaml config keyword: "Acknowledgments".
 
- Public Attributes inherited from Configurable
Signal signalParametersChanged
 Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted.
 

Static Public Attributes

static constexpr const int VERSION_COUNT = 8
 Latest version of the ModelConfiguration class.
 
static constexpr const int LAST_V1_VERSION = 7
 Last version of the ModelConfiguration class that supports MachineLearningModel V1.
 
static const std::string p_defaultInputName
 
static const std::string p_defaultOutputName
 

Additional Inherited Members

- Protected Attributes inherited from Configurable
std::vector< Paramm_params
 List of all registered Parameter and SubProperty instances.
 

Member Function Documentation

◆ save()

bool save ( const std::string & outputYamlPath) const

Save model configuration to YAML file.

This can be useful for converting an old configuration to the latest version.

◆ configure()

void configure ( const Properties * p)
overridevirtual

Configure this object instance by de-serializing the given Properties.

The default implementation will do so automatically for all registered Parameter and SubProperty instances.

See also
configuration() for the inverse functionality

Reimplemented from Configurable.

◆ configuration()

void configuration ( Properties * p) const
overridevirtual

Serialize the current object configuration into the given Properties object.

The default implementation will do so automatically for all registered Parameter and SubProperty instances.

See also
configure() for the inverse functionality

Reimplemented from Configurable.

◆ version()

int version ( ) const
Deprecated
"Use p_version instead."

◆ name()

const std::string & name ( ) const
Deprecated
"Use p_name instead."

◆ description()

const std::string & description ( ) const
Deprecated
"Use p_description instead."

◆ modelPath()

const std::string & modelPath ( ) const
Deprecated
"Use engineConfig.p_modelFile instead."

◆ engine()

const std::string & engine ( ) const
Deprecated
"Use engineConfig.p_name instead."

◆ modelType()

ModelType modelType ( ) const
Deprecated
"Use p_modelType instead."

◆ predictionTypes()

const std::vector< PredictionType > & predictionTypes ( ) const
Deprecated
"Use p_predictionTypes instead."

◆ predictionOutputTypes()

const std::vector< PredictionOutput > & predictionOutputTypes ( ) const
Deprecated
"Use p_predictionOutputTypes instead."

◆ preprocessingInputFields()

const std::vector< std::string > & preprocessingInputFields ( ) const
Deprecated
"Use p_preprocessingInputFields instead."

◆ engineInputFields()

const std::vector< std::string > & engineInputFields ( ) const
Deprecated
"Use engineConfig.p_inputFields instead."

◆ engineOutputFields()

const std::vector< std::string > & engineOutputFields ( ) const
Deprecated
"Use engineConfig.p_outputFields instead."

◆ engineOutputFieldsToIgnore()

const std::vector< std::string > & engineOutputFieldsToIgnore ( ) const
Deprecated
"Use engineConfig.p_outputFieldsToIgnore instead."

◆ labelNames()

const std::map< std::string, std::vector< std::string > > & labelNames ( ) const
Deprecated
"Use p_labelNames instead."

◆ verbose()

bool verbose ( ) const
Deprecated
"Use p_verbose instead."

◆ maxBatchSize()

int maxBatchSize ( ) const
Deprecated
"Use p_maxBatchSize instead."

◆ ringBufferSize()

std::optional< int > ringBufferSize ( ) const
Deprecated
"Use p_ringBufferSize instead."

◆ forceCPU()

bool forceCPU ( ) const
Deprecated
"Use engineConfig.p_forceCPU instead."

◆ setForceCPU()

void setForceCPU ( bool forceCPU)
Deprecated
"Use engineConfig.p_forceCPU instead."

◆ getPreProcessingOptions() [1/2]

const std::vector< Operation::Specs > & getPreProcessingOptions ( ) const
Deprecated
"Use p_preprocessing config object instead."

◆ getPostProcessingOptions() [1/2]

const std::vector< Operation::Specs > & getPostProcessingOptions ( ) const
Deprecated
"Use p_postprocessing config object instead."

◆ getSamplingParameters()

Properties getSamplingParameters ( ) const
Deprecated
"Use sampling config object instead."

◆ getPreProcessingOptions() [2/2]

std::vector< Operation::Specs > & getPreProcessingOptions ( )
Deprecated
"Use p_preprocessing config object instead."

◆ getPostProcessingOptions() [2/2]

std::vector< Operation::Specs > & getPostProcessingOptions ( )
Deprecated
"Use p_postprocessing config object instead."

◆ getEngineProperties()

Properties getEngineProperties ( ) const
Deprecated
"Use engine config object instead."

◆ skipUnpadding()

bool skipUnpadding ( ) const
Deprecated
"Use samplingConfig.p_skipUnpadding instead."

◆ mustCloneInputContainer()

bool mustCloneInputContainer ( ) const
Deprecated
"Use p_cloneInputContainer instead."

Member Data Documentation

◆ LAST_V1_VERSION

const int LAST_V1_VERSION = 7
staticconstexpr

Last version of the ModelConfiguration class that supports MachineLearningModel V1.

MachineLearningModel V2 introduces a new logic for splitting the input image into patches and recombining the predictions. This improves the efficiency and the stability of the model predictions, but may also introduce changes that could affect model predictions.

◆ p_cloneInputContainer

ModelParameter<bool> p_cloneInputContainer = {"CloneInputContainer", false, this, ParamRequired::No}

Whether the model must create an output with the exact same type of the input For pixelwise predictions, the output will have the same type as the input if this flag is true.

If false, the output must be exactly a SharedImageSet.

◆ p_ringBufferSize

ModelParameter<std::optional<int> > p_ringBufferSize = {"RingBufferSize", std::optional<int>{}, this, ParamRequired::No}

Control the number of frames the model is batching from a stream.

This attribute is used only by PixelwiseLearningStream for models trained on a buffer of images (needs special treatment by the class)

◆ p_upgradeMLModelV2

ModelParameter<bool> p_upgradeMLModelV2 = {"UpgradeToMLModelV2", false, this, ParamRequired::No}

Controls whether the model configuration should be upgraded to the latest version (V8).

When set to true, the configuration will be automatically upgraded to the latest available version during parsing, even if the original version is 7 or lower. This enables new features and improvements but may introduce changes in the splitting/recombination logic that could affect model predictions.

Default is false to maintain backward compatibility and avoid potential regressions in existing models.

◆ p_preprocessingInputFields

ModelParameter<std::vector<std::string> > p_preprocessingInputFields
Initial value:
= {"PreprocessingInputFields",
std::vector<std::string>{EngineConfiguration::p_defaultInputName},
this,
ParamRequired::No}

Input fields of the preprocessing.

◆ p_defaultInputName

const std::string p_defaultInputName
static
Deprecated
"Use EngineConfiguration::p_defaultInputName instead."

◆ p_defaultOutputName

const std::string p_defaultOutputName
static
Deprecated
"Use EngineConfiguration::p_defaultOutputName instead."

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close