onnx-simplifier
onnx-simplifier copied to clipboard
[Feature] Eliminate unnecessary Transpose nodes in ONNX models ported from tensorflow models
Hello, good work for practical use! However, some ONNX models which are ported from tensorflow models has some unnecessary Tranpose nodes. For example, the input of the ported ONNX model has input shape of 1x256x256x3, and follows by a Transpose node which transposes the shape to 1x3x256x256. As ONNX claims (https://github.com/onnx/onnx-tensorflow/issues/779#issuecomment-769258601) that NCHW is the input shape format that is officially supported, I wonder if we can add this feature to the onnx-simplifier.
I process input orders using a tool that I have created myself. However, I think the idea of adding an option to onnx-simplifier is great. :smile:
- "Very simple NCHW and NHWC conversion tool for ONNX. Change to the specified input order for each and every input OP. Also, change the channel order of RGB and BGR. Simple Channel Converter for ONNX."
- https://github.com/PINTO0309/scc4onnx
- https://github.com/PINTO0309/simple-onnx-processing-tools
Also, although not a perfect implementation, to avoid useless Transpose extrapolation in onnx-tensorflow, I have also created a tool that automatically converts the entire model NCHW to NHWC. However, using this tool is a bit cumbersome.
- "This script converts the ONNX/OpenVINO IR model to Tensorflow's saved_model, tflite, h5, tfjs, tftrt(TensorRT), CoreML, EdgeTPU, ONNX and pb. PyTorch (NCHW) -> ONNX (NCHW) -> OpenVINO (NCHW) -> openvino2tensorflow -> Tensorflow/Keras (NHWC/NCHW) -> TFLite (NHWC/NCHW). And the conversion from .pb to saved_model and from saved_model to .pb and from .pb to .tflite and saved_model to .tflite and saved_model to onnx. Support for building environments with Docker. It is possible to directly access the host PC GUI and the camera to verify the operation. NVIDIA GPU (dGPU) support. Intel iHD GPU (iGPU) support." https://github.com/PINTO0309/openvino2tensorflow
If this is not very helpful, please ignore it.