Skip to main content

Convert Progressive Learning models to ONNX

Project description

Introduction

proglearn-onnx converts ProgLearn models to ONNX. Once in the ONNX format, you can use tools like ONNX Runtime for high performance scoring. All converters are tested with onnxruntime.

Supported Converters

This version implements ProgLearn estimators that adhere to the sklearn-onnx API on registering custom converters

Name Package Supported
ClassificationProgressiveLearner progressive_learner Yes
LifelongClassificationForest forest Yes
LifelongClassificationNetwork network No

Installation

You can install from PyPi:

pip install prog2onnx

Note: There is a known backtracking issue in pip's dependency resolver that may significantly affect the time required to fetch the correct versions of the dependencies. A quick and easy fix is to add --use-deprecated legacy-resolver at the end of pip install .

Getting started

# Train a model using 3 tasks.
import numpy as np
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from proglearn.forest import LifelongClassificationForest

iris = load_iris()
X, y = iris.data, iris.target
X = X.astype(np.float32)
X_train, X_test, y_train, y_test = train_test_split(X, y)

clr = LifelongClassificationForest(default_n_estimators=10)

for _ in range(3):
	clr.add_task(X_train, y_train)

# Convert into ONNX format.
from prog2onnx import Prog2ONNX

p2o = Prog2ONNX(clr)

# Convert for task_ID = 0
onx = p2o.to_onnx(0)

# Validate ONNX model (Optional) 
p2o.validate()

# Save ONNX model to file (Optional) 
p2o.save("forest_iris_0.onnx")

# Compute the prediction with onnxruntime.
import onnxruntime as rt

sess = rt.InferenceSession(onx.SerializeToString(), providers=["CPUExecutionProvider"])
input_name = sess.get_inputs()[0].name
pred_onx = sess.run(None, {input_name: X_test.astype(np.float32)})[0]

Testing

Several scenarios are assessed in the form of separate tests using the Python's built in unittest testing framework.

python -m unittest -v tests/test_proglearn.py

Contribute

We are open to contributions in the form of feedback, ideas, or code.

License

Apache License v2.0

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

prog2onnx-0.0.1-0beta-py2.py3-none-any.whl (14.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file prog2onnx-0.0.1-0beta-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for prog2onnx-0.0.1-0beta-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a964cad7791cc65991f374baa814a74e2e5e7f492476821d0340799383b31490
MD5 2285df979e62dbdbe69be57f873221b8
BLAKE2b-256 ffd7134c7a32dc09ecca16a9ba506dc085eb51cf6d9b5b2ecb6e75f043d52bc8

See more details on using hashes here.

Supported by

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