Skip to main content

Python Runtime for ONNX models, other helpers to convert machine learned models in C++.

Project description

https://github.com/sdpython/mlprodict/blob/master/_doc/sphinxdoc/source/phdoc_static/project_ico.png?raw=true

mlprodict

Build status Build Status Windows https://circleci.com/gh/sdpython/mlprodict/tree/master.svg?style=svg https://dev.azure.com/xavierdupre3/mlprodict/_apis/build/status/sdpython.mlprodict https://badge.fury.io/py/mlprodict.svg MIT License https://codecov.io/github/sdpython/mlprodict/coverage.svg?branch=master GitHub Issues Notebook Coverage Downloads Forks Stars https://mybinder.org/badge_logo.svg size

mlprodict was initially started to help implementing converters to ONNX. The main features is a python runtime for ONNX (class OnnxInference), visualization tools (see Visualization), and a numpy API for ONNX). The package also provides tools to compare predictions, to benchmark models converted with sklearn-onnx.

import numpy
from sklearn.linear_model import LinearRegression
from sklearn.datasets import load_iris
from mlprodict.onnxrt import OnnxInference
from mlprodict.onnxrt.validate.validate_difference import measure_relative_difference
from mlprodict import __max_supported_opset__, get_ir_version

iris = load_iris()
X = iris.data[:, :2]
y = iris.target
lr = LinearRegression()
lr.fit(X, y)

# Predictions with scikit-learn.
expected = lr.predict(X[:5])
print(expected)

# Conversion into ONNX.
from mlprodict.onnx_conv import to_onnx
model_onnx = to_onnx(lr, X.astype(numpy.float32),
                     black_op={'LinearRegressor'},
                     target_opset=__max_supported_opset__)
print("ONNX:", str(model_onnx)[:200] + "\n...")

# Predictions with onnxruntime
model_onnx.ir_version = get_ir_version(__max_supported_opset__)
oinf = OnnxInference(model_onnx, runtime='onnxruntime1')
ypred = oinf.run({'X': X[:5].astype(numpy.float32)})
print("ONNX output:", ypred)

# Measuring the maximum difference.
print("max abs diff:", measure_relative_difference(expected, ypred['variable']))

# And the python runtime
oinf = OnnxInference(model_onnx, runtime='python')
ypred = oinf.run({'X': X[:5].astype(numpy.float32)},
                 verbose=1, fLOG=print)
print("ONNX output:", ypred)

Installation

Installation from pip should work unless you need the latest development features.

pip install mlprodict

The package includes a runtime for ONNX. That’s why there is a limited number of dependencies. However, some features relies on sklearn-onnx, onnxruntime, scikit-learn. They can be installed with the following instructions:

pip install mlprodict[all]

The code is available at GitHub/mlprodict and has online documentation.

Project details


Download files

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

Source Distribution

mlprodict-0.9.1883.tar.gz (814.9 kB view details)

Uploaded Source

Built Distributions

mlprodict-0.9.1883-cp310-cp310-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.10 Windows x86-64

mlprodict-0.9.1883-cp310-cp310-manylinux_2_24_x86_64.whl (27.4 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.24+ x86-64

mlprodict-0.9.1883-cp310-cp310-macosx_10_13_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.10 macOS 10.13+ x86-64

mlprodict-0.9.1883-cp39-cp39-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.9 Windows x86-64

mlprodict-0.9.1883-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (40.0 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

mlprodict-0.9.1883-cp39-cp39-macosx_10_13_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.9 macOS 10.13+ x86-64

mlprodict-0.9.1883-cp38-cp38-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.8 Windows x86-64

mlprodict-0.9.1883-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (40.1 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

mlprodict-0.9.1883-cp38-cp38-macosx_10_13_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.8 macOS 10.13+ x86-64

mlprodict-0.9.1883-cp37-cp37m-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.7m Windows x86-64

mlprodict-0.9.1883-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (41.3 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

File details

Details for the file mlprodict-0.9.1883.tar.gz.

File metadata

  • Download URL: mlprodict-0.9.1883.tar.gz
  • Upload date:
  • Size: 814.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for mlprodict-0.9.1883.tar.gz
Algorithm Hash digest
SHA256 4be87c687d3d09b6a7f55eeb90d0795fc84a969c271ad4053ef53015d06dd398
MD5 b2efe11fc250f3de35e182cb6e22a3fb
BLAKE2b-256 5bd27f643bb8432e9c7961becb4f44e0e0f8455dffa92344c6e4ca7b4d18d232

See more details on using hashes here.

File details

Details for the file mlprodict-0.9.1883-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for mlprodict-0.9.1883-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a39323222595cb9f7ce16d167febd670e41be5c26ac334e475978266c3b494e6
MD5 1844ae3e8d826046d6785c24d8cc34bf
BLAKE2b-256 8c05ca4996e5cd1aa11af640f2d29b3ae40d1a0deaa5a42bde4329daeaa97940

See more details on using hashes here.

File details

Details for the file mlprodict-0.9.1883-cp310-cp310-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for mlprodict-0.9.1883-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 9460033d0331aaefe79d19e45aa5ef04663ad2d89a3edcf674b64c8087c07101
MD5 de7c6bcc2371f8e744c90cb2e089bba0
BLAKE2b-256 6fcf97957338b23f937d337e1b8ec9047aa19987257a1c9889ebe640e2fad5a4

See more details on using hashes here.

File details

Details for the file mlprodict-0.9.1883-cp310-cp310-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for mlprodict-0.9.1883-cp310-cp310-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 3ca38c90d5f0ddf7715ec171074a5ed13265d1a70df69f718996b4824243b6af
MD5 2561723606cd7f9e9ee99ca47f70360f
BLAKE2b-256 54f91b152e47b910991107edbfdf7d14270d518883f18f9748d7cd1251fa2e10

See more details on using hashes here.

File details

Details for the file mlprodict-0.9.1883-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for mlprodict-0.9.1883-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 15465beed3fb1504a03d15986cff2c962d30fede0c6a04b248d24d4c32ac728a
MD5 7117d88104d192ac3758faf71ee5e47e
BLAKE2b-256 90076ce9f5f6579c56cfa827ff155d8600d62a9d7d93367555592c799d234a45

See more details on using hashes here.

File details

Details for the file mlprodict-0.9.1883-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mlprodict-0.9.1883-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6a97172bddfb16467992d17bc673f0ed8e11b626e5ed711fdfb4a99c5e07196c
MD5 78b76a8ff35823004b892ebeb4452732
BLAKE2b-256 76c4231e76b59c9d0252e990afc710e8c919f7ec3bce38677b3bb72c14b31853

See more details on using hashes here.

File details

Details for the file mlprodict-0.9.1883-cp39-cp39-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for mlprodict-0.9.1883-cp39-cp39-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 6a2843aabf25433967fa80bae244dc6eff3a42a7e947d03c47fdb93ac215fef8
MD5 802bc7f502bd776cf35de05560b23838
BLAKE2b-256 05ac6d9ffe86930951d3418604fd97b05dc4afa02a07e1a0ee387dca8b3258ae

See more details on using hashes here.

File details

Details for the file mlprodict-0.9.1883-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for mlprodict-0.9.1883-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 fda5699f053b6014470b4bc645949a4fa6bb8246bbfdb090a50390efbcc421f0
MD5 3f442562588b96fedcbd26640b83447b
BLAKE2b-256 ccbcb2ca328e32f8098cddb69c8c99033ceff538b695ca5fed4914182c3138d4

See more details on using hashes here.

File details

Details for the file mlprodict-0.9.1883-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mlprodict-0.9.1883-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2d4ab90f145174ac71a556466ae374c0e51145957f71ede2fa78119696934774
MD5 1db1ea036054dfaf92d3542b5b7808b5
BLAKE2b-256 1e3c53a12d2942e6821231503d571cf3b67d72d239d858b0b987af17a0d716ae

See more details on using hashes here.

File details

Details for the file mlprodict-0.9.1883-cp38-cp38-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for mlprodict-0.9.1883-cp38-cp38-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 3d0f71d940a622960e528e4be6d6bd4eea901d0bfc0e5a81c90de5310e2e64a3
MD5 595dc7d058377dbe6109ed6a34d7cba4
BLAKE2b-256 7898f012e83f9f028f2f06bcb10724bc6415049e9660cf6c62da9fa345ef5b19

See more details on using hashes here.

File details

Details for the file mlprodict-0.9.1883-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for mlprodict-0.9.1883-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 a6e4945379e5378532c35d9054538655407f081838b2c11158f73bcc5f10d65d
MD5 4b55af772ae08d9c8674908258176144
BLAKE2b-256 97a6e83adbcd805fe583dfcdf4557f5b6a3ca3b3459fe22293aad21b3e6ebc2c

See more details on using hashes here.

File details

Details for the file mlprodict-0.9.1883-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mlprodict-0.9.1883-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 215c9a413fa9b24e66b6274daa4395f5d2713a7f7b718641e13abe908b42101c
MD5 a1750a30f35fb9dbca0689c2b88a8a85
BLAKE2b-256 9b5db36f8b0543089319fd82a0b4ff91e3206862b25c9b7dfcb57130f34030b8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page