Join our fan page
- Views:
- 3904
- Rating:
- Published:
- 2023.03.27 12:11
- Updated:
- 2023.08.25 08:52
-
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance
The ONNX model run function requires the model's input and output sizes to be defined. The sizes are specified via the OnnxSetInputShape and OnnxSetOutputShape functions, respectively.
Not all models have fixed input and output data sizes. In these cases, the script will return -1.
OnnxTypeInfo type_info; long input_count=OnnxGetInputCount(session_handle); Print("model has ",input_count," input(s)"); for(long i=0; i<input_count; i++) { string input_name=OnnxGetInputName(session_handle,i); Print(i," input name is ",input_name); if(OnnxGetInputTypeInfo(session_handle,i,type_info)) PrintTypeInfo(i,"input",type_info); } long output_count=OnnxGetOutputCount(session_handle); Print("model has ",output_count," output(s)"); for(long i=0; i<output_count; i++) { string output_name=OnnxGetOutputName(session_handle,i); Print(i," output name is ",output_name); if(OnnxGetOutputTypeInfo(session_handle,i,type_info)) PrintTypeInfo(i,"output",type_info); }
Use the FileSelectDialog function to select a model from the MQL5\Files folder
An example of how the script runs is shown below:
Create model from mnist.onnx with debug logs ONNX: Creating and using per session threadpools since use_per_session_threads_ is true ONNX: Dynamic block base set to 0 ONNX: Initializing session. ONNX: Adding default CPU execution provider. ONNX: Removing initializer 'Parameter6'. It is no longer used by any node. ONNX: Removing initializer 'Parameter88'. It is no longer used by any node. ONNX: Total shared scalar initializer count: 0 ONNX: Removing initializer 'Parameter193_reshape1_shape'. It is no longer used by any node. ONNX: Removing initializer 'Parameter193'. It is no longer used by any node. ONNX: Total fused reshape node count: 0 ONNX: Total shared scalar initializer count: 0 ONNX: Total fused reshape node count: 0 ONNX: Removing initializer 'Parameter5'. It is no longer used by any node. ONNX: Removing initializer 'Parameter87'. It is no longer used by any node. ONNX: Use DeviceBasedPartition as default ONNX: Saving initialized tensors. ONNX: Done saving initialized tensors ONNX: Session successfully initialized. model has 1 input(s) 0 input name is Input3 type ONNX_TYPE_TENSOR data type ONNX_DATA_TYPE_FLOAT shape [1, 1, 28, 28] shape of input data can be reduced to [28, 28] model has 1 output(s) 0 output name is Plus214_Output_0 type ONNX_TYPE_TENSOR data type ONNX_DATA_TYPE_FLOAT shape [1, 10] shape of output data can be reduced to [10]
Update: Due to the fact that the OnnxTypeInfo structure was changed in build 3700, the source code of the script has been modified.
Translated from Russian by MetaQuotes Ltd.
Original code: https://www.mql5.com/ru/code/43452

Script gets information about input and output tensors of onnx-model, their types and shapes

Official example involve complex wrapper classes, Here is a simple one

Time Left To New Bar Watch

hi, this code need your telegram token and telegram chat id . you can make robot by BotFather and then search in google how you can find telegram token and chat id then attach them to this code . now every trade would be signals on your telegram channel.