.. 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-19 .. code-block:: default import onnxruntime as rt import numpy from onnxruntime.datasets import get_example .. GENERATED FROM PYTHON SOURCE LINES 20-22 Let's load a very simple model. The model is available on github `onnx...test_sigmoid `_. .. GENERATED FROM PYTHON SOURCE LINES 22-26 .. code-block:: default example1 = get_example("sigmoid.onnx") sess = rt.InferenceSession(example1, providers=rt.get_available_providers()) .. GENERATED FROM PYTHON SOURCE LINES 27-28 Let's see the input name and shape. .. GENERATED FROM PYTHON SOURCE LINES 28-36 .. 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 Out: .. code-block:: none input name x input shape [3, 4, 5] input type tensor(float) .. GENERATED FROM PYTHON SOURCE LINES 37-38 Let's see the output name and shape. .. GENERATED FROM PYTHON SOURCE LINES 38-46 .. 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 Out: .. code-block:: none output name y output shape [3, 4, 5] output type tensor(float) .. GENERATED FROM PYTHON SOURCE LINES 47-48 Let's compute its outputs (or predictions if it is a machine learned model). .. GENERATED FROM PYTHON SOURCE LINES 48-54 .. 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 Out: .. code-block:: none [array([[[0.6423601 , 0.65232253, 0.6620137 , 0.708999 , 0.65169865], [0.548968 , 0.59544575, 0.7161434 , 0.525905 , 0.7210646 ], [0.5178277 , 0.5842683 , 0.5627599 , 0.6324704 , 0.5833795 ], [0.69634616, 0.60848683, 0.6746977 , 0.50677085, 0.5549751 ]], [[0.5097179 , 0.59407187, 0.56360227, 0.7223234 , 0.5392329 ], [0.5398089 , 0.5622808 , 0.5369593 , 0.5819309 , 0.5735331 ], [0.5688669 , 0.71247685, 0.63964766, 0.63349843, 0.63380575], [0.64378905, 0.60552883, 0.5184905 , 0.6312441 , 0.5047166 ]], [[0.63900065, 0.6108959 , 0.5249817 , 0.5055595 , 0.55390376], [0.62443805, 0.550723 , 0.5320551 , 0.5522731 , 0.68858314], [0.69650024, 0.54673976, 0.56964463, 0.58536506, 0.5743989 ], [0.6382853 , 0.5826889 , 0.53635114, 0.52279866, 0.7300966 ]]], 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 :class: 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 `_