module npy.onnx_sklearn_wrapper#

Short summary#

module mlprodict.npy.onnx_sklearn_wrapper

Helpers to use numpy API to easily write converters for scikit-learn classes for onnx.

Functions#

function

truncated documentation

_call_validate

_common_converter_begin

_common_converter_int_t

_common_converter_t

_common_shape_calculator_int_t

_common_shape_calculator_t

_converter_classifier

Default converter for a classifier with one input and two outputs, label and probabilities of the same input type. …

_converter_cluster

Default converter for a clustering with one input and two outputs, label and distances of the same input type. It …

_converter_regressor

Default converter for a regressor with one input and one output of the same type. It assumes instance operator

_converter_transformer

Default converter for a transformer with one input and one output of the same type. It assumes instance operator

_internal_decorator

_internal_method_decorator

_shape_calculator_classifier

Default shape calculator for a classifier with one input and two outputs, label (int64) and probabilites of the same …

_shape_calculator_cluster

Default shape calculator for a clustering with one input and two outputs, label (int64) and distances of the same type. …

_shape_calculator_regressor

Default shape calculator for a regressor with one input and one output of the same type.

_shape_calculator_transformer

Default shape calculator for a transformer with one input and one output of the same type.

_skl2onnx_add_to_container

Adds ONNX graph to skl2onnx container and scope.

onnxsklearn_class

Decorator to declare a converter for a class derivated from scikit-learn, implementing inference method …

onnxsklearn_classifier

Decorator to declare a converter for a classifier implemented using numpy syntax but executed with ONNX

onnxsklearn_cluster

Decorator to declare a converter for a cluster implemented using numpy syntax but executed with ONNX

onnxsklearn_regressor

Decorator to declare a converter for a regressor implemented using numpy syntax but executed with ONNX

onnxsklearn_transformer

Decorator to declare a converter for a transformer implemented using numpy syntax but executed with ONNX

update_registered_converter_npy

Registers or updates a converter for a new model so that it can be converted when inserted in a scikit-learn pipeline. …

Documentation#

Helpers to use numpy API to easily write converters for scikit-learn classes for onnx.

New in version 0.6.

source on GitHub

mlprodict.npy.onnx_sklearn_wrapper._call_validate(self, X)#
mlprodict.npy.onnx_sklearn_wrapper._common_converter_begin(scope, operator, container, n_outputs)#
mlprodict.npy.onnx_sklearn_wrapper._common_converter_int_t(scope, operator, container)#
mlprodict.npy.onnx_sklearn_wrapper._common_converter_t(scope, operator, container)#
mlprodict.npy.onnx_sklearn_wrapper._common_shape_calculator_int_t(operator)#
mlprodict.npy.onnx_sklearn_wrapper._common_shape_calculator_t(operator)#
mlprodict.npy.onnx_sklearn_wrapper._converter_classifier(scope, operator, container)#

Default converter for a classifier with one input and two outputs, label and probabilities of the same input type. It assumes instance operator has an attribute onnx_numpy_fct_ from a function wrapped with decorator onnxsklearn_classifier.

New in version 0.6.

source on GitHub

mlprodict.npy.onnx_sklearn_wrapper._converter_cluster(scope, operator, container)#

Default converter for a clustering with one input and two outputs, label and distances of the same input type. It assumes instance operator has an attribute onnx_numpy_fct_ from a function wrapped with decorator onnxsklearn_cluster.

New in version 0.6.

source on GitHub

mlprodict.npy.onnx_sklearn_wrapper._converter_regressor(scope, operator, container)#

Default converter for a regressor with one input and one output of the same type. It assumes instance operator has an attribute onnx_numpy_fct_ from a function wrapped with decorator onnxsklearn_regressor.

New in version 0.6.

source on GitHub

mlprodict.npy.onnx_sklearn_wrapper._converter_transformer(scope, operator, container)#

Default converter for a transformer with one input and one output of the same type. It assumes instance operator has an attribute onnx_numpy_fct_ from a function wrapped with decorator onnxsklearn_transformer.

New in version 0.6.

source on GitHub

mlprodict.npy.onnx_sklearn_wrapper._internal_decorator(fct, op_version=None, runtime=None, signature=None, register_class=None, overwrite=True, options=None)#
mlprodict.npy.onnx_sklearn_wrapper._internal_method_decorator(register_class, method, op_version=None, runtime=None, signature=None, method_names=None, overwrite=True, options=None)#
mlprodict.npy.onnx_sklearn_wrapper._shape_calculator_classifier(operator)#

Default shape calculator for a classifier with one input and two outputs, label (int64) and probabilites of the same type.

New in version 0.6.

source on GitHub

mlprodict.npy.onnx_sklearn_wrapper._shape_calculator_cluster(operator)#

Default shape calculator for a clustering with one input and two outputs, label (int64) and distances of the same type.

New in version 0.6.

source on GitHub

mlprodict.npy.onnx_sklearn_wrapper._shape_calculator_regressor(operator)#

Default shape calculator for a regressor with one input and one output of the same type.

New in version 0.6.

source on GitHub

mlprodict.npy.onnx_sklearn_wrapper._shape_calculator_transformer(operator)#

Default shape calculator for a transformer with one input and one output of the same type.

New in version 0.6.

source on GitHub

mlprodict.npy.onnx_sklearn_wrapper._skl2onnx_add_to_container(onx, scope, container, outputs)#

Adds ONNX graph to skl2onnx container and scope.

Parameters:
  • onx – onnx graph

  • scope – scope

  • container – container

source on GitHub

mlprodict.npy.onnx_sklearn_wrapper.onnxsklearn_class(method_name, op_version=None, runtime=None, signature=None, method_names=None, overwrite=True)#

Decorator to declare a converter for a class derivated from scikit-learn, implementing inference method and using numpy syntax but executed with ONNX operators.

Parameters:
  • method_name – name of the method implementing the inference method with numpy API for ONNX

  • op_versionONNX opset version

  • runtime‘onnxruntime’ or one implemented by OnnxInference

  • signature – if None, the signature is replaced by a standard signature depending on the model kind, otherwise, it is the signature of the ONNX function

  • method_names – if None, method names is guessed based on the class kind (transformer, regressor, classifier, clusterer)

  • overwrite – overwrite existing registered function if any

New in version 0.6.

source on GitHub

mlprodict.npy.onnx_sklearn_wrapper.onnxsklearn_classifier(op_version=None, runtime=None, signature=None, register_class=None, overwrite=True)#

Decorator to declare a converter for a classifier implemented using numpy syntax but executed with ONNX operators.

Parameters:
  • op_versionONNX opset version

  • runtime‘onnxruntime’ or one implemented by OnnxInference

  • signature – if None, the signature is replaced by a standard signature for transformer NDArraySameType("all")

  • register_class – automatically register this converter for this class to sklearn-onnx

  • overwrite – overwrite existing registered function if any

New in version 0.6.

source on GitHub

mlprodict.npy.onnx_sklearn_wrapper.onnxsklearn_cluster(op_version=None, runtime=None, signature=None, register_class=None, overwrite=True)#

Decorator to declare a converter for a cluster implemented using numpy syntax but executed with ONNX operators.

Parameters:
  • op_versionONNX opset version

  • runtime‘onnxruntime’ or one implemented by OnnxInference

  • signature – if None, the signature is replaced by a standard signature for transformer NDArraySameType("all")

  • register_class – automatically register this converter for this class to sklearn-onnx

  • overwrite – overwrite existing registered function if any

New in version 0.6.

source on GitHub

mlprodict.npy.onnx_sklearn_wrapper.onnxsklearn_regressor(op_version=None, runtime=None, signature=None, register_class=None, overwrite=True)#

Decorator to declare a converter for a regressor implemented using numpy syntax but executed with ONNX operators.

Parameters:
  • op_versionONNX opset version

  • runtime‘onnxruntime’ or one implemented by OnnxInference

  • signature – if None, the signature is replaced by a standard signature for transformer NDArraySameType("all")

  • register_class – automatically register this converter for this class to sklearn-onnx

  • overwrite – overwrite existing registered function if any

New in version 0.6.

source on GitHub

mlprodict.npy.onnx_sklearn_wrapper.onnxsklearn_transformer(op_version=None, runtime=None, signature=None, register_class=None, overwrite=True)#

Decorator to declare a converter for a transformer implemented using numpy syntax but executed with ONNX operators.

Parameters:
  • op_versionONNX opset version

  • runtime‘onnxruntime’ or one implemented by OnnxInference

  • signature – if None, the signature is replaced by a standard signature for transformer NDArraySameType("all")

  • register_class – automatically register this converter for this class to sklearn-onnx

  • overwrite – overwrite existing registered function if any

New in version 0.6.

source on GitHub

mlprodict.npy.onnx_sklearn_wrapper.update_registered_converter_npy(model, alias, convert_fct, shape_fct=None, overwrite=True, parser=None, options=None)#

Registers or updates a converter for a new model so that it can be converted when inserted in a scikit-learn pipeline. This function assumes the converter is written as a function decoarated with onnxsklearn_transformer.

Parameters:
  • model – model class

  • alias – alias used to register the model

  • shape_fct – function which checks or modifies the expected outputs, this function should be fast so that the whole graph can be computed followed by the conversion of each model, parallelized or not

  • convert_fct – function which converts a model

  • overwrite – False to raise exception if a converter already exists

  • parser – overwrites the parser as well if not empty

  • options – registered options for this converter

The alias is usually the library name followed by the model name.

New in version 0.6.

source on GitHub