Skip to content

ONNX models

ONNX Models in Machine Learning

ONNX (Open Neural Network Exchange) is an open-source format for machine learning models. This project has several major advantages:

  • ONNX is supported by large companies such as Microsoft, Facebook, Amazon and other partners.
  • Its open format enables format conversions between different machine learning toolkits, while Microsoft’sONNXMLTools allows converting models to the ONNX format.
  • MQL5 provides automatic data type conversion for model inputs and outputs if the passed parameter type does not match the model.
  • ONNX models can be created using various machine learning tools. They are currently supported in Caffe2, Microsoft Cognitive Toolkit, MXNet, PyTorch and OpenCV. Interfaces for other popular frameworks and libraries are also available.
  • With the MQL5 language, you can implement an ONNX model in a trading strategy and use it along with all the advantages of the MetaTrader 5 platform for efficient operations in the financial markets.
  • Before tunning a model for live trading, you can test the model behavior on historical data in the Strategy Tester, without using third-party tools.

MQL5 provides the following functions for working with ONNX:

FunctionAction
OnnxCreateCreate an ONNX session, loading a model from an *.onnx file
OnnxCreateFromBufferCreate an ONNX session, loading a model from a data array
OnnxReleaseClose an ONNX session
OnnxRunRun an ONNX model
OnnxGetInputCountGet the number of inputs in an ONNX model
OnnxGetOutputCountGet the number of outputs in an ONNX model
OnnxGetInputNameGet the name of a model’s input by index
OnnxGetOutputNameGet the name of a model’s output by index
OnnxGetInputTypeInfoGet the description of the input type from the model
OnnxGetOutputTypeInfoGet the description of the output type from the model
OnnxSetInputShapeSet the shape of a model’s input data by index
OnnxSetOutputShapeSet the shape of a model’s output data by index
Last updated on