Skip to main content

ONNX Runtime Runtime Python bindings

Project description

ONNX Runtime (Preview) enables high-performance evaluation of trained machine learning (ML) models while keeping resource usage low. Building on Microsoft’s dedication to the Open Neural Network Exchange (ONNX) community, it supports traditional ML models as well as Deep Learning algorithms in the ONNX-ML format. Documentation is available at Python Bindings for ONNX Runtime.


The following example demonstrates an end-to-end example in a very common scenario. A model is trained with scikit-learn but it has to run very fast in a optimized environment. The model is then converted into ONNX format and ONNX Runtime replaces scikit-learn to compute the predictions.

# Train a model.
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForest
iris = load_iris()
X, y =,
X_train, X_test, y_train, y_test = train_test_split(X, y)
clr = RandomForest(), y_train)

# Convert into ONNX format with onnxmltools
from onnxmltools import convert_sklearn
from onnxmltools.utils import save_model
from onnxmltools.convert.common.data_types import FloatTensorType
initial_type = [('float_input', FloatTensorType([1, 4]))]
onx = convert_sklearn(clr, initial_types=initial_type)
save_model(onx, "rf_iris.onnx")

# Compute the prediction with ONNX Runtime
import onnxruntime as rt
import numpy
sess = rt.InferenceSession("rf_iris.onnx")
input_name = sess.get_inputs()[0].name
label_name = sess.get_outputs()[0].name
pred_onx =[label_name], {input_name: X_test.astype(numpy.float32)})[0]

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for onnxruntime, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size onnxruntime-0.1.2-cp35-cp35m-manylinux1_x86_64.whl (4.6 MB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size onnxruntime-0.1.2-cp36-cp36m-manylinux1_x86_64.whl (4.6 MB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size onnxruntime-0.1.2-cp37-cp37m-manylinux1_x86_64.whl (4.6 MB) File type Wheel Python version cp37 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page