Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to 1.7 #384

Merged
merged 3 commits into from
Apr 9, 2020
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
7 changes: 0 additions & 7 deletions .azure-pipelines/linux-conda-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ jobs:
vmImage: 'Ubuntu-16.04'
strategy:
matrix:
Python27-123-RT040:
python.version: '2.7'
ONNX_PATH: onnx==1.2.3
ONNXRT_PATH: onnxruntime==0.4.0
xgboost.version: ''
# Python35:
# python.version: '3.5'
Python36-141-RT050:
python.version: '3.6'
ONNX_PATH: onnx==1.4.1
Expand Down
2 changes: 1 addition & 1 deletion onnxmltools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
This framework converts any machine learned model into onnx format
which is a common language to describe any machine learned model.
"""
__version__ = "1.6.5"
__version__ = "1.7.0"
__author__ = "Microsoft"
__producer__ = "OnnxMLTools"
__producer_version__ = __version__
Expand Down
5 changes: 3 additions & 2 deletions onnxmltools/convert/coreml/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

import coremltools
from uuid import uuid4
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
from ...proto import onnx
from ...proto import onnx_proto, get_opset_number_from_onnx
from ...proto import onnx_proto
from ..common._topology import convert_topology
from ._parse import parse_coreml

Expand Down Expand Up @@ -55,7 +56,7 @@ def convert(model, name=None, initial_types=None, doc_string='', target_opset=No
if name is None:
name = str(uuid4().hex)

target_opset = target_opset if target_opset else get_opset_number_from_onnx()
target_opset = target_opset if target_opset else get_maximum_opset_supported()
# Parse CoreML model as our internal data structure (i.e., Topology)
topology = parse_coreml(spec, initial_types, target_opset, custom_conversion_functions, custom_shape_calculators)

Expand Down
4 changes: 2 additions & 2 deletions onnxmltools/convert/h2o/_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

from onnxconverter_common.data_types import FloatTensorType
from ..common._container import H2OModelContainer
from ..common._topology import Topology, FloatTensorType
from ..common._topology import Topology

def _parse_h2o(scope, model, inputs):
'''
Expand Down
5 changes: 3 additions & 2 deletions onnxmltools/convert/h2o/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import tempfile
import h2o

from ...proto import onnx, get_opset_number_from_onnx
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
from ...proto import onnx
from ..common._topology import convert_topology
from ..common.data_types import FloatTensorType
from ._parse import parse_h2o
Expand Down Expand Up @@ -64,7 +65,7 @@ def convert(model, name=None, initial_types=None, doc_string='', target_opset=No
if mojo_model["params"]["algo"] != "gbm":
raise ValueError("Model type not supported (algo=%s). Only GBM Mojo supported for now." % mojo_model["params"]["algo"])

target_opset = target_opset if target_opset else get_opset_number_from_onnx()
target_opset = target_opset if target_opset else get_maximum_opset_supported()
topology = parse_h2o(mojo_model, initial_types, target_opset, custom_conversion_functions, custom_shape_calculators)
topology.compile()
onnx_model = convert_topology(topology, name, doc_string, target_opset, targeted_onnx)
Expand Down
4 changes: 2 additions & 2 deletions onnxmltools/convert/libsvm/_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

from onnxconverter_common.data_types import FloatTensorType
from ..common._container import LibSvmModelContainer
from ..common._topology import Topology, FloatTensorType
from ..common._topology import Topology


def _parse_libsvm_simple_model(scope, model, inputs):
Expand Down
2 changes: 2 additions & 0 deletions onnxmltools/convert/libsvm/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#--------------------------------------------------------------------------

from uuid import uuid4
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
from ...proto import onnx
from ..common._topology import convert_topology
from ._parse import parse_libsvm
Expand Down Expand Up @@ -34,6 +35,7 @@ def convert(model, name=None, initial_types=None, doc_string='', target_opset=No

if name is None:
name = str(uuid4().hex)
target_opset = target_opset if target_opset else get_maximum_opset_supported()

# Parse scikit-learn model as our internal data structure (i.e., Topology)
topology = parse_libsvm(model, initial_types, custom_conversion_functions,
Expand Down
5 changes: 3 additions & 2 deletions onnxmltools/convert/lightgbm/_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import numpy

from ..common._container import LightGbmModelContainer
from ..common._topology import *
from ..common.data_types import FloatTensorType
from ..common._topology import Topology
from ..common.data_types import (FloatTensorType,
SequenceType, DictionaryType, StringType, Int64Type)

from lightgbm import LGBMClassifier, LGBMRegressor

Expand Down
5 changes: 3 additions & 2 deletions onnxmltools/convert/lightgbm/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

from uuid import uuid4
import lightgbm
from ...proto import onnx, get_opset_number_from_onnx
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
from ...proto import onnx
from ..common._topology import convert_topology
from ._parse import parse_lightgbm, WrappedBooster

Expand Down Expand Up @@ -45,7 +46,7 @@ def convert(model, name=None, initial_types=None, doc_string='', target_opset=No
if name is None:
name = str(uuid4().hex)

target_opset = target_opset if target_opset else get_opset_number_from_onnx()
target_opset = target_opset if target_opset else get_maximum_opset_supported()
topology = parse_lightgbm(model, initial_types, target_opset, custom_conversion_functions, custom_shape_calculators)
topology.compile()
onnx_model = convert_topology(topology, name, doc_string, target_opset, targeted_onnx)
Expand Down
3 changes: 2 additions & 1 deletion onnxmltools/convert/sparkml/_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from onnxconverter_common.data_types import FloatTensorType
from .ops_names import get_sparkml_operator_name
from .ops_input_output import get_input_names, get_output_names

from ..common._container import SparkmlModelContainer
from ..common._topology import *
from ..common._topology import Topology

from pyspark.ml import PipelineModel

Expand Down
5 changes: 3 additions & 2 deletions onnxmltools/convert/sparkml/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
# --------------------------------------------------------------------------

from uuid import uuid4
from ...proto import onnx, get_opset_number_from_onnx
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
from ...proto import onnx
from ..common._topology import convert_topology
from ._parse import parse_sparkml
from . import operator_converters
Expand Down Expand Up @@ -63,7 +64,7 @@ def convert(model, name=None, initial_types=None, doc_string='', target_opset=No
if name is None:
name = str(uuid4().hex)

target_opset = target_opset if target_opset else get_opset_number_from_onnx()
target_opset = target_opset if target_opset else get_maximum_opset_supported()
# Parse spark-ml model as our internal data structure (i.e., Topology)
topology = parse_sparkml(spark_session, model, initial_types, target_opset, custom_conversion_functions, custom_shape_calculators)

Expand Down
5 changes: 3 additions & 2 deletions onnxmltools/convert/xgboost/_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import json
import numpy as np
from xgboost import XGBRegressor, XGBClassifier
from onnxconverter_common.data_types import FloatTensorType
from ..common._container import XGBoostModelContainer
from ..common._topology import *
from .common import get_xgb_params
from ..common._topology import Topology


xgboost_classifier_list = [XGBClassifier]

Expand Down
5 changes: 3 additions & 2 deletions onnxmltools/convert/xgboost/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

from uuid import uuid4
import xgboost
from ...proto import onnx, get_opset_number_from_onnx
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
from ...proto import onnx
from ..common._topology import convert_topology
from ._parse import parse_xgboost, WrappedBooster

Expand Down Expand Up @@ -40,7 +41,7 @@ def convert(model, name=None, initial_types=None, doc_string='', target_opset=No

if isinstance(model, xgboost.Booster):
model = WrappedBooster(model)
target_opset = target_opset if target_opset else get_opset_number_from_onnx()
target_opset = target_opset if target_opset else get_maximum_opset_supported()
topology = parse_xgboost(model, initial_types, target_opset, custom_conversion_functions, custom_shape_calculators)
topology.compile()
onnx_model = convert_topology(topology, name, doc_string, target_opset, targeted_onnx)
Expand Down
13 changes: 0 additions & 13 deletions onnxmltools/proto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,3 @@ def _make_tensor_fixed(name, data_type, dims, vals, raw=False):


helper.make_tensor = _make_tensor_fixed


def get_opset_number_from_onnx():
# since the method was widely used among while it is buggy to get the opset number...
# ... blindly, so change it to be safer without the name change.

default_max_opset = 11
try:
from onnxconverter_common.topology import DEFAULT_OPSET_NUMBER
default_max_opset = DEFAULT_OPSET_NUMBER
except: # noqa
pass
return min(default_max_opset, onnx.defs.onnx_opset_version())
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
keras2onnx
numpy
onnx
onnxconverter-common>=1.6.5, <1.7.0
onnxconverter-common>=1.7.0, <1.8.0
protobuf
six
skl2onnx
4 changes: 4 additions & 0 deletions tests/baseline/test_convert_baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ def test_keras2coreml_Dense_ImageNet_small(self):
"""
self.assertFalse(self.check_baseline(
"keras2coreml_Dense_ImageNet_small.mlmodel", "keras2coreml_Dense_ImageNet_small.json"))


if __name__ == "__main__":
unittest.main()
5 changes: 3 additions & 2 deletions tests/xgboost/test_xgboost_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from onnxmltools.convert.common.data_types import FloatTensorType
from onnxmltools.utils import dump_data_and_model
from onnxmltools.convert.xgboost.operator_converters.XGBoost import convert_xgboost as convert_xgb
from onnxmltools.proto import get_opset_number_from_onnx
from onnxconverter_common.onnx_ex import get_maximum_opset_supported


can_test = True
except ImportError:
Expand Down Expand Up @@ -135,7 +136,7 @@ def common_test_xgboost_10_skl(self, missing, replace=False):
input_xgb[input_xgb[:, :] == missing] = np.nan
onnx_last = convert_sklearn(model.steps[1][-1],
initial_types=[('X', FloatTensorType(shape=[None, input_xgb.shape[1]]))],
target_opset=get_opset_number_from_onnx())
target_opset=get_maximum_opset_supported())
session = rt.InferenceSession(onnx_last.SerializeToString())
pred_skl = model.steps[1][-1].predict(input_xgb).ravel()
pred_onx = session.run(None, {'X': input_xgb})[0].ravel()
Expand Down