show#
Loads an ONNX model and renders it as plain text, a Mermaid flowchart, an SVG image, Graphviz DOT source, Python code, or C++ code. The result is written to stdout by default.
python -m onnx_light show model.onnx
Synopsis:
python -m onnx_light show MODEL
[--format {pretty,mermaid,svg,dot,onnx-compact,builder,cpp}]
[--output OUTPUT]
[--shape-inference]
[--no-shapes]
[--include-attributes]
[--include-inplace]
[--include-release]
[--include-node-tags]
[--no-initializers]
[--direction DIRECTION]
[--layout {layered,umap}]
[--graphviz GRAPHVIZ_FORMAT]
Positional argument#
MODELPath to the input
.onnxmodel file.
Options#
--format FORMAT/-f FORMATOutput format (default:
pretty).pretty— compact text listing produced bypretty_onnx().mermaid— Mermaid flowchart source that can be embedded in Markdown or rendered with the Mermaid CLI.svg— SVG image written to stdout (or to the file given by--output).dot— Graphviz DOT source produced byto_dot().onnx-compact— Python code using the compact ONNX-compatible API.builder— Python code usingGraphBuilder.cpp— C++ code that rebuilds the model.
--output OUTPUT/-o OUTPUTWrite the rendered output to OUTPUT instead of printing to stdout.
--shape-inferenceRun onnx-light shape inference on the model before rendering.
--no-shapesSuppress shape annotations in the rendered output (applies to
mermaid,svganddotformats).--include-attributesInclude node attributes in the rendered output.
--include-inplaceShow in-place buffer-reuse annotations (
onnx_light.inplace_reusemetadata).--include-releaseShow
onnx_light.release_afterandonnx_light.not_used_afterlifetime annotations. Only used by theprettyformat.--include-node-tagsShow semantic shape/axes/weight/ambiguous node-tag annotations (
onnx_light.node_tagmetadata). Only used by theprettyformat.--no-initializersExclude initializer nodes from the rendered graph (applies to
mermaid,svganddotformats).--direction DIRECTIONFlowchart direction for
mermaid,svganddotformats. One ofTB(default),LR,TDorBT(Mermaid only).--layout {layered,umap}Selects box positioning for SVG output.
layeredis the default;umaprequires the optionalumap-learnpackage.--graphviz GRAPHVIZ_FORMATInvoke the Graphviz
dotexecutable on the generated DOT source and write the rendered image in GRAPHVIZ_FORMAT (e.g.png,svg,pdf). Only used when--format dotis given. Requires Graphviz to be installed anddotto be available onPATH.
Examples#
Print a compact text summary to stdout:
python -m onnx_light show model.onnx
Run shape inference first, then show the model:
python -m onnx_light show model.onnx --shape-inference
Render a Mermaid flowchart and save it to a file:
python -m onnx_light show model.onnx --format mermaid -o model.mmd
Generate an SVG with a left-to-right layout:
python -m onnx_light show model.onnx --format svg --direction LR -o model.svg
Show the model without initializer nodes and without shape annotations:
python -m onnx_light show model.onnx --format mermaid --no-initializers --no-shapes
Dump the Graphviz DOT source to a file:
python -m onnx_light show model.onnx --format dot -o model.dot
Render a PNG image via Graphviz (requires dot on PATH):
python -m onnx_light show model.onnx --format dot --graphviz png -o model.png
Generate Python or C++ code that rebuilds the model:
onnx-light show model.onnx --format onnx-compact -o model_compact.py
onnx-light show model.onnx --format builder -o model_builder.py
onnx-light show model.onnx --format cpp -o model.cc
See also#
pretty_onnx()— the Python function used by theprettyformat.to_dot()— the Python function used by thedotformat.How-to Python / C++ — other onnx-light how-to recipes.