onnx-tool
raw JSON → 1.0.1 verified Sat May 09 auth: no python
A library for parsing, editing, optimizing, and profiling ONNX models. Current version 1.0.1, no defined release cadence. Primarily used for model analysis and shape inference.
pip install onnx-tool Common errors
error AttributeError: module 'onnx_tool' has no attribute 'model' ↓
cause Incorrect import path; trying to import from a submodule that doesn't exist.
fix
Use 'from onnx_tool import ModelParser' instead of 'from onnx_tool.model import ModelParser'.
error ImportError: cannot import name 'extract_subgraph' from 'onnx_tool' ↓
cause The function was removed in version 1.0.0; use onnx.utils.Extractor instead.
fix
Use onnx.utils.Extractor for subgraph extraction.
error TypeError: 'NoneType' object is not iterable when calling graph_info() ↓
cause The model has no nodes or the graph is malformed; often due to loading a non-ONNX file.
fix
Verify the model file is valid ONNX using onnx.checker.check_model(model).
error onnx_tool.profiler.ProfilerError: Missing 'parameters' field in node ↓
cause ONNX opset version is too old or node attributes are missing; profiler expects certain fields.
fix
Upgrade ONNX model opset or ensure nodes have required attributes (e.g., kernel_shape for Conv).
Warnings
gotcha onnx-tool expects ONNX models in protobuf format; ensure you use onnx.load() rather than onnx.load_model() which is deprecated in newer ONNX versions. ↓
fix Use onnx.load(model_path) to load the model.
gotcha The ModelParser's graph_info() may return different keys across versions; always handle dictionary keys dynamically. ↓
fix Iterate over keys with .items() and check for presence.
deprecated The function 'infer_shapes' has been moved to a separate module 'shape_inference' in some versions; check documentation. ↓
fix Use from onnx_tool.shape_inference import infer_shapes if available.
breaking Version 1.0.0 changed the base class for ModelParser; existing code inheriting from it may break. ↓
fix Update subclass to match new API; see changelog.
Imports
- ModelParser wrong
from onnx_tool.model import ModelParsercorrectfrom onnx_tool import ModelParser - profiler wrong
from onnx_tool.profile import profilercorrectfrom onnx_tool import profiler
Quickstart
from onnx_tool import ModelParser
import onnx
# Load an ONNX model
model_path = 'model.onnx'
model = onnx.load(model_path)
# Create parser and get model graph info
parser = ModelParser(model)
print(parser.graph_info())