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.
from sklearn.linear_model import LogisticRegression
from skl2onnx import to_onnx
X = numpy.array([[0, 0.1]])
except Exception as e:
Unable to find a shape calculator for type '<class 'sphinx_runpython.runpython.sphinx_runpython_extension.run_python_script_139750068154240.<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
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.