A collection of small, focused Python CLI utilities for inspecting, converting, quantizing, and translating ONNX models.
Each script is self-contained, takes its inputs via argparse (no hard-coded
paths), and follows the conventions in the python-sdlc skill: type-annotated
signatures, Google-style docstrings, and an if __name__ == "__main__": guard.
| Script | Purpose |
|---|---|
find_opset.py |
Print the opset domains and versions imported by a model. |
inspect_onnx.py |
Print name/inputs/outputs of nodes matching an op type (default Conv). |
onnx_find_nodes.py |
List input/output tensor names via onnxruntime. |
set_onnx_opset_version.py |
Convert a model to a different (usually earlier) opset version. |
quantize_onnx.py |
Dynamically quantize a model to int8 weights. |
preprocess_quantize_onnx.py |
Run shape-inference pre-processing, then dynamic quantization. |
convert_onnx_pb.py |
Convert an ONNX model to a TensorFlow .pb graph (onnx_tf). |
- Python 3.10–3.13 (pinned to 3.12 via
.python-version) onnx,onnxruntime(core)onnx-tf,tensorflow(only forconvert_onnx_pb.py, optional extra)
This project uses uv for dependency management.
Dependencies, the Python version, the lockfile, and dev tooling (ruff, mypy,
pytest) are all declared in pyproject.toml.
Create the virtual environment and install the core + dev dependencies:
uv syncuv reads .python-version (3.12) and creates .venv/ automatically.
For the TensorFlow conversion script, install the optional tf extra:
uv sync --extra tfAlways run scripts through the uv-managed environment with uv run:
uv run python find_opset.py --help
uv run python find_opset.py --helpuv run ruff check . # lint
uv run ruff format . # format
uv run mypy *.py # type check
uv run pytest # tests (none yet)Every script supports --help:
uv run python find_opset.py --helpuv run python find_opset.py --model-path model.onnxOutput:
Domain: ai.onnx, Opset Version: 17
# All Conv nodes (default)
uv run python inspect_onnx.py --model-path model.onnx
# A different op type
uv run python inspect_onnx.py --model-path model.onnx --op-type Reluuv run python onnx_find_nodes.py --model-path model.onnx# Default target opset is 13; output defaults to model_op13.onnx
uv run python set_onnx_opset_version.py --model-input model.onnx --target-opset 13
# Explicit output path
uv run python set_onnx_opset_version.py --model-input model.onnx --target-opset 13 --model-output model_op13.onnx# Quick quantization — output defaults to model_int8.onnx
uv run python quantize_onnx.py --model-input model.onnx
# Unsigned weights + explicit output
uv run python quantize_onnx.py --model-input model.onnx --weight-type QUInt8 --model-output model.uint8.onnxShape inference before quantization often yields a better-behaved model. Output paths embed the detected opset version by default:
uv run python preprocess_quantize_onnx.py --model-input model.onnx
# -> model_preprocessed_opset17.onnx and model_opset17_int8.onnxOverride the derived paths if needed:
uv run python preprocess_quantize_onnx.py \
--model-input model.onnx \
--preprocessed-output model.pre.onnx \
--quantized-output model.int8.onnx \
--weight-type QUInt8# Output defaults to model_tf_model.pb
uv run python convert_onnx_pb.py --model-input model.onnx
# Explicit output
uv run python convert_onnx_pb.py --model-input model.onnx --model-output graph.pbNote:
convert_onnx_pb.pyproduces a TensorFlow graph (.pb), not a PyTorch model.
These utilities follow the python-sdlc skill (a global Pi skill distilled
from rishapgandhi/python-skills):
- No hard-coded paths or magic constants. Every file path, opset version,
and output suffix is an
argparseflag with a sensible default. - Type annotations on all function signatures (
from __future__ import annotationsfor forward compatibility). - Google-style docstrings with
Args/Returns/Raisessections. if __name__ == "__main__":guards withsys.exit(main())so each script is importable and testable.
Unspecified — see the original repository history for provenance.