ONNX sklearn converter is a small python package that uses skl2onnx (ONNX official package) to convert sklearn models to ONNX format. This repo provide an easy-to-use framework to boost your sklearn models to production.
To use sklearn-onnx-converter you have to clone the repo and install the package.
- Python >=3.8
Before to use sklearn-onnx-converter you must install the package using pip
$ pip install .
To build the docker image you can use the following command:
$ docker build . -t sklearn-onnx
To convert a sklearn model to the ONNX format you can run the convert command as a bash script or using it as a Python script. (See the examples folder for more details).
$ python onnx_converter/onnx_converter.py -m PATH_TO_SKLEARN_MODEL -f PATH_TO_YOUR_FEATURE_CONFIG_FILE -o OUTPUT_FOLDER
- Create a main.py:
# main.py
from sklearn_onnx_converter import convert
if __name__ == "__main__":
convert(
# your sklearn model path
model_path="model_path",
# feature config YAML file
feature_config="features.yaml",
# output path
output_path="output_dir",
)
- run the script:
$ python main.py
$ docker run \
-v INPUT_FOLDER_ABSOLUTE_PATH:/input \
-v OUTPUT_FOLDER_ABSOLUTE_PATH:/output \
sklearn-onnx \
-m /input/MODEL_NAME \
-o /output/OUTPUT_DIRECTORY \
-f /input/FEATURE_CONFIG_FILE.yaml
- Add docker support
- Add more examples
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request