.. 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.7074605 , 0.66807246, 0.5468252 , 0.6794102 , 0.72581375], [0.7061233 , 0.7108102 , 0.7131539 , 0.5087233 , 0.7157812 ], [0.5101798 , 0.6822957 , 0.71132684, 0.63517916, 0.5935693 ], [0.6674769 , 0.71915364, 0.6055379 , 0.6265797 , 0.6334329 ]], [[0.7060813 , 0.65122193, 0.5852989 , 0.7020965 , 0.5418902 ], [0.70865536, 0.7239054 , 0.53950447, 0.6397851 , 0.61991036], [0.5108298 , 0.70998025, 0.5768114 , 0.70231366, 0.7083629 ], [0.5532729 , 0.6634668 , 0.68702626, 0.53754365, 0.63848865]], [[0.5546355 , 0.5326628 , 0.6045945 , 0.72216797, 0.5367474 ], [0.54598904, 0.683926 , 0.7086522 , 0.5805207 , 0.6906233 ], [0.71620524, 0.6052958 , 0.7310034 , 0.6245417 , 0.6648243 ], [0.6229709 , 0.5226055 , 0.67183244, 0.6684347 , 0.57293963]]], dtype=float32)] .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.007 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 `_