ONNXMLTools facilitates the conversion of various machine learning models (e.g., scikit-learn, LightGBM, XGBoost, TensorFlow, SparkML) into the ONNX (Open Neural Network Exchange) format. This enables model interoperability across different frameworks and hardware. The current version is 1.16.0, and it maintains an active development cycle with new releases every few months.
pip install onnxmltoolsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates converting a simple LightGBM classifier into the ONNX format. It highlights the use of `convert_lightgbm` and the importance of defining `initial_types` and `target_opset`. Remember to install `lightgbm`, `onnx`, and `onnx_lightgbm` separately for this to run.
Install the required converter package alongside `onnxmltools`. For example, for LightGBM models, use `pip install onnxmltools onnx_lightgbm lightgbm`.
Carefully define `initial_types` using data types like `FloatTensorType`, `Int64TensorType`, etc., from `onnxmltools.convert.common.data_types`. Ensure the shape (e.g., `[None, num_features]`) matches your model's expected input.
Align `target_opset` with the capabilities of your ONNX Runtime environment and the features used in your original model. Consult the ONNX operator schema for supported opsets.
Explicitly check the output tensor shape after conversion and adjust post-processing logic if necessary. Newer versions of `onnxmltools` and underlying converters aim to standardize this, but vigilance is recommended.