![]() |
ImFusion SDK 4.3
|
#include <ImFusion/ML/Engine.h>
Generic interface for machine learning models serialized by specific frameworks (PyTorch, ONNX, etc.). More...
Inheritance diagram for Engine:Generic interface for machine learning models serialized by specific frameworks (PyTorch, ONNX, etc.).
This class is used by the MachineLearningModel to forward the prediction request to the framework that was used to serialize the model.
C++ implementations of this interface are provided through dedicated plugins that encapsulate the framework-specific logic and libraries required for model deserialization and execution. See for instance the TorchPlugin and OnnxRuntimePlugin.
Python bindings are also available, enabling engine implementation directly in Python. This approach is useful for prototyping and Python SDK users. See imfusion.machinelearning.engines for examples of Python engine implementations.
Public Member Functions | |
| Engine (const std::string &name) | |
| virtual DataItem | predict (const DataItem &input)=0 |
| Main method to compute predictions of all classes on a DataItem containing heterogeneous elements. | |
| std::string | name () const |
| Returns the name of the operation as defined in the factories. | |
| virtual void | configure (const Properties *properties) override |
| Configure the Engine according to the properties. | |
| virtual void | configuration (Properties *properties) const override |
| Serialize the current object configuration into the given Properties object. | |
| virtual bool | isIdentical (const Engine *other) const |
| Check whether this engine instance is the same as other. | |
| virtual void | checkInputFields (const DataItem &input) |
| Check that inputs specified in the config are present in the input item. | |
| virtual void | checkOutputFields (const DataItem &input) |
| Check that outputs specified in the config are present in the predicted item. | |
| virtual std::vector< ExecutionProvider > | availableProviders () const =0 |
| Returns which provider is supported by the engine and available on the host. | |
| virtual std::optional< ExecutionProvider > | provider () const =0 |
| Returns which provider is used by the engine to run the model, empty if none available. | |
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 | |
| Configurable & | operator= (const Configurable &) |
| Configurable & | operator= (Configurable &&) noexcept |
Static Public Member Functions | |
| static bool | isRegistered (const std::string &engineName, bool silent=true) |
| Convenience function for checking that engine is registered in any factory (cpp or python for now...). | |
| static std::unique_ptr< Engine > | create (const std::string &engineName, const Properties &properties) |
| Convenience function to create an engine registered in any factory (cpp or python for now...) | |
Public Attributes | |
| Parameter< std::string > | p_modelFile = {"ModelFile", "", nullptr} |
| Parameters shared by all engines. | |
| Parameter< bool > | p_forceCPU = {"ForceCPU", false, nullptr} |
| Whether to force run on CPU even if GPU is present. | |
| Parameter< std::vector< std::string > > | p_inputFields = {"EngineInputFields", std::vector<std::string>{}, nullptr} |
| Input field names expected by the model run by the engine. | |
| Parameter< std::vector< std::string > > | p_outputFields = {"EngineOutputFields", std::vector<std::string>{}, nullptr} |
| Output field names returned by the model run by the engine. | |
| Parameter< std::vector< std::string > > | p_ignoreOutputFields = {"EngineOutputFieldsToIgnore", std::vector<std::string>{}, nullptr} |
| Output field names to be ignored by the engine. | |
| Parameter< std::string > | p_version = {"Version", "", nullptr} |
| Version of the engine used to train and save the model. | |
Public Attributes inherited from Configurable | |
| Signal | signalParametersChanged |
Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted. | |
Protected Member Functions | |
| virtual void | init (const Properties &properties) |
| Configures the engine from properties + connect signals. | |
| virtual void | onModelFileChanged () |
| Function that gets called when p_modelFile changes. | |
| virtual void | onForceCPUChanged () |
| Function that gets called when p_forceCPU changes. | |
| virtual void | connectSignals () |
| Connect the signals like onModelFileChanged, onForceCPUChanged, ... (We do not do this automatically because children class need to call this after they register their parameters) | |
Protected Attributes | |
| EngineConfiguration | m_config |
| Configuration object. | |
| std::string | m_name = "" |
| Name of the engine interface (e.g. "torch") | |
Protected Attributes inherited from Configurable | |
| std::vector< Param > | m_params |
| List of all registered Parameter and SubProperty instances. | |
|
overridevirtual |
Configure the Engine according to the properties.
If the engine cannot be configured, a runtime_error should be raised
Reimplemented from Configurable.
|
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.
Reimplemented from Configurable.
|
static |
Convenience function for checking that engine is registered in any factory (cpp or python for now...).
When the silent flag is set to false, the function will print a detailed error message.
|
protectedvirtual |
Configures the engine from properties + connect signals.
This function must be called in the constructor of all implementations of this interface.
| Parameter<std::string> p_modelFile = {"ModelFile", "", nullptr} |
Parameters shared by all engines.
Model file, serialized by the specific framework