module npy.xop_convert#

Inheritance diagram of mlprodict.npy.xop_convert

Short summary#

module mlprodict.npy.xop_convert

Easier API to build onnx graphs. Inspired from skl2onnx.

Classes#

class

truncated documentation

OnnxSubEstimator

This operator is used to call the converter of a model to insert the node coming from the conversion into a bigger …

OnnxSubOnnx

This operator is used to insert existing ONNX into the ONNX graph being built.

Properties#

property

truncated documentation

input_names

Returns the input names.

input_names

Returns the input names.

output_names

Returns self.output_names_.

output_names

Returns self.output_names_.

Static Methods#

staticmethod

truncated documentation

_to_onnx

Converts a model into ONNX and inserts it into an ONNX graph.

_to_onnx_sklearn

Converts a scikit-learn model into ONNX and inserts it into an ONNX graph. The library relies on …

Methods#

method

truncated documentation

__init__

__init__

__repr__

usual

__repr__

usual

add_to

Adds to graph builder.

add_to

Adds to graph builder.

to_onnx_this

Returns the ONNX graph.

to_onnx_this

Returns the ONNX graph.

Documentation#

Easier API to build onnx graphs. Inspired from skl2onnx.

New in version 0.9.

source on GitHub

class mlprodict.npy.xop_convert.OnnxSubEstimator(model, *inputs, op_version=None, output_names=None, options=None, initial_types=None, **kwargs)#

Bases: OnnxSubOnnx

This operator is used to call the converter of a model to insert the node coming from the conversion into a bigger ONNX graph. It supports model from scikit-learn using sklearn-onnx.

Parameters:
  • model – model to convert

  • inputs – inputs

  • op_version – targetted opset

  • options – to rewrite the options used to convert the model

  • initial_types – the implementation may be wrong in guessing the input types of the model, this parameter can be used to overwrite them, usually a dictionary { input_name: numpy array as an example }

  • kwargs – any other parameters such as black listed or white listed operators

source on GitHub

__init__(model, *inputs, op_version=None, output_names=None, options=None, initial_types=None, **kwargs)#
__repr__()#

usual

static _to_onnx(model, inputs, op_version=None, options=None, initial_types=None, **kwargs)#

Converts a model into ONNX and inserts it into an ONNX graph.

Parameters:
  • model – a trained machine learned model

  • inputs – inputs

  • op_version – opset versions or None to use the latest one

  • options – options to change the behaviour of the converter

  • kwargs – additional parameters such as black listed or while listed operators

Returns:

ONNX model

The method currently supports models trained with scikit-learn, xgboost, :epkg`:lightgbm`.

source on GitHub

static _to_onnx_sklearn(model, inputs, op_version=None, options=None, initial_types=None, **kwargs)#

Converts a scikit-learn model into ONNX and inserts it into an ONNX graph. The library relies on function to_onnx and library :epkg:`skearn-onnx`.

Parameters:
  • model – a trained machine learned model

  • inputs – inputs

  • op_version – opset versions or None to use the latest one

  • initial_types – if None, the input types are guessed from the inputs. The function converts into ONNX the previous node of the graph and tries to infer the initial_types with the little informations it has. It may not work. It is recommended to specify this parameter.

  • options – options to change the behaviour of the converter

  • kwargs – additional parameters such as black listed or while listed operators

Returns:

ONNX model

Default options is {‘zipmap’: False} for a classifier.

source on GitHub

class mlprodict.npy.xop_convert.OnnxSubOnnx(model, *inputs, output_names=None)#

Bases: OnnxOperator

This operator is used to insert existing ONNX into the ONNX graph being built.

source on GitHub

__init__(model, *inputs, output_names=None)#
__repr__()#

usual

add_to(builder)#

Adds to graph builder.

Parameters:

builder – instance of _GraphBuilder, it must have a method add_node

source on GitHub

property input_names#

Returns the input names.

to_onnx_this(evaluated_inputs)#

Returns the ONNX graph.

Parameters:

evaluated_inputs – unused

Returns:

ONNX graph

source on GitHub