ONNX Model Predict
Libraries:
Deep Learning Toolbox /
Python Neural Networks
Description
The ONNX Model Predict block predicts responses using a pretrained Python®
ONNX™ model running in the MATLAB® Python environment. MATLAB supports the reference implementation of Python,
often called CPython. If you are on a Mac or Linux® platform, you already have Python installed. If you use a Mac or Linux® platform, you already have Python installed. If you use Windows®, you need to install a distribution, such as those found at https://www.python.org/downloads/. For
more information, see Configure Your System to Use Python. Your MATLAB Python environment must have the
onnxruntime
module installed. The ONNX Model Predict block has
been tested using Python version 3.10 and onnxruntime
version
1.14.1.
Load a Python model into the block by specifying the path to an ONNX model file that you saved in Python. You can optionally load a Python function to preprocess the input data that Simulink® passes to the Python model, and a Python function to postprocess the predicted responses from the model.
The input port In1 receives input data, optionally rearranges the input array dimensions, and converts the input data to a Python array. The preprocessing function (if specified) processes the converted data in Python and passes it to the ONNX model. The model generates predicted responses for the input data in Python and passes the responses to the Python postprocessing function (if specified). The output port Out1 returns the predicted responses.
You can add and configure input and output ports using the Inputs and Outputs tabs of the Block Parameters dialog box (see Inputs and Outputs). The software attempts to automatically populate the table in each tab when you click the Autofill Fields From Model File button on the Specify model file tab.
Note
You cannot run the ONNX Model Predict block in Rapid Accelerator mode.
Examples
Ports
Input
Output
Parameters
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
Version History
Introduced in R2024a
See Also
Blocks
- PyTorch Model Predict | TensorFlow Model Predict | Custom Python Model Predict | Scikit-learn Model Predict (Statistics and Machine Learning Toolbox)