1

I’m trying to export my trained model that in .pt format to ONNX but after I execute the script the program output bunch of logging stuff like in the pic below and the converted onnx format seems not appear in my local disk I don’t know what I got wrong here?

enter image description here

frankenstein
  • 125
  • 2
  • 11

1 Answers1

0

It looks like the export went fine. There should be a file "ScaledYolo4.onnx" in the directory from where you run the script.

To make sure what directory it is, you can add this at the end of your program:

import os
print(os.getcwd())

You can also try to specify the full path instead of just "ScaledYolo4.onnx".

Edit. Add this at the end of your program and run, what do you see?

import os
print(os.getcwd())
print(os.listdir())
Sergii Dymchenko
  • 6,890
  • 1
  • 21
  • 46
  • Hi , Thank for answer . I tried to give it full path but no luck, I can not find onnx converted format anywhere else in the directory I give it – frankenstein Jun 17 '21 at 02:06
  • and I just read a website it says about onnx " However, whenever a model contains control flow, like for loops or if statements, the tracer method will fail, simply because the tracer is never aware of the existence of the control flow statements, it faithfully records the flow based on the supplied input." . And my model contains control flow like if else statements. – frankenstein Jun 17 '21 at 02:16
  • The file should be there anyway, the statement is talking about completely different issue. – Sergii Dymchenko Jun 17 '21 at 03:53
  • @frankenstein Try do add the three lines from my answer at the end of your program, run and let me know what it printed. – Sergii Dymchenko Jun 17 '21 at 03:57
  • I added 2 lines of code that you said but surprisingly the program not printed it out. – frankenstein Jun 17 '21 at 04:01
  • I got the same result as indicate in the post above and did not see the output of 2 print statements – frankenstein Jun 17 '21 at 04:03
  • @frankenstein Then probably the program that actually runs is not the program you edited. Also, the `onnx.export` function shouldn't print the result unless `verbose=True` provided. Are you sure you run correct file? – Sergii Dymchenko Jun 17 '21 at 04:06
  • it looks like after execute torch.onnx.export the program is terminated – frankenstein Jun 17 '21 at 04:06
  • Can you upload the whole printout somewhere, not just the last several lines on the screenshot? – Sergii Dymchenko Jun 17 '21 at 04:07
  • absolutely yes. I ran it using terminal command. The script named debug.py and I ran it by => python debug.py in terminal – frankenstein Jun 17 '21 at 04:08
  • here https://pastebin.com/BqiFyvJ9 It outputs lots of logging stuff, I can just captured part of it from terminal. – frankenstein Jun 17 '21 at 04:13
  • What if you add the three lines and comment out the call to the export. What do you see? – Sergii Dymchenko Jun 17 '21 at 04:17
  • i see. : /home/heligate/Documents/ScaledYOLOv4/ScaledYOLOv4 ['config.py', 'detections_val2017__results.json', 'yolov4-p5.pt', 'utils', 'data', 'experiment.py', '.git', 'train.py', 'yolov5s.pt', 'detect_marutrek.py', 'weights', 'convert_pt2onnx.py', 'detect.py', 'best-yolov4-csp.pt', 'debug.py', 'copyimg_copy.py', 'debug_model', 'test.py', 'README.md', 'runs', 'result', 'last_yolov4-csp.pt', '.vscode', '.gitignore', 'copyimg.py', 'models', '__pycache__'] – frankenstein Jun 17 '21 at 04:19
  • and of course there is no onnx version :( – frankenstein Jun 17 '21 at 04:21
  • I don't know then. Maybe out of disk space? What's in the beginning on debug.py? I wonder why the onnx network is even printed to the standard output. – Sergii Dymchenko Jun 17 '21 at 04:24
  • the disk space has more than 62GB, here is the screenshot of the directory structure, let take a look https://drive.google.com/file/d/1PZvE4vkaiYZU_rkLlWPrq0yE4SOfaIuj/view?usp=sharing – frankenstein Jun 17 '21 at 04:30
  • actually , I went through tutorial on pytorch website on how to convert model .pt to onnx and the code works just fine with pretrained weights but on my trained weights with custom datasets the result like you know... – frankenstein Jun 17 '21 at 04:34
  • I'm out of ideas. Without `verbose=True` the export should not print the network, and the screenshot you posted doesn't have `verbose=True` in the export command. And the file should be saved unless there is an error, and I don't see any errors from the printout you posted (warnings are fine). Maybe there is an error in the omitted printout part? – Sergii Dymchenko Jun 17 '21 at 04:37
  • I don't know then, I struggled with this from the day before yesterday lol – frankenstein Jun 17 '21 at 04:41
  • I just read about ONNX exporter on pytorch offical website . They said " If your model contains control flows like for loops and if conditions, trace-based exporter will unroll the loops and if conditions, exporting a static graph that is exactly the same as this run. If you want to export your model with dynamic control flows, you will need to use the script-based exporter." Here is the link https://pytorch.org/docs/master/onnx.html – frankenstein Jun 17 '21 at 06:50
  • And my model does contains a lot of if else and for loop statements, that might be the case – frankenstein Jun 17 '21 at 06:51
  • No, that just means that the ONNX model output may be different from PyTorch output if input that controls `if` or loop changes. The model should export fine still. – Sergii Dymchenko Jun 17 '21 at 07:17
  • Double check that there is no errors in the onnx.export output, the pastebin doesn't have everything. – Sergii Dymchenko Jun 17 '21 at 07:18
  • 1
    if I can fix it I will let you know. – frankenstein Jun 17 '21 at 07:31
  • 1
    I did it. I convert the .pt file to .weights that was written in darknet then from that I convert .weights to Onnx. Thank you for your time buddy – frankenstein Jun 17 '21 at 08:18