Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from sklearn.mixture import GaussianMixture, BayesianGaussianMixture
from skl2onnx import convert_sklearn, to_onnx
from skl2onnx.common.data_types import FloatTensorType
from mlprodict.tools.ort_wrapper import OrtFail
from onnxruntime.capi._pybind_state import Fail as OrtFail # pylint: disable=E0611
from mlprodict.tools.ort_wrapper import InferenceSession
from mlprodict.testing.test_utils import dump_data_and_model
from mlprodict import __max_supported_opset__ as TARGET_OPSET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from pyquickhelper.ipythonhelper import test_notebook_execution_coverage
from pyquickhelper.pycode import (
add_missing_development_version, ExtTestCase)
from onnxruntime import __version__ as ort_version
from skl2onnx import __version__ as skl2onnx_version
import mlprodict
from mlprodict.tools.ort_wrapper import onnxrt_version as ort_version


class TestNotebookNumpyOnnx(ExtTestCase):
Expand Down
2 changes: 1 addition & 1 deletion _unittests/ut_documentation/test_run_notebooks_onnx_sbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from pyquickhelper.pycode import (
add_missing_development_version, ExtTestCase)
from skl2onnx import __version__ as skl2onnx_version
from onnxruntime import __version__ as ort_version
import mlprodict
from mlprodict.tools.ort_wrapper import onnxrt_version as ort_version


class TestNotebookOnnxSbs(ExtTestCase):
Expand Down
5 changes: 3 additions & 2 deletions _unittests/ut_npy/test_a_onnx_variable_ort.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
from typing import Any
import numpy
from pyquickhelper.pycode import ExtTestCase, ignore_warnings
from mlprodict.tools.ort_wrapper import OrtInvalidArgument
from onnxruntime.capi._pybind_state import ( # pylint: disable=E0611
InvalidArgument as OrtInvalidArgument)
from mlprodict.npy import onnxnumpy, onnxnumpy_np
import mlprodict.npy.numpy_onnx_impl as nxnp
from mlprodict.npy import (
OnnxNumpyCompiler as ONC, NDArray, NDArraySameTypeSameShape)
import mlprodict.npy.numpy_onnx_impl as nxnp


@ignore_warnings(DeprecationWarning)
Expand Down
3 changes: 2 additions & 1 deletion _unittests/ut_npy/test_a_onnxpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from typing import Any
import numpy
from pyquickhelper.pycode import ExtTestCase
from mlprodict.tools.ort_wrapper import OrtInvalidArgument
from onnxruntime.capi._pybind_state import ( # pylint: disable=E0611
InvalidArgument as OrtInvalidArgument)
from mlprodict.npy import OnnxNumpyCompiler as ONC, NDArray
from mlprodict.npy.onnx_variable import OnnxVar
from mlprodict.npy.onnx_numpy_annotation import _NDArrayAlias
Expand Down
2 changes: 1 addition & 1 deletion _unittests/ut_npy/test_b_numpy_onnx_pyrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import scipy.special as sp
from pyquickhelper.pycode import ExtTestCase, ignore_warnings
from pyquickhelper.texthelper import compare_module_version
from onnxruntime import __version__ as ort_version
from mlprodict.onnxrt import OnnxInference
from mlprodict.onnxrt.ops_cpu.op_pad import onnx_pad
from mlprodict.npy.onnx_version import FctVersion
from mlprodict.tools.ort_wrapper import onnxrt_version as ort_version
from mlprodict.plotting.text_plot import onnx_simple_text_plot
import mlprodict.npy.numpy_onnx_pyrt as nxnpy

Expand Down
3 changes: 2 additions & 1 deletion _unittests/ut_onnx_conv/test_onnx_conv_knn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from pandas import DataFrame
from scipy.spatial.distance import cdist as scipy_cdist
from pyquickhelper.pycode import ExtTestCase, ignore_warnings as igw
from onnxruntime.capi._pybind_state import ( # pylint: disable=E0611
InvalidArgument as OrtInvalidArgument)
from sklearn.calibration import CalibratedClassifierCV
from sklearn.datasets import load_iris, make_regression
from sklearn.model_selection import train_test_split
Expand All @@ -26,7 +28,6 @@
from mlprodict.onnxrt.ops_cpu.op_topk import topk_sorted_implementation
from mlprodict import __max_supported_opset__ as TARGET_OPSET, get_ir_version
from mlprodict.testing.test_utils import _capture_output
from mlprodict.tools.ort_wrapper import OrtInvalidArgument


def old_topk_sorted_implementation(X, k, axis, largest):
Expand Down
2 changes: 1 addition & 1 deletion _unittests/ut_onnxrt/test_bugs_onnxconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from sklearn.model_selection import train_test_split
from sklearn.ensemble import AdaBoostClassifier
from sklearn.tree import DecisionTreeClassifier
from skl2onnx import to_onnx
from mlprodict.onnx_conv import to_onnx
from mlprodict.onnxrt import OnnxInference


Expand Down
3 changes: 2 additions & 1 deletion _unittests/ut_onnxrt/test_onnx_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
_numpy_array)
from mlprodict.onnxrt.ops_cpu._op_helper import proto2dtype
from mlprodict.onnxrt import OnnxInference
from mlprodict.tools.ort_wrapper import OrtInvalidArgument


class TestOnnxHelper(ExtTestCase):
Expand All @@ -39,6 +38,8 @@ def test_conversion_int64(self):

@skipif_appveyor("unstable")
def test_change_input_first_dimension(self):
from onnxruntime.capi._pybind_state import ( # pylint: disable=E0611
InvalidArgument as OrtInvalidArgument)
iris = load_iris()
X, _ = iris.data, iris.target
clr = KMeans()
Expand Down
2 changes: 1 addition & 1 deletion _unittests/ut_onnxrt/test_onnx_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from mlprodict.onnx_conv import to_onnx
from mlprodict.onnxrt import OnnxInference
from mlprodict import __max_supported_opset__ as TARGET_OPSET
from mlprodict.tools.ort_wrapper import SessionOptions


class TestOnnxInference(ExtTestCase):
Expand Down Expand Up @@ -53,6 +52,7 @@ def test_onnx_inference_name_confusion(self):

@ignore_warnings(DeprecationWarning)
def test_onnx_inference_so(self):
from onnxruntime import SessionOptions
X = helper.make_tensor_value_info(
'X', TensorProto.FLOAT, [None, 2]) # pylint: disable=E1101
Y = helper.make_tensor_value_info(
Expand Down
5 changes: 3 additions & 2 deletions _unittests/ut_onnxrt/test_onnxrt_iobinding.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
from onnxruntime.capi._pybind_state import ( # pylint: disable=E0611,W0611
OrtDevice as C_OrtDevice, OrtValue as C_OrtValue)
from onnxruntime import get_device
from skl2onnx.algebra.onnx_ops import ( # pylint: disable=E0611,W0611
OnnxAdd)
from mlprodict.onnxrt import OnnxInference
from mlprodict.tools.onnx_inference_ort_helper import get_ort_device
from mlprodict.npy.xop import loadop
from mlprodict import __max_supported_opset__ as TARGET_OPSET


DEVICE = "cuda" if get_device().upper() == 'GPU' else 'cpu'

OnnxAdd = loadop('Add')


class TestOnnxrtIOBinding(ExtTestCase):

Expand Down
11 changes: 6 additions & 5 deletions _unittests/ut_onnxrt/test_onnxrt_python_runtime_.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@
from mlprodict.onnxrt.ops_cpu._op_helper import proto2dtype
from mlprodict.onnx_tools.onnx2py_helper import (
guess_proto_dtype, _elem_type_as_str)
from mlprodict.tools.data_types import (
FloatTensorType, Int64TensorType, DoubleTensorType, StringTensorType,
Int32TensorType, BooleanTensorType, UInt8TensorType,
Int16TensorType, Int8TensorType, UInt16TensorType,
UInt32TensorType, UInt64TensorType, Float16TensorType)
from mlprodict.testing.test_utils.quantized_tensor import (
QuantizedTensor, QuantizedBiasTensor, test_qlinear_conv)
from mlprodict.onnxrt.ops_cpu.op_qlinear_conv_ import ( # pylint: disable=W0611,E0611,E0401
Expand All @@ -120,6 +115,12 @@
from mlprodict.plotting.text_plot import onnx_simple_text_plot
from mlprodict import __max_supported_opset__ as TARGET_OPSET, get_ir_version

from skl2onnx.common.data_types import ( # pylint: disable=C0412
FloatTensorType, Int64TensorType, DoubleTensorType, StringTensorType,
Int32TensorType, BooleanTensorType, UInt8TensorType,
Int16TensorType, Int8TensorType, UInt16TensorType,
UInt32TensorType, UInt64TensorType, Float16TensorType)

try:
numpy_str = numpy.str_
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion _unittests/ut_onnxrt/test_onnxrt_side_by_side.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from sklearn.gaussian_process.kernels import RBF, ConstantKernel as CK, Sum
from pyquickhelper.pycode import ExtTestCase, ignore_warnings
from pyquickhelper.texthelper.version_helper import compare_module_version
from onnxruntime import __version__ as ort_version
from skl2onnx.common.data_types import FloatTensorType
try:
from skl2onnx.operator_converters.gaussian_process import convert_kernel
Expand All @@ -19,7 +20,6 @@
side_by_side_by_values, merge_results,
_side_by_side_by_values_inputs)
from mlprodict.testing.test_utils import _capture_output
from mlprodict.tools.ort_wrapper import onnxrt_version as ort_version
from mlprodict import __max_supported_opset__ as TARGET_OPSET, get_ir_version


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import ExtTestCase, skipif_circleci
from pyquickhelper.texthelper.version_helper import compare_module_version
from onnxruntime import __version__ as ort_version
from sklearn.exceptions import ConvergenceWarning
try:
from sklearn.utils._testing import ignore_warnings
Expand All @@ -18,7 +19,6 @@
from skl2onnx.common.data_types import FloatTensorType
from mlprodict.onnxrt.validate import enumerate_validated_operator_opsets
from mlprodict.onnxrt import OnnxInference
from mlprodict.tools.ort_wrapper import onnxrt_version as ort_version
from mlprodict import __max_supported_opset__ as TARGET_OPSET, get_ir_version


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import ExtTestCase, skipif_circleci
from pyquickhelper.texthelper.version_helper import compare_module_version
from onnxruntime import __version__ as ort_version
from sklearn.exceptions import ConvergenceWarning
try:
from sklearn.utils._testing import ignore_warnings
except ImportError:
from sklearn.utils.testing import ignore_warnings
from skl2onnx import __version__ as skl2onnx_version
from mlprodict.onnxrt.validate import enumerate_validated_operator_opsets
from mlprodict.tools.ort_wrapper import onnxrt_version as ort_version


threshold = "0.4.0"
Expand Down
10 changes: 6 additions & 4 deletions _unittests/ut_plotting/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,32 @@
@brief test log(time=2s)
"""
import os
import platform
import unittest
from pyquickhelper.pycode import ExtTestCase, get_temp_folder
from mlprodict.plotting.plotting import plot_benchmark_metrics


class TestPlotBenchScatter(ExtTestCase):

@unittest.skipIf(platform.platform() != 'win32' and __name__ != '__main__',
reason="stream not closed by matplotlib")
def test_plot_logreg_xtime(self):
from matplotlib import pyplot as plt
temp = get_temp_folder(__file__, "temp_plot_benchmark_metrics")
img = os.path.join(temp, "plot_bench.png")

data = {(1, 1): 0.1, (10, 1): 1, (1, 10): 2,
(10, 10): 100, (100, 1): 100, (100, 10): 1000}
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 2, figsize=(10, 4))
plot_benchmark_metrics(data, ax=ax[0], cbar_kw={'shrink': 0.6})
plot_benchmark_metrics(data, ax=ax[1], transpose=True, xlabel='X', ylabel='Y',
cbarlabel="ratio")
# fig = ax[0].get_figure()
fig.savefig(img)
if __name__ == "__main__":
fig.savefig(img)
self.assertExists(img)
plt.show()
plt.close('all')
self.assertExists(img)


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion _unittests/ut_sklapi/test_onnx_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from pyquickhelper.pycode import ExtTestCase, skipif_appveyor, ignore_warnings
from mlprodict.sklapi import OnnxTransformer
from mlprodict import __max_supported_opset__ as TARGET_OPSET
from mlprodict.tools.ort_wrapper import OrtInvalidArgument


class TestOnnxTransformer(ExtTestCase):
Expand Down Expand Up @@ -110,6 +109,8 @@ def test_pipeline_iris(self):
@ignore_warnings(DeprecationWarning)
@skipif_appveyor("crashes")
def test_pipeline_iris_change_dim(self):
from onnxruntime.capi._pybind_state import ( # pylint: disable=E0611
InvalidArgument as OrtInvalidArgument)
iris = load_iris()
X, y = iris.data, iris.target
pipe = make_pipeline(PCA(n_components=2), LogisticRegression())
Expand Down
2 changes: 1 addition & 1 deletion _unittests/ut_testing/test_einsum.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy
from onnx import numpy_helper
from pyquickhelper.pycode import ExtTestCase
from mlprodict.tools.ort_wrapper import (
from onnxruntime import (
InferenceSession, GraphOptimizationLevel, SessionOptions)
from mlprodict.testing.einsum.einsum_impl_ext import (
numpy_diagonal, numpy_extended_dot, numpy_extended_dot_python)
Expand Down
3 changes: 1 addition & 2 deletions _unittests/ut_testing/test_filename.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from pyquickhelper.pycode import ExtTestCase
from mlprodict.tools.filename_helper import (
extract_information_from_filename,
make_readable_title
)
make_readable_title)


class TestFilename(ExtTestCase):
Expand Down
4 changes: 2 additions & 2 deletions _unittests/ut_testing/test_onnx_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ def test_enumerate_onnx_tests_run(self):

if __name__ == '__main__':
print(len(missed), len(failed), len(mismatch))
for t in missed:
print("missed", t[0])
for t in failed:
print("failed", t[0])
for t in mismatch:
print("mismatch", t[0])
for t in missed:
print("missed", t[0])


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion _unittests/ut_testing/test_sklearn_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ def test_plot_kernel_ridge_regression(self):


if __name__ == "__main__":
TestSklearnExample().test_plot_kernel_ridge_regression()
# TestSklearnExample().test_plot_kernel_ridge_regression()
unittest.main()
5 changes: 5 additions & 0 deletions _unittests/ut_tools/test_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@brief test log(time=2s)
"""
import unittest
import platform
import numpy
from sklearn.linear_model import LinearRegression
from sklearn.datasets import load_iris
Expand All @@ -13,8 +14,11 @@

class TestDisplay(ExtTestCase):

@unittest.skipIf(platform.platform() != 'win32' and __name__ != '__main__',
reason="stream not closed by matplotlib")
def test_plot_logreg_xtime(self):

import matplotlib.pyplot as plt
iris = load_iris()
X = iris.data[:, :2]
y = iris.target
Expand All @@ -25,6 +29,7 @@ def test_plot_logreg_xtime(self):
self.assertIn('opset_import', disp)
self.assertIn('producer_version', disp)
self.assertLess(len(disp), 1010)
plt.close('all')


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions _unittests/ut_tools/test_onnxrt_validate_rt_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class TestOnnxrtValidateRtGraph(ExtTestCase):

@ignore_warnings(category=(UserWarning, ConvergenceWarning, RuntimeWarning))
def test_validate_pyrt_ort(self):
fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__")
logger = getLogger('skl2onnx')
logger.disabled = True
verbose = 1 if __name__ == "__main__" else 0
Expand All @@ -37,10 +36,10 @@ def test_validate_pyrt_ort(self):
plt.clf()
self.assertNotEmpty(fig)
self.assertNotEmpty(ax)
plt.close('all')

@ignore_warnings(category=(UserWarning, ConvergenceWarning, RuntimeWarning))
def test_validate_pyrt_ort2(self):
fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__")
logger = getLogger('skl2onnx')
logger.disabled = True
verbose = 0 if __name__ == "__main__" else 0
Expand All @@ -60,6 +59,7 @@ def test_validate_pyrt_ort2(self):
plt.clf()
self.assertNotEmpty(fig)
self.assertNotEmpty(ax)
plt.close('all')


if __name__ == "__main__":
Expand Down
Loading