.. 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.72821426, 0.6339202 , 0.7272735 , 0.6409311 , 0.61518466], [0.7185246 , 0.640914 , 0.60131776, 0.6857518 , 0.70039463], [0.7135308 , 0.65056884, 0.58760184, 0.7135416 , 0.63284004], [0.7188247 , 0.5470599 , 0.58532 , 0.67812634, 0.6893187 ]], [[0.6211655 , 0.554035 , 0.55418974, 0.56652635, 0.62399405], [0.55780345, 0.6938668 , 0.5910147 , 0.59314 , 0.54391265], [0.7126377 , 0.65041703, 0.62936115, 0.69839984, 0.5651956 ], [0.6023196 , 0.6012137 , 0.7164181 , 0.59447944, 0.7121656 ]], [[0.6137416 , 0.65805656, 0.6757898 , 0.7231871 , 0.6186665 ], [0.662174 , 0.61860013, 0.6509645 , 0.57368857, 0.689906 ], [0.7140595 , 0.7226651 , 0.6117408 , 0.5281206 , 0.69103116], [0.7082236 , 0.7197187 , 0.6111821 , 0.6187154 , 0.53502613]]], dtype=float32)] .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.013 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 `_