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 'pyquickhelper.sphinxext.sphinx_runpython_extension.run_python_script_140034457742208.<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 section shows how to create a custom converter.