ZhangGe6 / onnx-modifier

A tool to modify ONNX models in a visualization fashion, based on Netron and Flask.
MIT License
1.28k stars 157 forks source link

Cannot always add outputs #75

Closed mcusgithub closed 10 months ago

mcusgithub commented 1 year ago

Same as #57 (reopening) Same issue as before (tested with YOLOv8n this time), and the initial workaround does not work anymore unfortunately. For instance: 1) delete final "concat" op, 2) create one "output" for each concat (now deleted) input (2 total), 3) save, 4) reload = outputs are missing (and/or have the wrong shape depending on some unknown condition)

mcusgithub commented 1 year ago

New workaround (not sure if all save/reload steps are required): Add a temporary "shape" operator where the "output" is needed, save (with shape inference = on, clean up = off), reload, add the "output" operator (same input as "shape" op), save again, reload, delete the temporary "shape" operator, save again. I suspect that the issue has something to do with the "output" operator failing to get / evaluate the right tensor dimensions. Adding a temporary "shape" operator may help passing the right shape values to the output layer when added.

Thanks for developing and supporting onnx-modifier!

ZhangGe6 commented 11 months ago

@mcusgithub Thanks for reporting. The issue of "adding output" is really our old friend. It is usually caused by unperfect auto shape inference. I have tried to fix it by using onnx-tool for shape inference. With the latest code, the editing of both the YOLOv8n and the squeezenet in #57 works as expected.

issue75