.. 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.72465897, 0.72574586, 0.6371799 , 0.71288747, 0.6594067 ], [0.6177746 , 0.587299 , 0.5193266 , 0.6938682 , 0.64304864], [0.52724993, 0.6042261 , 0.6895429 , 0.6509503 , 0.6616442 ], [0.6763506 , 0.6537579 , 0.6264375 , 0.59437954, 0.5884929 ]], [[0.6776498 , 0.5767992 , 0.6779048 , 0.67587113, 0.61081856], [0.7236815 , 0.5775631 , 0.61381036, 0.6063235 , 0.62550837], [0.50100976, 0.62944853, 0.70942533, 0.6089567 , 0.63848245], [0.5719551 , 0.68211 , 0.511835 , 0.7158986 , 0.53346515]], [[0.6256963 , 0.5512383 , 0.5719546 , 0.6073346 , 0.64393806], [0.6807264 , 0.6192803 , 0.5377599 , 0.5919384 , 0.7111624 ], [0.7152287 , 0.6213895 , 0.7274681 , 0.609508 , 0.59370804], [0.6366582 , 0.5454885 , 0.72254837, 0.55745107, 0.5137241 ]]], dtype=float32)] .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.009 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 `_