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#

MODEL

Path to the input .onnx model file.

Options#

--format FORMAT / -f FORMAT

Output format (default: pretty).

  • pretty — compact text listing produced by pretty_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 by to_dot().

  • onnx-compact — Python code using the compact ONNX-compatible API.

  • builder — Python code using GraphBuilder.

  • cpp — C++ code that rebuilds the model.

--output OUTPUT / -o OUTPUT

Write the rendered output to OUTPUT instead of printing to stdout.

--shape-inference

Run onnx-light shape inference on the model before rendering.

--no-shapes

Suppress shape annotations in the rendered output (applies to mermaid, svg and dot formats).

--include-attributes

Include node attributes in the rendered output.

--include-inplace

Show in-place buffer-reuse annotations (onnx_light.inplace_reuse metadata).

--include-release

Show onnx_light.release_after and onnx_light.not_used_after lifetime annotations. Only used by the pretty format.

--include-node-tags

Show semantic shape/axes/weight/ambiguous node-tag annotations (onnx_light.node_tag metadata). Only used by the pretty format.

--no-initializers

Exclude initializer nodes from the rendered graph (applies to mermaid, svg and dot formats).

--direction DIRECTION

Flowchart direction for mermaid, svg and dot formats. One of TB (default), LR, TD or BT (Mermaid only).

--layout {layered,umap}

Selects box positioning for SVG output. layered is the default; umap requires the optional umap-learn package.

--graphviz GRAPHVIZ_FORMAT

Invoke the Graphviz dot executable on the generated DOT source and write the rendered image in GRAPHVIZ_FORMAT (e.g. png, svg, pdf). Only used when --format dot is given. Requires Graphviz to be installed and dot to be available on PATH.

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#