- ONNX支持
- 格式转换
- 自动数据类型转换
- 创建模型
- 运行模型
- 运行策略测试
- OnnxCreate
- OnnxCreateFromBuffer
- OnnxRelease
- OnnxRun
- OnnxGetInputCount
- OnnxGetOutputCount
- OnnxGetInputName
- OnnxGetOutputName
- OnnxGetInputTypeInfo
- OnnxGetOutputTypeInfo
- OnnxSetInputShape
- OnnxSetOutputShape
- 数据结构
运行模型
要在MQL5中运行ONNX模型,请完成以下3个步骤:
- 使用OnnxCreate函数从*.onnx文件中加载模型或使用OnnxCreateFromBuffer函数从数组中加载模型。
- 使用OnnxSetInputShape和OnnxSetOutputShape函数指定输入和输出数据形状。
- 使用OnnxRun函数运行模型,并将相关的输入和输出参数传递到这里。
- 当需要时,您可以使用OnnxRelease函数终止模型操作。
在创建ONNX模型时,您应该考虑现有的范围和限制,请参阅https://github.com/microsoft/onnxruntime/blob/rel-1.14.0/docs/OperatorKernels.md
这类限制的一些示例如下:
Operation |
支持的数据类型 |
---|---|
ReduceSum |
tensor(double), tensor(float), tensor(int32), tensor(int64) |
Mul |
tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64) |
下面是来自公共项目ONNX.Price.Prediction的MQL5代码示例。
const long ExtOutputShape[] = {1,1}; // 模型输出形状
|
Script run example:
ONNX: Creating and using per session threadpools since use_per_session_threads_ is true
|
The MetaTrader 5 terminal has selected the optimal executor for calculations ― ONNX Runtime Execution Provider. In this example, the model was executed on the CPU.
Let's modify the script to calculate the percentage of successful Close price predictions made based on the values of the preceding 10 bars.
#resource "Python/model.onnx" as uchar ExtModel[]// 作为资源的模型
|
运行脚本:预测准确率约为51%
ONNX: Creating and using per session threadpools since use_per_session_threads_ is true
|