module sklapi.onnx_transformer#

Inheritance diagram of mlprodict.sklapi.onnx_transformer

Short summary#

module mlprodict.sklapi.onnx_transformer

Wraps runtime into a scikit-learn transformer.

source on GitHub

Classes#

class

truncated documentation

OnnxTransformer

Calls onnxruntime or the runtime implemented in this package to transform input based on a ONNX graph. It …

Properties#

property

truncated documentation

_repr_html_

HTML representation of estimator. This is redundant with the logic of _repr_mimebundle_. The latter should …

opsets

Returns the opsets as dictionary {domain: opset}.

Static Methods#

staticmethod

truncated documentation

enumerate_create

Creates multiple OnnxTransformer, one for each requested intermediate node. onnx_bytes : bytes …

Methods#

method

truncated documentation

__init__

__repr__

usual

_check_arrays

Ensures that double floats are converted into single floats if enforce_float32 is True or raises an exception. …

fit

Loads the ONNX model.

fit_transform

Loads the ONNX model and runs the predictions.

onnx_converter

Returns a converter for this model. If not overloaded, it fetches the converter mapped to the first scikit-learn

onnx_parser

Returns a parser for this model.

onnx_shape_calculator

transform

Runs the predictions. If X is a dataframe, the function assumes every columns is a separate input, otherwise, …

Documentation#

Wraps runtime into a scikit-learn transformer.

source on GitHub

class mlprodict.sklapi.onnx_transformer.OnnxTransformer(onnx_bytes, output_name=None, enforce_float32=True, runtime='python', change_batch_size=None, reshape=False)#

Bases: BaseEstimator, TransformerMixin, OnnxOperatorMixin

Calls onnxruntime or the runtime implemented in this package to transform input based on a ONNX graph. It follows scikit-learn API so that it can be included in a scikit-learn pipeline. See notebook Transfer Learning with ONNX for an example.

Parameters:
  • onnx_bytes – bytes

  • output_name – string requested output name or None to request all and have method transform to store all of them in a dataframe

  • enforce_float32 – boolean onnxruntime only supports float32, scikit-learn usually uses double floats, this parameter ensures that every array of double floats is converted into single floats

  • runtime – string, defined the runtime to use as described in OnnxInference.

  • change_batch_size – some models are converted for a specific batch size, this parameter changes it, None to avoid changing it, 0 to fix an undefined first dimension

  • reshape – reshape the output to get a matrix and not a multidimensional array

source on GitHub

__init__(onnx_bytes, output_name=None, enforce_float32=True, runtime='python', change_batch_size=None, reshape=False)#
__repr__()#

usual

source on GitHub

_check_arrays(inputs)#

Ensures that double floats are converted into single floats if enforce_float32 is True or raises an exception.

source on GitHub

_sklearn_auto_wrap_output_keys = {'transform'}#
static enumerate_create(onnx_bytes, output_names=None, enforce_float32=True)#

Creates multiple OnnxTransformer, one for each requested intermediate node.

onnx_bytes : bytes output_names: string

requested output names or None to request all and have method transform to store all of them in a dataframe

enforce_float32boolean

onnxruntime only supports float32, scikit-learn usually uses double floats, this parameter ensures that every array of double floats is converted into single floats

Returns:

iterator on OnnxTransformer (‘output name’, OnnxTransformer)

source on GitHub

fit(X=None, y=None, **fit_params)#

Loads the ONNX model.

Parameters:
  • X – unused

  • y – unused

  • fit_params – additional parameter (unused)

Returns:

self

source on GitHub

fit_transform(X, y=None, **inputs)#

Loads the ONNX model and runs the predictions.

Parameters:
  • X – iterable, data to process (or first input if several expected)

  • y – unused

  • inputsONNX graph support multiple inputs, each column of a dataframe is converted into as many inputs if X is a dataframe, otherwise, X is considered as the first input and inputs can be used to specify the other ones

Returns:

DataFrame

source on GitHub

onnx_converter()#

Returns a converter for this model. If not overloaded, it fetches the converter mapped to the first scikit-learn parent it can find.

source on GitHub

onnx_parser()#

Returns a parser for this model.

source on GitHub

onnx_shape_calculator()#

Returns a shape calculator for this model. If not overloaded, it fetches the parser mapped to the first scikit-learn parent it can find.

property opsets#

Returns the opsets as dictionary {domain: opset}.

source on GitHub

transform(X, y=None, **inputs)#

Runs the predictions. If X is a dataframe, the function assumes every columns is a separate input, otherwise, X is considered as a first input and inputs can be used to specify extra inputs.

Parameters:
  • X – iterable, data to process (or first input if several expected)

  • y – unused

  • inputsONNX graph support multiple inputs, each column of a dataframe is converted into as many inputs if X is a dataframe, otherwise, X is considered as the first input and inputs can be used to specify the other ones

Returns:

DataFrame

source on GitHub