ONNX Simplifier (onnxsim) is a Python library designed to reduce the complexity of ONNX models by inferring the computation graph and performing constant folding. This makes ONNX models more efficient for inference and deployment. It is actively maintained with frequent minor releases, currently at version 0.6.2.
pip install onnxsimVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to load an ONNX model, simplify it using `onnxsim.simplify`, and save the optimized model. A dummy PyTorch model is created and exported to ONNX for a complete runnable example.
Ensure `cmake` and a C++ compiler (like GCC or MSVC) are installed on your system before attempting `pip install onnxsim`.
Consider splitting very large models into smaller subgraphs if possible, or investigate advanced techniques for handling large ONNX models outside the typical workflow.
Ensure the input ONNX model adheres to the ONNX specification regarding graph topology. Tools like Netron can help visualize and debug model graphs.
Remove the `--enable-fuse-bn` flag. If you need to skip this optimization, use `--skip-fuse-bn` instead.
Pass a dictionary mapping input names to their expected (or example) shapes, e.g., `simplify(model, input_shapes={'input_name': [1, 3, 224, 224]})` or `onnxsim input.onnx output.onnx --input-shape input_name:1,3,224,224`.