mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-15 18:23:41 +00:00
262 lines
No EOL
12 KiB
HTML
262 lines
No EOL
12 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||
|
||
<title>Draw a pipeline — ONNX Runtime 1.11.0 documentation</title>
|
||
<link rel="stylesheet" type="text/css" href="../static/pygments.css" />
|
||
<link rel="stylesheet" type="text/css" href="../static/alabaster.css" />
|
||
<link rel="stylesheet" type="text/css" href="../static/graphviz.css" />
|
||
<link rel="stylesheet" type="text/css" href="../static/sg_gallery.css" />
|
||
<link rel="stylesheet" type="text/css" href="../static/sg_gallery-binder.css" />
|
||
<link rel="stylesheet" type="text/css" href="../static/sg_gallery-dataframe.css" />
|
||
<link rel="stylesheet" type="text/css" href="../static/sg_gallery-rendered-html.css" />
|
||
<script data-url_root="../" id="documentation_options" src="../static/documentation_options.js"></script>
|
||
<script src="../static/jquery.js"></script>
|
||
<script src="../static/underscore.js"></script>
|
||
<script src="../static/doctools.js"></script>
|
||
<link rel="index" title="Index" href="../genindex.html" />
|
||
<link rel="search" title="Search" href="../search.html" />
|
||
<link rel="next" title="Load and predict with ONNX Runtime and a very simple model" href="plot_load_and_predict.html" />
|
||
<link rel="prev" title="Gallery of examples" href="index.html" />
|
||
|
||
<link rel="stylesheet" href="../static/custom.css" type="text/css" />
|
||
|
||
|
||
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
|
||
|
||
</head><body>
|
||
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
|
||
|
||
<div class="body" role="main">
|
||
|
||
<div class="sphx-glr-download-link-note admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>Click <a class="reference internal" href="#sphx-glr-download-auto-examples-plot-pipeline-py"><span class="std std-ref">here</span></a>
|
||
to download the full example code</p>
|
||
</div>
|
||
<section class="sphx-glr-example-title" id="draw-a-pipeline">
|
||
<span id="sphx-glr-auto-examples-plot-pipeline-py"></span><h1>Draw a pipeline<a class="headerlink" href="#draw-a-pipeline" title="Permalink to this headline">¶</a></h1>
|
||
<p>There is no other way to look into one model stored
|
||
in ONNX format than looking into its node with
|
||
<em>onnx</em>. This example demonstrates
|
||
how to draw a model and to retrieve it in <em>json</em>
|
||
format.</p>
|
||
<div class="contents local topic" id="contents">
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#retrieve-a-model-in-json-format" id="id1">Retrieve a model in JSON format</a></p></li>
|
||
<li><p><a class="reference internal" href="#draw-a-model-with-onnx" id="id2">Draw a model with ONNX</a></p></li>
|
||
</ul>
|
||
</div>
|
||
<section id="retrieve-a-model-in-json-format">
|
||
<h2><a class="toc-backref" href="#id1">Retrieve a model in JSON format</a><a class="headerlink" href="#retrieve-a-model-in-json-format" title="Permalink to this headline">¶</a></h2>
|
||
<p>That’s the most simple way.</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">onnxruntime.datasets</span> <span class="k">import</span> <span class="n">get_example</span>
|
||
<span class="n">example1</span> <span class="o">=</span> <span class="n">get_example</span><span class="p">(</span><span class="s2">"mul_1.onnx"</span><span class="p">)</span>
|
||
|
||
<span class="kn">import</span> <span class="nn">onnx</span>
|
||
<span class="n">model</span> <span class="o">=</span> <span class="n">onnx</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">example1</span><span class="p">)</span> <span class="c1"># model is a ModelProto protobuf message</span>
|
||
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p class="sphx-glr-script-out">Out:</p>
|
||
<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>ir_version: 3
|
||
producer_name: "chenta"
|
||
graph {
|
||
node {
|
||
input: "X"
|
||
input: "W"
|
||
output: "Y"
|
||
name: "mul_1"
|
||
op_type: "Mul"
|
||
}
|
||
name: "mul test"
|
||
initializer {
|
||
dims: 3
|
||
dims: 2
|
||
data_type: 1
|
||
float_data: 1.0
|
||
float_data: 2.0
|
||
float_data: 3.0
|
||
float_data: 4.0
|
||
float_data: 5.0
|
||
float_data: 6.0
|
||
name: "W"
|
||
}
|
||
input {
|
||
name: "X"
|
||
type {
|
||
tensor_type {
|
||
elem_type: 1
|
||
shape {
|
||
dim {
|
||
dim_value: 3
|
||
}
|
||
dim {
|
||
dim_value: 2
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
output {
|
||
name: "Y"
|
||
type {
|
||
tensor_type {
|
||
elem_type: 1
|
||
shape {
|
||
dim {
|
||
dim_value: 3
|
||
}
|
||
dim {
|
||
dim_value: 2
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
opset_import {
|
||
domain: ""
|
||
version: 7
|
||
}
|
||
</pre></div>
|
||
</div>
|
||
</section>
|
||
<section id="draw-a-model-with-onnx">
|
||
<h2><a class="toc-backref" href="#id2">Draw a model with ONNX</a><a class="headerlink" href="#draw-a-model-with-onnx" title="Permalink to this headline">¶</a></h2>
|
||
<p>We use <a class="reference external" href="https://github.com/onnx/onnx/blob/master/onnx/tools/net_drawer.py">net_drawer.py</a>
|
||
included in <em>onnx</em> package.
|
||
We use <em>onnx</em> to load the model
|
||
in a different way than before.</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">onnx</span> <span class="k">import</span> <span class="n">ModelProto</span>
|
||
<span class="n">model</span> <span class="o">=</span> <span class="n">ModelProto</span><span class="p">()</span>
|
||
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">example1</span><span class="p">,</span> <span class="s1">'rb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">fid</span><span class="p">:</span>
|
||
<span class="n">content</span> <span class="o">=</span> <span class="n">fid</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
|
||
<span class="n">model</span><span class="o">.</span><span class="n">ParseFromString</span><span class="p">(</span><span class="n">content</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>We convert it into a graph.</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">onnx.tools.net_drawer</span> <span class="k">import</span> <span class="n">GetPydotGraph</span><span class="p">,</span> <span class="n">GetOpNodeProducer</span>
|
||
<span class="n">pydot_graph</span> <span class="o">=</span> <span class="n">GetPydotGraph</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">graph</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">model</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">rankdir</span><span class="o">=</span><span class="s2">"LR"</span><span class="p">,</span>
|
||
<span class="n">node_producer</span><span class="o">=</span><span class="n">GetOpNodeProducer</span><span class="p">(</span><span class="s2">"docstring"</span><span class="p">))</span>
|
||
<span class="n">pydot_graph</span><span class="o">.</span><span class="n">write_dot</span><span class="p">(</span><span class="s2">"graph.dot"</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Then into an image</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span>
|
||
<span class="n">os</span><span class="o">.</span><span class="n">system</span><span class="p">(</span><span class="s1">'dot -O -Tpng graph.dot'</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p class="sphx-glr-script-out">Out:</p>
|
||
<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>0
|
||
</pre></div>
|
||
</div>
|
||
<p>Which we display…</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
|
||
<span class="n">image</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">imread</span><span class="p">(</span><span class="s2">"graph.dot.png"</span><span class="p">)</span>
|
||
<span class="n">plt</span><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><span class="n">image</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<img src="../images/sphx_glr_plot_pipeline_001.png" srcset="../images/sphx_glr_plot_pipeline_001.png" alt="plot pipeline" class = "sphx-glr-single-img"/><p class="sphx-glr-script-out">Out:</p>
|
||
<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span><matplotlib.image.AxesImage object at 0x7f8ddd338c10>
|
||
</pre></div>
|
||
</div>
|
||
<p class="sphx-glr-timing"><strong>Total running time of the script:</strong> ( 0 minutes 0.258 seconds)</p>
|
||
<div class="sphx-glr-footer class sphx-glr-footer-example docutils container" id="sphx-glr-download-auto-examples-plot-pipeline-py">
|
||
<div class="sphx-glr-download sphx-glr-download-python docutils container">
|
||
<p><a class="reference download internal" download="" href="../downloads/d436e9922b51a71358604ec00f09e7e4/plot_pipeline.py"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">plot_pipeline.py</span></code></a></p>
|
||
</div>
|
||
<div class="sphx-glr-download sphx-glr-download-jupyter docutils container">
|
||
<p><a class="reference download internal" download="" href="../downloads/2dbd202de70c8b6a394b8a1c7c1e12b8/plot_pipeline.ipynb"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Jupyter</span> <span class="pre">notebook:</span> <span class="pre">plot_pipeline.ipynb</span></code></a></p>
|
||
</div>
|
||
</div>
|
||
<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p>
|
||
</section>
|
||
</section>
|
||
|
||
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||
<div class="sphinxsidebarwrapper">
|
||
<p class="logo"><a href="../index.html">
|
||
<img class="logo" src="../static/ONNX_Runtime_icon.png" alt="Logo"/>
|
||
</a></p>
|
||
<h1 class="logo"><a href="../index.html">ONNX Runtime</a></h1>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../tutorial.html">Tutorial</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../api_summary.html">API</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="index.html">Gallery of examples</a></li>
|
||
</ul>
|
||
|
||
<div class="relations">
|
||
<h3>Related Topics</h3>
|
||
<ul>
|
||
<li><a href="../index.html">Documentation overview</a><ul>
|
||
<li><a href="index.html">Gallery of examples</a><ul>
|
||
<li>Previous: <a href="index.html" title="previous chapter">Gallery of examples</a></li>
|
||
<li>Next: <a href="plot_load_and_predict.html" title="next chapter">Load and predict with ONNX Runtime and a very simple model</a></li>
|
||
</ul></li>
|
||
</ul></li>
|
||
</ul>
|
||
</div>
|
||
<div id="searchbox" style="display: none" role="search">
|
||
<h3 id="searchlabel">Quick search</h3>
|
||
<div class="searchformwrapper">
|
||
<form class="search" action="../search.html" method="get">
|
||
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
|
||
<input type="submit" value="Go" />
|
||
</form>
|
||
</div>
|
||
</div>
|
||
<script>$('#searchbox').show(0);</script>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="footer">
|
||
©2018-2021, Microsoft.
|
||
|
||
|
|
||
Powered by <a href="http://sphinx-doc.org/">Sphinx 4.4.0</a>
|
||
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
|
||
|
||
|
|
||
<a href="../sources/auto_examples/plot_pipeline.rst.txt"
|
||
rel="nofollow">Page source</a>
|
||
</div>
|
||
|
||
|
||
|
||
|
||
</body>
|
||
</html> |