OnnxConverter Class
The converter that converts the pipeline/model objects from pkl format to onnx format.
Before the input data is fitted/transformed, call Initialize to setup the signature of the X. Then the convert method can be called multi times, to convert given sklearn pipeline.
Construct the Onnx converter.
- Inheritance
-
builtins.objectOnnxConverter
Constructor
OnnxConverter(version='', is_onnx_compatible=False, enable_split_onnx_featurizer_estimator_models=False, **kwargs)
Parameters
Name | Description |
---|---|
version
|
|
is_onnx_compatible
|
Default value: False
|
enable_split_onnx_featurizer_estimator_models
|
Default value: False
|
Methods
convert |
Convert the Python model with given child run object into ONNX model. |
get_converted_onnx_model_resource |
Get the resource of the converted ONNX model. |
get_init_metadata_dict |
Return the metadata dictionary of the onnx converter in the init phase. |
get_onnx_metadata |
given the training data, generate metadata needed for ONNX conversion |
initialize_input |
Initialize the converter with given training data X. NOTE.The X must be the original value, before it's transformed. :param X: The original input X before transformation applied. |
initialize_with_metadata |
Initialize the onnx converter with the previously generated init phase metadata. |
is_initialized |
Return if the converter is initialized or not. |
load_onnx_model |
Load the binary format ONNX model. |
save_onnx_model |
Save an ONNX model to a ProtoBuf object binary file. |
save_onnx_model_to_text_file |
Save the ONNX model in text format. |
convert
Convert the Python model with given child run object into ONNX model.
convert(raw_model: Pipeline, model_name: str = '', model_desc: str | Dict[str, Any] | None = None) -> Tuple[ModelProto | None, ModelProto | None, ModelProto | None, Dict[str, Any] | None]
Parameters
Name | Description |
---|---|
raw_model
Required
|
The sklearn pipeline object to convert to ONNX. |
model_name
Required
|
The name of the model. |
model_desc
|
The model description. Default value: None
|
get_converted_onnx_model_resource
Get the resource of the converted ONNX model.
get_converted_onnx_model_resource() -> Dict[Any, Any]
get_init_metadata_dict
Return the metadata dictionary of the onnx converter in the init phase.
get_init_metadata_dict() -> Dict[str, Any] | None
get_onnx_metadata
given the training data, generate metadata needed for ONNX conversion
static get_onnx_metadata(X: ndarray | DataFrame | spmatrix | EnginelessDataflow, x_raw_column_names: ndarray | None = None) -> Dict[str, Any] | None
Parameters
Name | Description |
---|---|
X
Required
|
Input data. |
x_raw_column_names
|
Default value: None
|
Returns
Type | Description |
---|---|
A metadata dictionary used by ONNX conversion. |
initialize_input
Initialize the converter with given training data X.
NOTE.The X must be the original value, before it's transformed. :param X: The original input X before transformation applied.
initialize_input(X: ndarray | DataFrame, x_raw_column_names: ndarray | None = None, model_name: str = '', model_desc: Dict[Any, Any] | None = None) -> None
Parameters
Name | Description |
---|---|
X
Required
|
|
x_raw_column_names
|
Default value: None
|
model_name
|
|
model_desc
|
Default value: None
|
initialize_with_metadata
Initialize the onnx converter with the previously generated init phase metadata.
initialize_with_metadata(metadata_dict: Dict[str, Any] | None, model_name: str = '', model_desc: Dict[Any, Any] | None = None) -> None
Parameters
Name | Description |
---|---|
metadata_dict
Required
|
|
model_name
|
|
model_desc
|
Default value: None
|
is_initialized
Return if the converter is initialized or not.
is_initialized()
load_onnx_model
Load the binary format ONNX model.
static load_onnx_model(file_path: str) -> ModelProto
Parameters
Name | Description |
---|---|
file_path
Required
|
the path including file name to save the model |
Returns
Type | Description |
---|---|
the loaded onnx model object. |
save_onnx_model
Save an ONNX model to a ProtoBuf object binary file.
static save_onnx_model(onnx_model: ModelProto, file_path: str) -> None
Parameters
Name | Description |
---|---|
model
Required
|
ONNX model |
file_path
Required
|
ONNX file (full file name) |
onnx_model
Required
|
|
save_onnx_model_to_text_file
Save the ONNX model in text format.
static save_onnx_model_to_text_file(onnx_model: ModelProto, file_path: str) -> None
Parameters
Name | Description |
---|---|
model
Required
|
ONNX model (object) |
file_path
Required
|
the path including file name to save the model |
onnx_model
Required
|
|