Skip to content

Commit 329fdd4

Browse files
committed
Merge branch 'master' into r1.9
2 parents 8e8c234 + da324a5 commit 329fdd4

File tree

302 files changed

+24093
-1484
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

302 files changed

+24093
-1484
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ __pycache__
1313
.eggs
1414
*.egg-info
1515
run.sh
16+
tests/tfhub/*/*.onnx
17+
tests/tfhub/*/*.tar.gz
18+
tests/tfhub/*/*.tflite
19+
tests/tfhub/*/**

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<!--- SPDX-License-Identifier: Apache-2.0 -->
22

3-
# tf2onnx - Convert TensorFlow, Keras and Tflite models to ONNX.
3+
# tf2onnx - Convert TensorFlow, Keras, Tensorflow.js and Tflite models to ONNX.
44

5-
tf2onnx converts TensorFlow (tf-1.x or tf-2.x), tf.keras and tflite models to ONNX via command
5+
tf2onnx converts TensorFlow (tf-1.x or tf-2.x), keras, tensorflow.js and tflite models to ONNX via command
66
line or python api.
77

8-
__Note: after tf2onnx-1.8.3 we made a change that impacts the output names for the ONNX model.
9-
Instead of taking the output names from the tensorflow graph (ie. for keras models this is frequently Identity:0) we decided that it is better to use the structured output names of the model so the output names are now identical to the names in the keras or saved model.__
8+
__Note: tensorflow.js support was just added. While we tested it with many tfjs models from tfhub, it should be considered experimental.__
109

1110
TensorFlow has many more ops than ONNX and occasionally mapping a model to ONNX creates issues.
1211

@@ -18,8 +17,8 @@ The common issues we run into we try to document here [Troubleshooting Guide](Tr
1817

1918
| Build Type | OS | Python | Tensorflow | ONNX opset | Status |
2019
| --- | --- | --- | --- | --- | --- |
21-
| Unit Test - Basic | Linux, MacOS<sup>\*</sup>, Windows<sup>\*</sup> | 3.6-3.9 | 1.12-1.15, 2.1-2.5 | 8-14 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test?branchName=master)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=16&branchName=master) |
22-
| Unit Test - Full | Linux, MacOS, Windows | 3.6-3.9 | 1.12-1.15, 2.1-2.5 | 8-14 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test-matrix?branchName=master)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=18&branchName=master) | |
20+
| Unit Test - Basic | Linux, MacOS<sup>\*</sup>, Windows<sup>\*</sup> | 3.6-3.9 | 1.12-1.15, 2.1-2.6 | 8-14 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test?branchName=master)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=16&branchName=master) |
21+
| Unit Test - Full | Linux, MacOS, Windows | 3.6-3.9 | 1.12-1.15, 2.1-2.6 | 8-14 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test-matrix?branchName=master)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=18&branchName=master) | |
2322
<br/>
2423

2524
## Supported Versions
@@ -127,7 +126,8 @@ We recently added support for tflite. You convert ```tflite``` models via comman
127126
python -m tf2onnx.convert
128127
--saved-model SOURCE_SAVED_MODEL_PATH |
129128
--checkpoint SOURCE_CHECKPOINT_METAFILE_PATH |
130-
--tflite SOURCE_TFLITE_PATH |
129+
--tflite TFLITE_MODEL_PATH |
130+
--tfjs TFJS_MODEL_PATH |
131131
--input | --graphdef SOURCE_GRAPHDEF_PB
132132
--output TARGET_ONNX_MODEL
133133
[--inputs GRAPH_INPUTS]
@@ -157,14 +157,18 @@ TensorFlow model as saved_model. We expect the path to the saved_model directory
157157

158158
TensorFlow model as checkpoint. We expect the path to the .meta file.
159159

160-
#### --tflite
161-
162-
Convert a tflite model by providing a path to the .tflite file. Inputs/outputs do not need to be specified.
163-
164160
#### --input or --graphdef
165161

166162
TensorFlow model as graphdef file.
167163

164+
#### --tfjs
165+
166+
Convert a tensorflow.js model by providing a path to the .tfjs file. Inputs/outputs do not need to be specified.
167+
168+
#### --tflite
169+
170+
Convert a tflite model by providing a path to the .tflite file. Inputs/outputs do not need to be specified.
171+
168172
#### --output
169173

170174
The target onnx file path.
@@ -260,7 +264,6 @@ optional arguments:
260264
--opset OPSET target opset to use
261265
--perf csv-file capture performance numbers for tensorflow and onnx runtime
262266
--debug dump generated graph with shape info
263-
--fold_const when set, TensorFlow fold_constants transformation will be applied before conversion. This will benefit features including Transpose optimization (e.g. Transpose operations introduced during tf-graph-to-onnx-graph conversion will be removed), and RNN unit conversion (for example LSTM).
264267
```
265268
```run_pretrained_models.py``` will run the TensorFlow model, captures the TensorFlow output and runs the same test against the specified ONNX backend after converting the model.
266269

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Nightly keras2onnx application tests
2+
3+
jobs:
4+
5+
- job: 'Linux'
6+
timeoutInMinutes: 180
7+
pool:
8+
vmImage: 'Ubuntu-16.04'
9+
strategy:
10+
matrix:
11+
Python36-onnx1.5:
12+
python.version: '3.6'
13+
ONNX_PATH: onnx==1.5.0
14+
INSTALL_KERAS: pip install keras==2.2.4
15+
UNINSTALL_KERAS:
16+
INSTALL_TENSORFLOW: pip install tensorflow==1.15.0
17+
INSTALL_ORT: pip install onnxruntime==1.8.0
18+
INSTALL_KERAS_RESNET: pip install keras-resnet
19+
INSTALL_TRANSFORMERS:
20+
NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py"
21+
22+
Python37-onnx1.6:
23+
python.version: '3.7.3'
24+
ONNX_PATH: onnx==1.6.0
25+
INSTALL_KERAS: pip install keras==2.3.1
26+
UNINSTALL_KERAS:
27+
INSTALL_TENSORFLOW: pip install tensorflow==1.15.0
28+
INSTALL_ORT: pip install onnxruntime==1.8.0
29+
INSTALL_KERAS_RESNET: pip install keras-resnet
30+
INSTALL_TRANSFORMERS:
31+
NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py"
32+
33+
Python37-onnx1.9:
34+
python.version: '3.7.3'
35+
ONNX_PATH: onnx==1.9.0
36+
INSTALL_KERAS: pip install keras==2.3.1
37+
UNINSTALL_KERAS:
38+
INSTALL_TENSORFLOW: pip install tensorflow==1.15.0
39+
INSTALL_ORT: pip install onnxruntime==1.8.0
40+
INSTALL_KERAS_RESNET: pip install keras-resnet
41+
INSTALL_TRANSFORMERS:
42+
NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py"
43+
44+
Python38-tf2:
45+
python.version: '3.8'
46+
ONNX_PATH: onnx==1.9.0
47+
INSTALL_KERAS:
48+
UNINSTALL_KERAS: pip uninstall keras -y
49+
INSTALL_TENSORFLOW: pip install tensorflow==2.2.0
50+
INSTALL_ORT: pip install onnxruntime==1.8.0
51+
INSTALL_KERAS_RESNET: pip install keras-resnet
52+
INSTALL_TRANSFORMERS: pip install transformers==3.4.0
53+
NIGHTLY_BUILD_TEST: python run_all_v2.py
54+
55+
steps:
56+
- template: 'templates/keras2onnx_application_tests.yml'
57+
parameters:
58+
platform: 'linux'
59+
60+
- job: 'Win'
61+
timeoutInMinutes: 180
62+
pool:
63+
vmImage: 'vs2017-win2016'
64+
strategy:
65+
matrix:
66+
Python36-onnx1.5:
67+
python.version: '3.6'
68+
ONNX_PATH: onnx==1.5.0
69+
INSTALL_KERAS: pip install keras==2.2.4
70+
UNINSTALL_KERAS:
71+
INSTALL_TENSORFLOW: pip install tensorflow==1.15.0
72+
INSTALL_ORT: pip install onnxruntime==1.8.0
73+
INSTALL_KERAS_RESNET: pip install keras-resnet
74+
INSTALL_TRANSFORMERS:
75+
NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py test_mask_rcnn.py"
76+
77+
Python37-onnx1.6:
78+
python.version: '3.7'
79+
ONNX_PATH: onnx==1.6.0
80+
INSTALL_KERAS: pip install keras==2.3.1
81+
UNINSTALL_KERAS:
82+
INSTALL_TENSORFLOW: pip install tensorflow==1.15.0
83+
INSTALL_ORT: pip install onnxruntime==1.8.0
84+
INSTALL_KERAS_RESNET: pip install keras-resnet
85+
INSTALL_TRANSFORMERS:
86+
NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py test_mask_rcnn.py"
87+
88+
Python37-onnx1.9:
89+
python.version: '3.7'
90+
ONNX_PATH: onnx==1.9.0
91+
INSTALL_KERAS: pip install keras==2.3.1
92+
UNINSTALL_KERAS:
93+
INSTALL_TENSORFLOW: pip install tensorflow==1.15.0
94+
INSTALL_ORT: pip install onnxruntime==1.8.0
95+
INSTALL_KERAS_RESNET: pip install keras-resnet
96+
INSTALL_TRANSFORMERS:
97+
NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py test_mask_rcnn.py"
98+
99+
steps:
100+
- template: 'templates/keras2onnx_application_tests.yml'
101+
parameters:
102+
platform: 'windows'

ci_build/azure_pipelines/keras2onnx_unit_test.yml

Lines changed: 7 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Tests copied from keras2onnx
1+
# Nightly keras2onnx unit tests
22

33
jobs:
44

@@ -70,49 +70,9 @@ jobs:
7070
INSTALL_ORT: pip install onnxruntime==1.8.0
7171

7272
steps:
73-
- script: sudo install -d -m 0777 /home/vsts/.conda/envs
74-
displayName: Fix Conda permissions
75-
76-
- task: CondaEnvironment@1
77-
inputs:
78-
createCustomEnvironment: true
79-
environmentName: 'py$(python.version)'
80-
packageSpecs: 'python=$(python.version)'
81-
82-
- script: |
83-
python -m pip install --upgrade pip
84-
conda config --set always_yes yes --set changeps1 no
85-
pip install $(ONNX_PATH)
86-
pip install h5py==2.9.0
87-
pip install numpy==1.19
88-
pip install $(TENSORFLOW_PATH)
89-
if [[ ! -z $KERAS ]];
90-
then
91-
pip install $(KERAS)
92-
fi
93-
pip install git+https://github.com/microsoft/onnxconverter-common
94-
pip install -r requirements.txt
95-
pip install -r requirements-dev.txt
96-
pip install pytest pytest-cov pytest-runner
97-
$(INSTALL_ORT)
98-
displayName: 'Install dependencies'
99-
100-
- script: |
101-
pip install -e .
102-
python -c "import onnxruntime"
103-
python -c "import onnxconverter_common"
104-
if [[ ! -z $KERAS ]];
105-
then
106-
export TF_KERAS=0
107-
fi
108-
pytest keras2onnx_tests --doctest-modules --junitxml=junit/test-results.xml
109-
displayName: 'pytest'
110-
111-
- task: PublishTestResults@2
112-
inputs:
113-
testResultsFiles: '**/test-results.xml'
114-
testRunTitle: 'Python $(python.version)'
115-
condition: succeededOrFailed()
73+
- template: 'templates/keras2onnx_unit_test.yml'
74+
parameters:
75+
platform: 'linux'
11676

11777
- job: 'Win'
11878
pool:
@@ -179,43 +139,6 @@ jobs:
179139
INSTALL_ORT: pip install onnxruntime==1.8.0
180140

181141
steps:
182-
- task: UsePythonVersion@0
183-
inputs:
184-
versionSpec: '$(python.version)'
185-
architecture: 'x64'
186-
187-
- powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts"
188-
displayName: Add conda to PATH
189-
190-
- script: conda create --yes --quiet --name py$(python.version) -c conda-forge python=$(python.version) numpy protobuf
191-
displayName: Create Anaconda environment
192-
193-
- script: |
194-
call activate py$(python.version)
195-
python -m pip install --upgrade pip numpy==1.19
196-
echo Test numpy installation... && python -c "import numpy"
197-
pip install %ONNX_PATH%
198-
pip uninstall -y protobuf
199-
pip install protobuf
200-
pip install h5py==2.9.0
201-
pip install %TENSORFLOW_PATH%
202-
IF NOT "%KERAS%"=="" (pip install %KERAS%)
203-
pip install git+https://github.com/microsoft/onnxconverter-common
204-
pip install pytest pytest-cov pytest-runner
205-
%INSTALL_ORT%
206-
displayName: 'Install dependencies'
207-
208-
- script: |
209-
call activate py$(python.version)
210-
pip install -e .
211-
echo Test onnxruntime installation... && python -c "import onnxruntime"
212-
python -c "import onnxconverter_common"
213-
IF NOT "%KERAS%"=="" (set TF_KERAS=0)
214-
pytest keras2onnx_tests --doctest-modules --junitxml=junit/test-results.xml
215-
displayName: 'pytest'
216-
217-
- task: PublishTestResults@2
218-
inputs:
219-
testResultsFiles: '**/test-results.xml'
220-
testRunTitle: 'Python $(python.version)'
221-
condition: succeededOrFailed()
142+
- template: 'templates/keras2onnx_unit_test.yml'
143+
parameters:
144+
platform: 'windows'

ci_build/azure_pipelines/onnxruntime_nightly_test.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
stages:
44
- stage:
55
jobs:
6+
- template: 'templates/job_generator.yml'
7+
parameters:
8+
python_versions: ['3.7']
9+
tf_versions: ['2.5.0', '2.3.0']
10+
onnx_opsets: ['']
11+
onnx_backends: {onnxruntime: ['nightly']}
12+
skip_tflite_tests: 'False'
13+
skip_tf_tests: 'True'
14+
job:
15+
steps:
16+
- template: 'unit_test.yml'
17+
report_coverage: 'True'
18+
619
- template: 'templates/job_generator.yml'
720
parameters:
821
platforms: ['linux', 'windows']
@@ -38,6 +51,18 @@ stages:
3851
steps:
3952
- template: 'unit_test.yml'
4053
report_coverage: 'True'
54+
55+
- template: 'templates/job_generator.yml'
56+
parameters:
57+
platforms: ['linux']
58+
python_versions: ['3.7']
59+
tf_versions: ['2.4.1']
60+
onnx_opsets: ['']
61+
onnx_backends: {onnxruntime: ['nightly']}
62+
job:
63+
steps:
64+
- template: 'unit_test.yml'
65+
report_coverage: 'True'
4166

4267
- template: 'templates/job_generator.yml'
4368
parameters:
@@ -51,6 +76,18 @@ stages:
5176
- template: 'unit_test.yml'
5277
report_coverage: 'True'
5378

79+
- template: 'templates/job_generator.yml'
80+
parameters:
81+
platforms: ['linux']
82+
python_versions: ['3.9']
83+
tf_versions: ['2.6.0']
84+
onnx_opsets: ['']
85+
onnx_backends: {onnxruntime: ['nightly']}
86+
job:
87+
steps:
88+
- template: 'unit_test.yml'
89+
report_coverage: 'True'
90+
5491
- template: 'templates/job_generator.yml'
5592
parameters:
5693
platforms: ['windows']

ci_build/azure_pipelines/pretrained_model_test-matrix.yml

100644100755
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,20 @@ jobs:
3636
job:
3737
steps:
3838
- template: 'pretrained_model_test.yml'
39+
40+
- template: 'templates/job_generator.yml'
41+
parameters:
42+
platforms: ['linux', 'windows']
43+
python_versions: ['3.9']
44+
tf_versions: ['2.6.0']
45+
job:
46+
steps:
47+
- template: 'pretrained_model_test.yml'
48+
49+
schedules:
50+
- cron: "0 10 * * *"
51+
displayName: pre-trained model test, full matrix
52+
branches:
53+
include:
54+
- master
55+
always: true

ci_build/azure_pipelines/pretrained_model_test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ jobs:
66
python_versions: ['3.7']
77
tf_versions: ['2.4.1']
88
skip_tflite_tests: 'False'
9+
skip_tfjs_tests: 'False'
910
skip_tf_tests: 'True'
1011
job:
1112
steps:
@@ -14,7 +15,7 @@ jobs:
1415
- template: 'templates/job_generator.yml'
1516
parameters:
1617
python_versions: ['3.7']
17-
tf_versions: ['1.15.5','2.4.1']
18+
tf_versions: ['1.15.5','2.6.0']
1819
job:
1920
steps:
2021
- template: 'pretrained_model_test.yml'

0 commit comments

Comments
 (0)