.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_load_and_predict.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_load_and_predict.py: .. _l-example-simple-usage: Load and predict with ONNX Runtime and a very simple model ========================================================== This example demonstrates how to load a model and compute the output for an input vector. It also shows how to retrieve the definition of its inputs and outputs. .. GENERATED FROM PYTHON SOURCE LINES 14-20 .. code-block:: default import numpy import onnxruntime as rt from onnxruntime.datasets import get_example .. GENERATED FROM PYTHON SOURCE LINES 21-23 Let's load a very simple model. The model is available on github `onnx...test_sigmoid `_. .. GENERATED FROM PYTHON SOURCE LINES 23-27 .. code-block:: default example1 = get_example("sigmoid.onnx") sess = rt.InferenceSession(example1, providers=rt.get_available_providers()) .. GENERATED FROM PYTHON SOURCE LINES 28-29 Let's see the input name and shape. .. GENERATED FROM PYTHON SOURCE LINES 29-37 .. code-block:: default input_name = sess.get_inputs()[0].name print("input name", input_name) input_shape = sess.get_inputs()[0].shape print("input shape", input_shape) input_type = sess.get_inputs()[0].type print("input type", input_type) .. rst-class:: sphx-glr-script-out .. code-block:: none input name x input shape [3, 4, 5] input type tensor(float) .. GENERATED FROM PYTHON SOURCE LINES 38-39 Let's see the output name and shape. .. GENERATED FROM PYTHON SOURCE LINES 39-47 .. code-block:: default output_name = sess.get_outputs()[0].name print("output name", output_name) output_shape = sess.get_outputs()[0].shape print("output shape", output_shape) output_type = sess.get_outputs()[0].type print("output type", output_type) .. rst-class:: sphx-glr-script-out .. code-block:: none output name y output shape [3, 4, 5] output type tensor(float) .. GENERATED FROM PYTHON SOURCE LINES 48-49 Let's compute its outputs (or predictions if it is a machine learned model). .. GENERATED FROM PYTHON SOURCE LINES 49-56 .. code-block:: default import numpy.random x = numpy.random.random((3, 4, 5)) x = x.astype(numpy.float32) res = sess.run([output_name], {input_name: x}) print(res) .. rst-class:: sphx-glr-script-out .. code-block:: none [array([[[0.59265393, 0.7246058 , 0.62519205, 0.7004995 , 0.6416377 ], [0.5454135 , 0.65959364, 0.6020219 , 0.56796944, 0.63770235], [0.6438767 , 0.73105097, 0.6988132 , 0.67353356, 0.67766804], [0.5540559 , 0.67908806, 0.64719033, 0.70831954, 0.71614885]], [[0.6420407 , 0.6707052 , 0.59057796, 0.63475496, 0.50294226], [0.68205726, 0.6349313 , 0.6219983 , 0.6343657 , 0.6805997 ], [0.685706 , 0.60009193, 0.7035725 , 0.63636667, 0.667937 ], [0.57011735, 0.6401627 , 0.7033285 , 0.65497917, 0.69604504]], [[0.67350495, 0.5930217 , 0.5114459 , 0.70683706, 0.67305243], [0.6557756 , 0.6705569 , 0.55717707, 0.62621975, 0.55469143], [0.5987439 , 0.6382455 , 0.5550844 , 0.5442223 , 0.56532246], [0.5364911 , 0.6803087 , 0.5160084 , 0.5848341 , 0.5916815 ]]], dtype=float32)] .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.008 seconds) .. _sphx_glr_download_auto_examples_plot_load_and_predict.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_load_and_predict.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_load_and_predict.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_