Recent

Author Topic: AI Vision ONNXRuntime Loading model issue  (Read 1195 times)

Jonvy

  • Full Member
  • ***
  • Posts: 102
AI Vision ONNXRuntime Loading model issue
« on: August 02, 2024, 05:33:40 am »
Hello everyone,

I tried  ONNXRuntime sample from github:https://github.com/hshatti/TONNXRuntime/tree/main/examples/Lazarus/FasterRCNN10

When I select the model, I get this error, can anyone help me what's wrong with the code?

Jonvy
« Last Edit: August 02, 2024, 12:22:40 pm by Jonvy »

domasz

  • Hero Member
  • *****
  • Posts: 527
Re: AI modlel ONNXRuntime sample issue
« Reply #1 on: August 02, 2024, 08:53:27 am »
Move you .EXE to the folder with your .ONNX

Jonvy

  • Full Member
  • ***
  • Posts: 102
Re: AI modlel ONNXRuntime sample issue
« Reply #2 on: August 02, 2024, 09:06:52 am »
Yes,they're in same folder.

Jonvy

  • Full Member
  • ***
  • Posts: 102
Re: AI modlel ONNXRuntime sample issue
« Reply #3 on: August 02, 2024, 09:26:15 am »
Looks like sample's onnx model format has problem, I get error information from Netron.

But if I choose my own correct model,best_simply.onnx, it will raise another error.

Can anyone succesfully use this example?

myisjwj

  • Jr. Member
  • **
  • Posts: 78
Re: AI Vision ONNXRuntime Loading model issue
« Reply #4 on: August 02, 2024, 02:13:43 pm »
Your model looks like a YOLO. Instead of using the FasterRCNN10 example, you can refer to the YoloV7_GPU example to implement it. You can also look at this address
https://www.cnblogs.com/jwjss/p/18263154

Jonvy

  • Full Member
  • ***
  • Posts: 102
Re: AI Vision ONNXRuntime Loading model issue
« Reply #5 on: August 03, 2024, 04:01:31 am »
Yes,my model is YOLOv5, I wonder why Haitham Shatti's example not working. I just use his FasterRCNN-10 model, still not working.

For YoloV7_GPU model, I can not use it, it's for Delphi, even convert from lazaurs, it will lost many units.

Follow your blog, I modified line 2487 in onnxruntime.pas, is that what your mean?

After this, still get error when loading model FasterRCNN-10:Protobuf parsing failed.

I download another model,yolov7-tiny_640x640, it can be loaded, after loading model, when I load source Image, it will get exception: Access violation.

Jonvy

  • Full Member
  • ***
  • Posts: 102
Re: AI Vision ONNXRuntime Loading model issue
« Reply #6 on: August 03, 2024, 04:02:34 am »
exception when load image.

myisjwj

  • Jr. Member
  • **
  • Posts: 78
Re: AI Vision ONNXRuntime Loading model issue
« Reply #7 on: August 04, 2024, 04:18:43 am »
Lazarus calls the Yolo example
Code: Pascal  [Select][+][-]
  1. {$mode delphi}{$H+}
  2. interface
  3. uses
  4. onnxruntime_pas_api,onnxruntime;
  5. var
  6.   session:TORTSession;
  7. InputNames,OutputNames:array of string;
  8. input_w,input_h,output_w,output_h:Integer;
  9. img: TBitmap;
  10. input:TOrtTensor<single>;
  11. tempp:PByte;
  12. inputs,outputs:TORTNameValueList;
  13. outTensor: TOrtTensor<single>;
  14.  
  15.  
  16. //InitOnnxrun
  17. session := TORTSession.Create(YouModFile);
  18. setLength(InputNames, Session.GetInputCount());
  19.     for i := 0 to High(InputNames) do
  20.     begin
  21.       Info := Session.GetInputTypeInfo(i);
  22.       InputNames[i] := string(session.GetInputNameAllocated(i, DefaultAllocator)
  23.         {$ifndef NO_SMARTPTR}
  24.         .Instance
  25.         {$endif}
  26.         );
  27.       tensorInfo := Info.GetTensorTypeAndShapeInfo();
  28.       ints := tensorInfo.GetShape();
  29.       input_w := ints[3];
  30.       input_h := ints[2];
  31.     end;
  32.     setLength(OutputNames, Session.GetOutputCount());
  33.     for i := 0 to High(OutputNames) do
  34.     begin
  35.       Info := Session.GetOutputTypeInfo(i);
  36.       OutputNames[i] := string(session.GetOutputNameAllocated(i, DefaultAllocator)
  37.         {$ifndef NO_SMARTPTR}
  38.         .Instance
  39.         {$endif}
  40.         );
  41.       if OutputNames[i].IndexOf('output') >= 0 then
  42.       begin
  43.         tensorInfo := Info.GetTensorTypeAndShapeInfo();
  44.         ints := tensorInfo.GetShape();
  45.         output_w := ints[2];
  46.         output_h := ints[1];
  47.         outst:=OutputNames[i];
  48.       end;
  49.     end;
  50.  
  51. //run
  52. img:=TBitmap.Create;
  53.   img.Width:=input_w;
  54.   img.Height:=input_h;
  55.   img.PixelFormat:=pf24bit;
  56. .....
  57. Input := TOrtTensor<single>.Create([input_w, input_h, 3, 1]);
  58.     for yy := 0 to input_h - 1 do
  59.     begin
  60.       tempp := img.ScanLine[yy];
  61.       for xx := 0 to input_w - 1 do
  62.       begin
  63.         input.Index3[xx, yy, 0] := tempp[xx * 3 ] / 255;
  64.         input.Index3[xx, yy, 1] := tempp[xx * 3 + 1] / 255;
  65.         input.Index3[xx, yy, 2] := tempp[xx * 3+ 2] / 255;
  66.       end;
  67.     end;
  68.     inputs.AddOrSetValue('images', input);
  69. Outputs:=session.Run(Inputs);

Jonvy

  • Full Member
  • ***
  • Posts: 102
Re: AI Vision ONNXRuntime Loading model issue
« Reply #8 on: August 05, 2024, 10:09:44 am »
OK, I'll study this example,thanks myisjwj!
« Last Edit: August 10, 2024, 03:05:41 am by Jonvy »

 

TinyPortal © 2005-2018