A custom converter for a custom modelΒΆ
When sklearn-onnx converts a scikit-learn pipeline, it looks into every transformer and predictor and fetches the associated converter. The resulting ONNX graph combines the outcome of every converter in a single graph. If a model does not have its converter, it displays an error message telling it misses a converter.
<<<
import numpy
from sklearn.linear_model import LogisticRegression
from skl2onnx import to_onnx
class MyLogisticRegression(LogisticRegression):
pass
X = numpy.array([[0, 0.1]])
try:
to_onnx(MyLogisticRegression(), X)
except Exception as e:
print(e)
>>>
Unable to find a shape calculator for type '<class 'sphinx_runpython.runpython.sphinx_runpython_extension.run_python_script_140503414016832.<locals>.MyLogisticRegression'>'.
It usually means the pipeline being converted contains a
transformer or a predictor with no corresponding converter
implemented in sklearn-onnx. If the converted is implemented
in another library, you need to register
the converted so that it can be used by sklearn-onnx (function
update_registered_converter). If the model is not yet covered
by sklearn-onnx, you may raise an issue to
https://github.com/onnx/sklearn-onnx/issues
to get the converter implemented or even contribute to the
project. If the model is a custom model, a new converter must
be implemented. Examples can be found in the gallery.
Following sections show how to create a custom converter. It assumes this new converter is not meant to be added to this package but only to be registered and used when converting a pipeline. To to contribute and add a converter for a scikit-learn model, the logic is still the same, only the converter registration changes. PR 737 can be used as an example.