module sklapi.onnx_transformer
#
Short summary#
module mlprodict.sklapi.onnx_transformer
Wraps runtime into a scikit-learn transformer.
Classes#
class |
truncated documentation |
---|---|
Calls onnxruntime or the runtime implemented in this package to transform input based on a ONNX graph. It … |
Properties#
property |
truncated documentation |
---|---|
|
HTML representation of estimator. This is redundant with the logic of _repr_mimebundle_. The latter should … |
Returns the opsets as dictionary |
Static Methods#
staticmethod |
truncated documentation |
---|---|
Creates multiple OnnxTransformer, one for each requested intermediate node. onnx_bytes : bytes … |
Methods#
method |
truncated documentation |
---|---|
usual |
|
Ensures that double floats are converted into single floats if enforce_float32 is True or raises an exception. … |
|
Loads the ONNX model. |
|
Loads the ONNX model and runs the predictions. |
|
Returns a converter for this model. If not overloaded, it fetches the converter mapped to the first scikit-learn … |
|
Returns a parser for this model. |
|
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.
- 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
- __init__(onnx_bytes, output_name=None, enforce_float32=True, runtime='python', change_batch_size=None, reshape=False)#
- __repr__()#
usual
- _check_arrays(inputs)#
Ensures that double floats are converted into single floats if enforce_float32 is True or raises an exception.
- _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)
- fit(X=None, y=None, **fit_params)#
Loads the ONNX model.
- Parameters:
X – unused
y – unused
fit_params – additional parameter (unused)
- Returns:
self
- 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
inputs – ONNX 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:
- 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.
- onnx_parser()#
Returns a parser for this model.
- 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}
.
- 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
inputs – ONNX 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: