onnxruntime/docs/api/python/sources/auto_examples/plot_profiling.rst.txt
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

208 lines
3.9 KiB
ReStructuredText

.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/plot_profiling.py"
.. LINE NUMBERS ARE GIVEN BELOW.
.. only:: html
.. note::
:class: sphx-glr-download-link-note
Click :ref:`here <sphx_glr_download_auto_examples_plot_profiling.py>`
to download the full example code
.. rst-class:: sphx-glr-example-title
.. _sphx_glr_auto_examples_plot_profiling.py:
.. _l-example-profiling:
Profile the execution of a simple model
=======================================
*ONNX Runtime* can profile the execution of the model.
This example shows how to interpret the results.
.. GENERATED FROM PYTHON SOURCE LINES 14-32
.. code-block:: default
import onnx
import onnxruntime as rt
import numpy
from onnxruntime.datasets import get_example
def change_ir_version(filename, ir_version=6):
"onnxruntime==1.2.0 does not support opset <= 7 and ir_version > 6"
with open(filename, "rb") as f:
model = onnx.load(f)
model.ir_version = 6
if model.opset_import[0].version <= 7:
model.opset_import[0].version = 11
return model
.. GENERATED FROM PYTHON SOURCE LINES 33-34
Let's load a very simple model and compute some prediction.
.. GENERATED FROM PYTHON SOURCE LINES 34-45
.. code-block:: default
example1 = get_example("mul_1.onnx")
onnx_model = change_ir_version(example1)
onnx_model_str = onnx_model.SerializeToString()
sess = rt.InferenceSession(onnx_model_str)
input_name = sess.get_inputs()[0].name
x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32)
res = sess.run(None, {input_name: x})
print(res)
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
[array([[ 1., 4.],
[ 9., 16.],
[25., 36.]], dtype=float32)]
.. GENERATED FROM PYTHON SOURCE LINES 46-48
We need to enable to profiling
before running the predictions.
.. GENERATED FROM PYTHON SOURCE LINES 48-60
.. code-block:: default
options = rt.SessionOptions()
options.enable_profiling = True
sess_profile = rt.InferenceSession(onnx_model_str, options)
input_name = sess.get_inputs()[0].name
x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32)
sess.run(None, {input_name: x})
prof_file = sess_profile.end_profiling()
print(prof_file)
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
onnxruntime_profile__2021-03-04_18-40-00.json
.. GENERATED FROM PYTHON SOURCE LINES 61-63
The results are stored un a file in JSON format.
Let's see what it contains.
.. GENERATED FROM PYTHON SOURCE LINES 63-71
.. code-block:: default
import json
with open(prof_file, "r") as f:
sess_time = json.load(f)
import pprint
pprint.pprint(sess_time)
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
[{'args': {},
'cat': 'Session',
'dur': 101,
'name': 'model_loading_array',
'ph': 'X',
'pid': 77,
'tid': 77,
'ts': 3},
{'args': {},
'cat': 'Session',
'dur': 227,
'name': 'session_initialization',
'ph': 'X',
'pid': 77,
'tid': 77,
'ts': 134}]
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 0 minutes 0.010 seconds)
.. _sphx_glr_download_auto_examples_plot_profiling.py:
.. only :: html
.. container:: sphx-glr-footer
:class: sphx-glr-footer-example
.. container:: sphx-glr-download sphx-glr-download-python
:download:`Download Python source code: plot_profiling.py <plot_profiling.py>`
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: plot_profiling.ipynb <plot_profiling.ipynb>`
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_