Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/onnx/sklearn-onnx
Convert scikit-learn models and pipelines to ONNX
https://github.com/onnx/sklearn-onnx
onnx scikit-learn
Last synced: 30 days ago
JSON representation
Convert scikit-learn models and pipelines to ONNX
- Host: GitHub
- URL: https://github.com/onnx/sklearn-onnx
- Owner: onnx
- License: apache-2.0
- Created: 2018-12-18T20:18:48.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-05-22T11:26:23.000Z (6 months ago)
- Last Synced: 2024-05-22T11:26:47.051Z (6 months ago)
- Topics: onnx, scikit-learn
- Language: Python
- Homepage:
- Size: 84.7 MB
- Stars: 510
- Watchers: 16
- Forks: 95
- Open Issues: 92
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOGS.md
- License: LICENSE
- Support: docs/supported.rst
Awesome Lists containing this project
README
[![Linux](https://github.com/onnx/sklearn-onnx/actions/workflows/linux-ci.yml/badge.svg)](https://github.com/onnx/sklearn-onnx/actions/workflows/linux-ci.yml)
[![Windows/Macos](https://github.com/onnx/sklearn-onnx/actions/workflows/windows-macos-ci.yml/badge.svg)](https://github.com/onnx/sklearn-onnx/actions/workflows/windows-macos-ci.yml)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
## Introduction
*sklearn-onnx* converts [scikit-learn](https://scikit-learn.org/stable/) models to [ONNX](https://github.com/onnx/onnx).
Once in the ONNX format, you can use tools like [ONNX Runtime](https://github.com/Microsoft/onnxruntime) for high performance scoring.
All converters are tested with [onnxruntime](https://onnxruntime.ai/).
Any external converter can be registered to convert scikit-learn pipeline
including models or transformers coming from external libraries.## Documentation
Full documentation including tutorials is available at [https://onnx.ai/sklearn-onnx/](https://onnx.ai/sklearn-onnx/).
[Supported scikit-learn Models](https://onnx.ai/sklearn-onnx/supported.html)
Last supported opset is 21.You may also find answers in [existing issues](https://github.com/onnx/sklearn-onnx/issues?utf8=%E2%9C%93&q=is%3Aissue)
or submit a new one.## Installation
You can install from [PyPi](https://pypi.org/project/skl2onnx/):
```
pip install skl2onnx
```
Or you can install from the source with the latest changes.
```
pip install git+https://github.com/onnx/sklearn-onnx.git
```## Getting started
```python
# Train a model.
import numpy as np
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifieriris = 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 = RandomForestClassifier()
clr.fit(X_train, y_train)# Convert into ONNX format.
from skl2onnx import to_onnxonx = to_onnx(clr, X[:1])
with open("rf_iris.onnx", "wb") as f:
f.write(onx.SerializeToString())# Compute the prediction with onnxruntime.
import onnxruntime as rtsess = rt.InferenceSession("rf_iris.onnx", providers=["CPUExecutionProvider"])
input_name = sess.get_inputs()[0].name
label_name = sess.get_outputs()[0].name
pred_onx = sess.run([label_name], {input_name: X_test.astype(np.float32)})[0]
```## Contribute
We welcome contributions in the form of feedback, ideas, or code.## License
[Apache License v2.0](LICENSE)