This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor rewritten sklearn operators
- Loading branch information
Showing
5 changed files
with
115 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
@file | ||
@brief Rewrites some of the converters implemented in | ||
:epkg:`sklearn-onnx`. | ||
""" | ||
import numpy | ||
from skl2onnx.operator_converters.support_vector_machines import ( | ||
convert_sklearn_svm_regressor, | ||
convert_sklearn_svm_classifier) | ||
|
||
|
||
def _op_type_domain_regressor(container): | ||
""" | ||
Defines *op_type* and *op_domain* based on | ||
`container.dtype`. | ||
""" | ||
if container.dtype == numpy.float32: | ||
return 'SVMRegressor', 'ai.onnx.ml', 1 | ||
if container.dtype == numpy.float64: | ||
return 'SVMRegressorDouble', 'mlprodict', 1 | ||
raise RuntimeError("Unsupported dtype {}.".format(container.dtype)) | ||
|
||
|
||
def _op_type_domain_classifier(container): | ||
""" | ||
Defines *op_type* and *op_domain* based on | ||
`container.dtype`. | ||
""" | ||
if container.dtype == numpy.float32: | ||
return 'SVMClassifier', 'ai.onnx.ml', 1 | ||
if container.dtype == numpy.float64: | ||
return 'SVMClassifierDouble', 'mlprodict', 1 | ||
raise RuntimeError("Unsupported dtype {}.".format(container.dtype)) | ||
|
||
|
||
def new_convert_sklearn_svm_regressor(scope, operator, container): | ||
""" | ||
Rewrites the converters implemented in | ||
:epkg:`sklearn-onnx` to support an operator supporting | ||
doubles. | ||
""" | ||
op_type, op_domain, op_version = _op_type_domain_regressor(container) | ||
convert_sklearn_svm_regressor( | ||
scope, operator, container, op_type=op_type, op_domain=op_domain, | ||
op_version=op_version) | ||
|
||
|
||
def new_convert_sklearn_svm_classifier(scope, operator, container): | ||
""" | ||
Rewrites the converters implemented in | ||
:epkg:`sklearn-onnx` to support an operator supporting | ||
doubles. | ||
""" | ||
op_type, op_domain, op_version = _op_type_domain_classifier(container) | ||
convert_sklearn_svm_classifier( | ||
scope, operator, container, op_type=op_type, op_domain=op_domain, | ||
op_version=op_version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters