modelEvaluateGenericNeuralNetwork
Extends from BaseClasses.BaseGenericNeuralNet.
Information
This is the most generic block to include neural networks within Modelica. It extends the BaseGenericNeuralNet and provides generic in- and outputs. It can be used for any neural network. For easier handling the specialized versions EvaluateFeedForwardNeuralNet, EvaluateRecurrentNeuralNet and EvaluateStatefulRecurrentNeuralNet are available.
This most likely use case of this model is with a multi-layer perceptron neural network.
In order to include a neural network in Model, place this block in your own model. You have to
- give the path of the TFLite/ONNX model
- specify the number of dimensions for in and output
- specify the vector sizes in each input and output dimension
- create input and output connectors
- connect input and output connectors to the single input and single output vector of the runInference submodel
The runInference model uses a flattened vectors for input and output. The total number of elements equals the product of all input or output sizes, respectively. The user has to connect the defined input and output to the flattened vectors in the same order as they are used within created neural network.
TensorFlow Lite FlexOps
To use FlexOps with the TensorFlow Lite runtime, additional dynamic libraries must be provided in the SMArtInt library resources. Follow the steps below:
-
Copy the appropriate FlexOps library into the corresponding platform folder
(
win64orlinux64) inside the Resources Library folder:- Windows:
tensorflowlite_flex.dll - Linux:
libtensorflowlite_flex.so
- Windows:
- Activate TensorFlow Lite FlexOps usage in the model parameter dialog.
CUDA GPU Support for ONNX Runtime
To use ONNX Runtime with GPU acceleration, CUDA must be installed on the operating system (tested with CUDA version 13.0), and a CUDA-compatible GPU must be available. In addition, the required ONNX Runtime GPU provider libraries must be provided in the SMArtInt library resources. Follow the steps below:
-
Download the ONNX Runtime build with GPU support from:
ONNX Runtime v1.23.2 Release -
Select and extract the appropriate package for your operating system:
- Windows:
onnxruntime-win-x64-gpu-1.23.2.zip - Linux:
onnxruntime-linux-x64-gpu-1.23.2.tgz
- Windows:
-
Copy the required provider libraries into the corresponding platform folder
(
win64orlinux64) inside the Resources Library folder:onnxruntime_providers_cuda.dll/.soonnxruntime_providers_shared.dll/.so
- Activate GPU usage in the model parameter dialog.
Parameters
| Type | Name | Default | Description |
|---|---|---|---|
| Integer | nInputElements (from BaseNeuralNet) | product(inputSizes) | |
| Integer | nOutputElements (from BaseNeuralNet) | product(outputSizes) | |
| Selected Model | |||
| String | pathToAIModel (from BaseNeuralNet) | "" | Choose path to AI model |
| Tensor sizing | |||
| Integer | inputDimensions (from BaseNeuralNet) | 1 | Number of input dimension |
| Integer | inputSizes (from BaseNeuralNet) | {1} | Vector with size of tensor in each dimension |
| Integer | outputDimensions (from BaseNeuralNet) | 1 | Number of output dimension |
| Integer | outputSizes (from BaseNeuralNet) | {1} | Vector with size of tensor in each dimension |
| RNN Timing Settings | |||
| Boolean | stateful (from BaseNeuralNet) | false | Activate state handling for RNN with state in-/outputs |
| Real | samplePeriod (from BaseNeuralNet) | 0 | Fixed sample period for RNNs |
| Advanced › Performance | |||
| Integer | numberOfThreads (from BaseNeuralNet) | 1 | Number of threads used for inference (0: Number of CPU cores) |
| Advanced › TFLite | |||
| Boolean | useFlexOps (from BaseNeuralNet) | false | Activate to allow Tensorflow Flex Ops for tflite models |
| Advanced › ONNX | |||
| Boolean | useGPU (from BaseNeuralNet) | false | Activate to use a compatible CUDA GPU for inference |
| Integer | gpuDeviceID (from BaseNeuralNet) | 0 | CUDA device ID |
| SMArtInt.Internal.Types.ExecutionMode | executionMode (from BaseNeuralNet) | SMArtInt.Internal.Types.ExecutionMode.Sequential | Execution mode for run inference |
Connectors
| Type | Name | Default | Description |
|---|---|---|---|
| Modelica.Blocks.Interfaces.RealInput[nInputElements] | u | ||
| Modelica.Blocks.Interfaces.RealOutput[nOutputElements] | y |
Components
| Type | Name | Default | Description |
|---|---|---|---|
| Internal.Utilities.Dependencies.OnnxGpuDependencies | onnxGpuDependencies (from BaseNeuralNet) | ||
| Internal.Utilities.Dependencies.TFFlexOpsDependencies | tFFlexOpsDependencies (from BaseNeuralNet) | ||
| Internal.Utilities.RunInferenceFlatInput | runInference (from BaseGenericNeuralNet) |