onnxruntime/docs/api/python/downloads/d436e9922b51a71358604ec00f09e7e4/plot_pipeline.py
Cassie a0f3e30de6
Docs update: updated nav, get started sections, home page, apis (#9060)
* initial setup and rename "how to" to "setup"

* move API to main nav

* move api to main nav

* add get starated, rework nav order

* rename to install move mds out of install section

* update api nav and home page

* add install docs and python qs updates

* python get started work

* remove c and obj c for now

* move java, python, and obj-c docs under api folder

* move java api html to iframe (ugh)

* remove api docs w/o details, move api text getstar

* remove api docs wo detail updates get started

* remvoe iframes

* move eco system to main nav

* fix api buttons

* added more examples moved intro to ORT

* fix links

* fix get started titles

* fix get started titles

* fix more links

* fix more links

* more link fixes

* fix nav remove inferencing and training subnav

* fix top nav remove inference and training nav

* fix title

* fix tutorials nav hierarchy

* fix python api button

* add tenorflow keras example

* fix quickstart toc

* add imports fix spacing

* fix links

* update nav and python get started page

* move ort training example, add coming soon for iot

* update C# get started

* fix spacing on quantization

* Add some js get started content

* fix formatting

* fix typo

* removed onnx-pytorch and onnx-tf

* updated pip install torch and added links iot page

* added pytorch tutorial heirarchy

* updated web to docs soon added release blog link

* add web link
2021-09-15 16:23:42 -05:00

69 lines
1.6 KiB
Python

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
"""
Draw a pipeline
===============
There is no other way to look into one model stored
in ONNX format than looking into its node with
*onnx*. This example demonstrates
how to draw a model and to retrieve it in *json*
format.
.. contents::
:local:
Retrieve a model in JSON format
+++++++++++++++++++++++++++++++
That's the most simple way.
"""
from onnxruntime.datasets import get_example
example1 = get_example("mul_1.onnx")
import onnx
model = onnx.load(example1) # model is a ModelProto protobuf message
print(model)
#################################
# Draw a model with ONNX
# ++++++++++++++++++++++
# We use `net_drawer.py <https://github.com/onnx/onnx/blob/master/onnx/tools/net_drawer.py>`_
# included in *onnx* package.
# We use *onnx* to load the model
# in a different way than before.
from onnx import ModelProto
model = ModelProto()
with open(example1, 'rb') as fid:
content = fid.read()
model.ParseFromString(content)
###################################
# We convert it into a graph.
from onnx.tools.net_drawer import GetPydotGraph, GetOpNodeProducer
pydot_graph = GetPydotGraph(model.graph, name=model.graph.name, rankdir="LR",
node_producer=GetOpNodeProducer("docstring"))
pydot_graph.write_dot("graph.dot")
#######################################
# Then into an image
import os
os.system('dot -O -Tpng graph.dot')
################################
# Which we display...
import matplotlib.pyplot as plt
image = plt.imread("graph.dot.png")
plt.imshow(image)