-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ci18' of https://github.com/xadupre/onnxmltools into xg…
…bempty
- Loading branch information
Showing
9 changed files
with
138 additions
and
157 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 |
---|---|---|
@@ -1,73 +1,66 @@ | ||
# Python package | ||
# Create and test a Python package on multiple Python versions. | ||
# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more: | ||
# https://docs.microsoft.com/azure/devops/pipelines/languages/python | ||
|
||
trigger: | ||
- master | ||
|
||
jobs: | ||
|
||
- job: 'Test' | ||
pool: | ||
vmImage: 'vs2017-win2016' | ||
strategy: | ||
matrix: | ||
Python36-nightly: | ||
python.version: '3.6' | ||
ONNX_PATH: onnx==1.7.0 | ||
ONNXRT_PATH: -i https://test.pypi.org/simple/ ort-nightly | ||
COREML_PATH: git+https://github.com/apple/coremltools@3.1 | ||
Python37-nightly: | ||
python.version: '3.7' | ||
ONNX_PATH: onnx==1.8.0 | ||
ONNXRT_PATH: -i https://test.pypi.org/simple/ ort-nightly | ||
COREML_PATH: git+https://github.com/apple/coremltools@3.1 | ||
maxParallel: 3 | ||
|
||
steps: | ||
- task: UsePythonVersion@0 | ||
inputs: | ||
versionSpec: '$(python.version)' | ||
architecture: 'x64' | ||
|
||
- powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts" | ||
displayName: Add conda to PATH | ||
|
||
- script: conda create --yes --quiet --name py$(python.version) -c conda-forge python=$(python.version) numpy protobuf | ||
displayName: Create Anaconda environment | ||
|
||
- script: | | ||
call activate py$(python.version) | ||
python -m pip install --upgrade pip numpy | ||
echo Test numpy installation... && python -c "import numpy" | ||
pip install %COREML_PATH% %ONNX_PATH% | ||
python -m pip install tensorflow-cpu==1.15.0 | ||
python -m pip install tf2onnx==1.5.6 | ||
python -m pip install git+https://github.com/microsoft/onnxconverter-common | ||
python -m pip install git+https://github.com/onnx/keras-onnx | ||
echo Test onnxconverter-common installation... && python -c "import onnxconverter_common" | ||
pip install -r requirements.txt | ||
pip install -r requirements-dev.txt | ||
pip install %ONNXRT_PATH% | ||
echo Test onnxruntime installation... && python -c "import onnxruntime" | ||
REM install libsvm from github | ||
git clone --recursive https://github.com/cjlin1/libsvm libsvm | ||
copy libsvm\windows\*.dll libsvm\python | ||
set PYTHONPATH=libsvm\python;%PYTHONPATH% | ||
dir libsvm\python | ||
echo Test libsvm installation... && python -c "import svmutil" | ||
displayName: 'Install dependencies' | ||
- script: | | ||
call activate py$(python.version) | ||
set PYTHONPATH=libsvm\python;%PYTHONPATH% | ||
pip install -e . | ||
python -m pytest tests --ignore=tests/sparkml --doctest-modules --junitxml=junit/test-results.xml | ||
displayName: 'pytest - onnxmltools' | ||
- task: PublishTestResults@2 | ||
inputs: | ||
testResultsFiles: '**/test-results.xml' | ||
testRunTitle: 'Python $(python.version)' | ||
condition: succeededOrFailed() | ||
# Python package | ||
# Create and test a Python package on multiple Python versions. | ||
# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more: | ||
# https://docs.microsoft.com/azure/devops/pipelines/languages/python | ||
|
||
trigger: | ||
- master | ||
|
||
jobs: | ||
|
||
- job: 'Test' | ||
pool: | ||
vmImage: 'vs2017-win2016' | ||
strategy: | ||
matrix: | ||
Python36-nightly: | ||
python.version: '3.6' | ||
ONNX_PATH: onnx==1.7.0 | ||
ONNXRT_PATH: -i https://test.pypi.org/simple/ ort-nightly | ||
COREML_PATH: git+https://github.com/apple/coremltools@3.1 | ||
Python37-nightly: | ||
python.version: '3.7' | ||
ONNX_PATH: onnx==1.8.0 | ||
ONNXRT_PATH: -i https://test.pypi.org/simple/ ort-nightly | ||
COREML_PATH: git+https://github.com/apple/coremltools@3.1 | ||
maxParallel: 3 | ||
|
||
steps: | ||
- task: UsePythonVersion@0 | ||
inputs: | ||
versionSpec: '$(python.version)' | ||
architecture: 'x64' | ||
|
||
- powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts" | ||
displayName: Add conda to PATH | ||
|
||
- script: conda create --yes --quiet --name py$(python.version) -c conda-forge python=$(python.version) numpy protobuf | ||
displayName: Create Anaconda environment | ||
|
||
- script: | | ||
call activate py$(python.version) | ||
python -m pip install --upgrade pip numpy | ||
echo Test numpy installation... && python -c "import numpy" | ||
pip install %COREML_PATH% %ONNX_PATH% | ||
python -m pip install tensorflow-cpu==1.15.0 | ||
python -m pip install tf2onnx==1.5.6 | ||
python -m pip install git+https://github.com/microsoft/onnxconverter-common | ||
python -m pip install git+https://github.com/onnx/keras-onnx | ||
echo Test onnxconverter-common installation... && python -c "import onnxconverter_common" | ||
pip install -r requirements.txt | ||
pip install -r requirements-dev.txt | ||
pip install %ONNXRT_PATH% | ||
echo Test onnxruntime installation... && python -c "import onnxruntime" | ||
displayName: 'Install dependencies' | ||
- script: | | ||
call activate py$(python.version) | ||
pip install -e . | ||
python -m pytest tests --ignore=tests/sparkml --doctest-modules --junitxml=junit/test-results.xml | ||
displayName: 'pytest - onnxmltools' | ||
- task: PublishTestResults@2 | ||
inputs: | ||
testResultsFiles: '**/test-results.xml' | ||
testRunTitle: 'Python $(python.version)' | ||
condition: succeededOrFailed() |
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
101 changes: 51 additions & 50 deletions
101
tests/coreml/test_cml_TreeEnsembleRegressorConverterXGBoost.py
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 |
---|---|---|
@@ -1,50 +1,51 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
""" | ||
Tests CoreML TreeEnsembleRegressor converter. | ||
""" | ||
import os | ||
import sys | ||
import unittest | ||
import numpy | ||
import pandas | ||
try: | ||
from sklearn.impute import SimpleImputer as Imputer | ||
import sklearn.preprocessing | ||
if not hasattr(sklearn.preprocessing, 'Imputer'): | ||
# coremltools 3.1 does not work with scikit-learn 0.22 | ||
setattr(sklearn.preprocessing, 'Imputer', Imputer) | ||
except ImportError: | ||
from sklearn.preprocessing import Imputer | ||
from coremltools.converters.xgboost import convert as convert_xgb_to_coreml | ||
from onnxmltools.convert.coreml import convert as convert_cml | ||
from xgboost import XGBRegressor | ||
from onnxmltools.utils import dump_data_and_model | ||
|
||
|
||
class TestCoreMLTreeEnsembleRegressorConverterXGBoost(unittest.TestCase): | ||
|
||
def test_tree_ensemble_regressor_xgboost(self): | ||
|
||
this = os.path.dirname(__file__) | ||
data_train = pandas.read_csv(os.path.join(this, "xgboost.model.xgb.n4.d3.train.txt"), header=None) | ||
|
||
X = data_train.iloc[:, 1:].values | ||
y = data_train.iloc[:, 0].values | ||
|
||
params = dict(n_estimator=4, max_depth=3) | ||
model = XGBRegressor(**params).fit(X, y) | ||
# See https://github.com/apple/coremltools/issues/51. | ||
model.booster = model.get_booster | ||
model_coreml = convert_xgb_to_coreml(model) | ||
model_onnx = convert_cml(model_coreml) | ||
assert model_onnx is not None | ||
if sys.version_info[0] >= 3: | ||
# python 2.7 returns TypeError: can't pickle instancemethod objects | ||
dump_data_and_model(X.astype(numpy.float32), model, model_onnx, | ||
basename="CmlXGBoostRegressor-OneOff-Reshape", | ||
allow_failure=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
""" | ||
Tests CoreML TreeEnsembleRegressor converter. | ||
""" | ||
import os | ||
import sys | ||
import unittest | ||
import numpy | ||
import pandas | ||
try: | ||
from sklearn.impute import SimpleImputer as Imputer | ||
import sklearn.preprocessing | ||
if not hasattr(sklearn.preprocessing, 'Imputer'): | ||
# coremltools 3.1 does not work with scikit-learn 0.22 | ||
setattr(sklearn.preprocessing, 'Imputer', Imputer) | ||
except ImportError: | ||
from sklearn.preprocessing import Imputer | ||
from coremltools.converters.xgboost import convert as convert_xgb_to_coreml | ||
from onnxmltools.convert.coreml import convert as convert_cml | ||
from xgboost import XGBRegressor | ||
from onnxmltools.utils import dump_data_and_model | ||
|
||
|
||
class TestCoreMLTreeEnsembleRegressorConverterXGBoost(unittest.TestCase): | ||
|
||
@unittest.skipIf(True, reason="broken") | ||
def test_tree_ensemble_regressor_xgboost(self): | ||
|
||
this = os.path.dirname(__file__) | ||
data_train = pandas.read_csv(os.path.join(this, "xgboost.model.xgb.n4.d3.train.txt"), header=None) | ||
|
||
X = data_train.iloc[:, 1:].values | ||
y = data_train.iloc[:, 0].values | ||
|
||
params = dict(n_estimator=4, max_depth=3) | ||
model = XGBRegressor(**params).fit(X, y) | ||
# See https://github.com/apple/coremltools/issues/51. | ||
model.booster = model.get_booster | ||
model_coreml = convert_xgb_to_coreml(model) | ||
model_onnx = convert_cml(model_coreml) | ||
assert model_onnx is not None | ||
if sys.version_info[0] >= 3: | ||
# python 2.7 returns TypeError: can't pickle instancemethod objects | ||
dump_data_and_model(X.astype(numpy.float32), model, model_onnx, | ||
basename="CmlXGBoostRegressor-OneOff-Reshape", | ||
allow_failure=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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