.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples_core/plot_print_command.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_core_plot_print_command.py: .. _l-plot-print-command: Command Line: ``python -m yobx print`` ======================================= This example builds a small ONNX model, saves it to a temporary file, and then demonstrates the different output formats produced by the ``python -m yobx print`` command. The same result can be achieved from the terminal with:: python -m yobx print pretty model.onnx python -m yobx print printer model.onnx python -m yobx print dot model.onnx .. GENERATED FROM PYTHON SOURCE LINES 17-26 .. code-block:: Python import os import tempfile import onnx import onnx.helper as oh from yobx._command_lines_parser import _cmd_print TFLOAT = onnx.TensorProto.FLOAT .. GENERATED FROM PYTHON SOURCE LINES 27-31 Build a small ONNX model ------------------------ The graph computes ``Z = Relu(X + Y)`` with static shapes ``(2, 3)``. .. GENERATED FROM PYTHON SOURCE LINES 31-51 .. code-block:: Python model = oh.make_model( oh.make_graph( [oh.make_node("Add", ["X", "Y"], ["added"]), oh.make_node("Relu", ["added"], ["Z"])], "add_relu", [ oh.make_tensor_value_info("X", TFLOAT, [2, 3]), oh.make_tensor_value_info("Y", TFLOAT, [2, 3]), ], [oh.make_tensor_value_info("Z", TFLOAT, [2, 3])], ), opset_imports=[oh.make_opsetid("", 18)], ir_version=10, ) # Save to a temporary file so the CLI helpers can load it. fd, tmp = tempfile.mkstemp(suffix=".onnx") os.close(fd) onnx.save(model, tmp) .. GENERATED FROM PYTHON SOURCE LINES 52-59 ``pretty`` format ----------------- The default format produced by :func:`yobx.helpers.onnx_helper.pretty_onnx`. It shows opset, inputs/outputs, and every node in a compact, human-readable layout. .. GENERATED FROM PYTHON SOURCE LINES 59-64 .. code-block:: Python print("python -m yobx print pretty model.onnx") print("-" * 40) _cmd_print(["print", "pretty", tmp]) .. rst-class:: sphx-glr-script-out .. code-block:: none python -m yobx print pretty model.onnx ---------------------------------------- opset: domain='' version=18 input: name='X' type=dtype('float32') shape=[2, 3] input: name='Y' type=dtype('float32') shape=[2, 3] Add(X, Y) -> added Relu(added) -> Z output: name='Z' type=dtype('float32') shape=[2, 3] .. GENERATED FROM PYTHON SOURCE LINES 65-70 ``printer`` format ------------------ Uses the built-in ``onnx.printer.to_text`` renderer which produces the official ONNX text representation. .. GENERATED FROM PYTHON SOURCE LINES 70-75 .. code-block:: Python print("python -m yobx print printer model.onnx") print("-" * 40) _cmd_print(["print", "printer", tmp]) .. rst-class:: sphx-glr-script-out .. code-block:: none python -m yobx print printer model.onnx ---------------------------------------- < ir_version: 10, opset_import: ["" : 18] > add_relu (float[2,3] X, float[2,3] Y) => (float[2,3] Z) { added = Add (X, Y) Z = Relu (added) } .. GENERATED FROM PYTHON SOURCE LINES 76-82 ``dot`` format -------------- Dumps the DOT graph source. Pipe the output to ``dot -Tsvg`` to get a visual representation of the graph (see also :func:`yobx.helpers.dot_helper.to_dot`). .. GENERATED FROM PYTHON SOURCE LINES 82-86 .. code-block:: Python print("python -m yobx print dot model.onnx") print("-" * 40) _cmd_print(["print", "dot", tmp]) .. rst-class:: sphx-glr-script-out .. code-block:: none python -m yobx print dot model.onnx ---------------------------------------- digraph { graph [rankdir=TB, splines=true, overlap=false, nodesep=0.2, ranksep=0.2, fontsize=8]; node [style="rounded,filled", color="#888888", fontcolor="#222222", shape=box]; edge [arrowhead=vee, fontsize=7, labeldistance=-5, labelangle=0]; I_0 [label="X\nFLOAT(2,3)", fillcolor="#aaeeaa"]; I_1 [label="Y\nFLOAT(2,3)", fillcolor="#aaeeaa"]; Add_2 [label="Add(., .)", fillcolor="#cccccc"]; Relu_3 [label="Relu(.)", fillcolor="#cccccc"]; I_0 -> Add_2 [label="FLOAT(2,3)"]; I_1 -> Add_2 [label="FLOAT(2,3)"]; Add_2 -> Relu_3 [label="FLOAT(2,3)"]; O_4 [label="Z\nFLOAT(2,3)", fillcolor="#aaaaee"]; Relu_3 -> O_4; } .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.170 seconds) .. _sphx_glr_download_auto_examples_core_plot_print_command.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_print_command.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_print_command.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_print_command.zip ` .. include:: plot_print_command.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_