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.8.1858.tar.gz (825.2 kB view details)

Uploaded Source

Built Distributions

mlprodict-0.8.1858-cp39-cp39-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.9 Windows x86-64

mlprodict-0.8.1858-cp39-cp39-manylinux_2_24_x86_64.whl (26.9 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.24+ x86-64

mlprodict-0.8.1858-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (39.2 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

mlprodict-0.8.1858-cp38-cp38-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.8 Windows x86-64

mlprodict-0.8.1858-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (39.2 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

mlprodict-0.8.1858-cp38-cp38-macosx_10_13_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.8 macOS 10.13+ x86-64

mlprodict-0.8.1858-cp37-cp37m-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.7m Windows x86-64

mlprodict-0.8.1858-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (40.3 MB view details)

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

File details

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

File metadata

  • Download URL: mlprodict-0.8.1858.tar.gz
  • Upload date:
  • Size: 825.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.11.3 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

File hashes

Hashes for mlprodict-0.8.1858.tar.gz
Algorithm Hash digest
SHA256 5633bfafac7560238d76a4f694911c1c0db9df59cf6c19a9d4d99363f1bdaa92
MD5 7c0e5da7b27795d24f6b73daaf64917f
BLAKE2b-256 42dac1e2b40d9d93b17dfeca80e2ba809325b636918c09737084ffd4b08e8e07

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mlprodict-0.8.1858-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.11.3 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

File hashes

Hashes for mlprodict-0.8.1858-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 9d6fdf55b0081a59740398ef0add28a64379a1a4c936c7deee1ba67793cb317c
MD5 ebfc7deba9fe99d070e63f6cea6009b4
BLAKE2b-256 74268b5dda74cf9bc959a286bc1694d0f2b53a7e0040987baba25fdb48a08f32

See more details on using hashes here.

File details

Details for the file mlprodict-0.8.1858-cp39-cp39-manylinux_2_24_x86_64.whl.

File metadata

  • Download URL: mlprodict-0.8.1858-cp39-cp39-manylinux_2_24_x86_64.whl
  • Upload date:
  • Size: 26.9 MB
  • Tags: CPython 3.9, manylinux: glibc 2.24+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.11.3 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

File hashes

Hashes for mlprodict-0.8.1858-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 990dc065140196fdb7b99074653d858a0746a3dfdfea7fc93b8d347fc7dddc92
MD5 86ebf2ffb1add81aa3d6254c3f52fe6b
BLAKE2b-256 ecc884d6945ad0f9ddc09ad215b596dfd88119e0bd9025d4a20dafe3e7800a38

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mlprodict-0.8.1858-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ecec56afdaad835856bed49d9c059878d1a4ce4ef468d1c93262c55799b012d2
MD5 d14ecb8077d789b239fc984161b12d21
BLAKE2b-256 dee8ebd3b967c253dd6de13bf389698c6d25ec1f771ab3e2c601d23bc5b18878

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mlprodict-0.8.1858-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.11.3 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

File hashes

Hashes for mlprodict-0.8.1858-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 414b29ef25ff0753d142dc09841cd25c3403bf8800d34e7c276deb38cbea2473
MD5 56359e759ecd02b6c22961f2f72b6ec8
BLAKE2b-256 d59ed47d1d4ea521b2d70b024026b09b54f1782d6a66c1262eb06c8d7ec11d79

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mlprodict-0.8.1858-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c7be070cabac6b835c8330ea491509c7a8b212ca3d1e1fea71cd917764d5df13
MD5 bee223fc7bec0d85d2f095e143682b56
BLAKE2b-256 54e3eb3cde1df7fb44a7bd656023da2aab2899919d277dd46a59ef1c82423d35

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mlprodict-0.8.1858-cp38-cp38-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: CPython 3.8, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.11.3 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

File hashes

Hashes for mlprodict-0.8.1858-cp38-cp38-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 f801ccb70803e9dbdff4d2ac3ba78357e83f82d9557b9a580d19b65ce16f9a69
MD5 6992cb5e1d148a4e1fb73c9b2754f9c1
BLAKE2b-256 8ebd3f3a33a012e0231680eedc48a9848597be9b98a5bc218c148ee28cb86799

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mlprodict-0.8.1858-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.11.3 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

File hashes

Hashes for mlprodict-0.8.1858-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 699b4c23976e306152da75c3469617101ad63958e135c32c5f52f23f1adb9d13
MD5 df7e8c8390f6f66a780fc5def9d93d49
BLAKE2b-256 2a7cacc94c689780029df261565d8a3b2c7b84ec10200a73958e0f4bb7491983

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mlprodict-0.8.1858-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d2c1a0bf81dc59c0b021719678ff9b5bfdf7dd07f29266d07d0d0a45100037a5
MD5 3bce6ddfe1704ac33e380b24e93994a9
BLAKE2b-256 cfbbb248fc1794747848964a0a42b73b684d8da47a015c2a291ae1a2e2ba115b

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