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

171 lines
3.6 KiB
ReStructuredText

.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/plot_backend.py"
.. LINE NUMBERS ARE GIVEN BELOW.
.. only:: html
.. note::
:class: sphx-glr-download-link-note
Click :ref:`here <sphx_glr_download_auto_examples_plot_backend.py>`
to download the full example code
.. rst-class:: sphx-glr-example-title
.. _sphx_glr_auto_examples_plot_backend.py:
.. _l-example-backend-api:
ONNX Runtime Backend for ONNX
=============================
*ONNX Runtime* extends the
`onnx backend API <https://github.com/onnx/onnx/blob/master/docs/ImplementingAnOnnxBackend.md>`_
to run predictions using this runtime.
Let's use the API to compute the prediction
of a simple logistic regression model.
.. GENERATED FROM PYTHON SOURCE LINES 17-35
.. code-block:: default
import numpy as np
from onnxruntime import datasets
from onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument
import onnxruntime.backend as backend
from onnx import load
name = datasets.get_example("logreg_iris.onnx")
model = load(name)
rep = backend.prepare(model, 'CPU')
x = np.array([[-1.0, -2.0]], dtype=np.float32)
try:
label, proba = rep.run(x)
print("label={}".format(label))
print("probabilities={}".format(proba))
except (RuntimeError, InvalidArgument) as e:
print(e)
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
[ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Got invalid dimensions for input: float_input for the following indices
index: 0 Got: 1 Expected: 3
Please fix either the inputs or the model.
.. GENERATED FROM PYTHON SOURCE LINES 36-38
The device depends on how the package was compiled,
GPU or CPU.
.. GENERATED FROM PYTHON SOURCE LINES 38-41
.. code-block:: default
from onnxruntime import get_device
print(get_device())
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
CPU
.. GENERATED FROM PYTHON SOURCE LINES 42-44
The backend can also directly load the model
without using *onnx*.
.. GENERATED FROM PYTHON SOURCE LINES 44-54
.. code-block:: default
rep = backend.prepare(name, 'CPU')
x = np.array([[-1.0, -2.0]], dtype=np.float32)
try:
label, proba = rep.run(x)
print("label={}".format(label))
print("probabilities={}".format(proba))
except (RuntimeError, InvalidArgument) as e:
print(e)
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
[ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Got invalid dimensions for input: float_input for the following indices
index: 0 Got: 1 Expected: 3
Please fix either the inputs or the model.
.. GENERATED FROM PYTHON SOURCE LINES 55-58
The backend API is implemented by other frameworks
and makes it easier to switch between multiple runtimes
with the same API.
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 0 minutes 0.019 seconds)
.. _sphx_glr_download_auto_examples_plot_backend.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_backend.py <plot_backend.py>`
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: plot_backend.ipynb <plot_backend.ipynb>`
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_