OnnxRun failure

 

Hi community,


I'll try to run my onnx model without any success. Here after are the steps :

- I use OnnxCreateFromBuffer to create my handle from my model --> it's ok my handle is not invalid

   onnxModel=OnnxCreateFromBuffer(ExtModel1,ONNX_DEFAULT);
   if(onnxModel==INVALID_HANDLE)
     {
      Print("First model OnnxCreateFromBuffer error ",GetLastError());
      return(INIT_FAILED);
     }

- I use OnnxSetInputShape and OnnxSetOutputShape to set the tensors with success

   const long input_shape[] = {1,30,6};
   if(!OnnxSetInputShape(onnxModel,0,input_shape))
     {
      Print("OnnxSetInputShape error ",GetLastError());
      OnnxRelease(onnxModel);
      return(INIT_FAILED);
     }

   const long output_shape[] = {1,1,1};
   if(!OnnxSetOutputShape(onnxModel,0,output_shape))
     {
      Print("OnnxSetOutputShape error ",GetLastError());
      OnnxRelease(onnxModel);
      return(INIT_FAILED);
     }

- I prepare my matrixf and vectorf for inputs and outputs

   double buff[];
   double min,max;
   static vectorf output_data(1);
   static matrixf inputData;
   
   inputData.Init(30,6);
   
   CopyOpen(_Symbol,_Period,0,30,buff); for (int i=0; i<30; i++) inputData[i][0] = buff[i];
   CopyHigh(_Symbol,_Period,0,30,buff); for (int i=0; i<30; i++) inputData[i][1] = buff[i];
   CopyLow(_Symbol,_Period,0,30,buff); for (int i=0; i<30; i++) inputData[i][2] = buff[i];
   CopyClose(_Symbol,_Period,0,30,buff); for (int i=0; i<30; i++) inputData[i][3] = buff[i];
   CopyBuffer(mma1,0,0,30,buff); for (int i=0; i<30; i++) inputData[i][4] = buff[i];
   CopyBuffer(mma2,0,0,30,buff); for (int i=0; i<30; i++) inputData[i][5] = buff[i];
   
   // normalisation
   min = inputData.Min();
   max = inputData.Max();
   inputData = (inputData - min)/(max - min);

- When I use the OnnxRun function I get this following error :

   if(!OnnxRun(onnxModel,ONNX_DEBUG_LOGS | ONNX_NO_CONVERSION,inputData,output_data))
     {
      Print("Echec de OnnxRun, erreur ",GetLastError()); 
      return; 
     }

ONNX: execute OnnxRun failed (OrtStatus: 6 '')


Someone can help me to understand this error ? What I made wrong ?


In attached file my onnx model.


Many thanks !

Files:
model02.zip  235 kb
 
Your topic has been moved to the section: Expert Advisors and Automated Trading — In the future, please consider which section is most appropriate for your query.
 

Hi,

After research I found the problem --> It's my model which is bad (output shape [-1,-1,1])

 

I also had this issue and will post an example so its clear how to fix.

First, you can double click your onnx file to inspect it

the ? in the shape is because my model can predict multiple samples at once.
Here is how it looks in MQL to set up those parameters.


And here is how you create and  pass your pointers


Hope this helps anyone else who comes looking, took me AGES to work this out.

 
Erwann Pannerec #:

Hi,

After research I found the problem --> It's my model which is bad (output shape [-1,-1,1])

Hi Erwann, could you please share more about what you learned from your research into setting the input and output shape cause I'm getting an error setting the input shape is giving me headaches bro...  

 

ONNX


This is what my ONNX model looks like in the MT5 editor, it has one output, it's a binary classifier. It classifies the next candle as being up or down.