An EA can detect a wrong ONNX model in OnInit, before its first prediction, instead of failing or returning other probabilities in OnTick. COnnxContract checks the model's signature, features, class labels, and SHA-256 hash against a contract file. COnnxParity compares the terminal's probabilities with onnxruntime on a golden file of reference rows, and a Python tool builds both files from your data. The tool also audits the EA's prediction log, because a golden pass covers only its own rows.
My first ONNX helper class for this article failed in a way I did not see at first. It created the session, set the input shape, and called OnnxRun() with one buffer for the predicted label. The model was a scikit-learn pipeline with two outputs, the label and the class probabilities. So every call failed with error 5804, and the journal said "incorrect parameters count passed to OnnxRun, expected 3 instead of 2". My own test script then reported 50 rows with 0 matches and 0 mismatches, and still printed PASS. The model was fine. The code around it was wrong, and the test could not tell.
That mistake changed the topic of the article. Exporting a model to ONNX is well covered on MQL5. I did not find a set of checks for an EA to run in OnInit before its first prediction. So I wrote three classes and a Python tool:
The checks answer different questions. The hash shows whether the file is byte for byte the one the contract was written for. The signature check shows whether the code can call the model at all. The golden file shows whether the terminal computes the same numbers as onnxruntime on the rows in that file. None of them says whether the model is any good, and the golden file says nothing about rows outside it.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Check out the new article: Does the Terminal Run the Model You Trained? ONNX Contract and Golden-File Checks in MQL5.
My first ONNX helper class for this article failed in a way I did not see at first. It created the session, set the input shape, and called OnnxRun() with one buffer for the predicted label. The model was a scikit-learn pipeline with two outputs, the label and the class probabilities. So every call failed with error 5804, and the journal said "incorrect parameters count passed to OnnxRun, expected 3 instead of 2". My own test script then reported 50 rows with 0 matches and 0 mismatches, and still printed PASS. The model was fine. The code around it was wrong, and the test could not tell.
That mistake changed the topic of the article. Exporting a model to ONNX is well covered on MQL5. I did not find a set of checks for an EA to run in OnInit before its first prediction. So I wrote three classes and a Python tool:
The checks answer different questions. The hash shows whether the file is byte for byte the one the contract was written for. The signature check shows whether the code can call the model at all. The golden file shows whether the terminal computes the same numbers as onnxruntime on the rows in that file. None of them says whether the model is any good, and the golden file says nothing about rows outside it.
Author: Ali Akbar