Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[MXNET-533] MXNet-ONNX export #11213

Merged
merged 83 commits into from
Jun 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
8d083f8
Resolve conflicts
Roshrini Apr 12, 2018
4c04e19
Export module Test Framework
rajanksin Apr 17, 2018
e66ef3b
refactoring export to work with pretrained models
Roshrini Apr 17, 2018
aa4e7cb
comments added
Roshrini Apr 17, 2018
f9e8cbf
1. Refactored export module.
rajanksin Apr 24, 2018
de3632d
Added Arithmetic operators:
rajanksin Apr 25, 2018
46931d3
Added operator support:
rajanksin Apr 25, 2018
ca74b02
Enabled ONNX tests: test_conv, test_basic_conv
rajanksin Apr 30, 2018
f653baf
Added support for:
rajanksin May 1, 2018
2cf7be0
adding more operators
Roshrini May 1, 2018
8ecf9dd
Added Operator support:
rajanksin May 2, 2018
af73173
Enabled more BASIC_MODEL tests
rajanksin May 2, 2018
e851cf3
Added power operator tests
Roshrini May 2, 2018
54edda1
Added support for reshape. ONNX only supports 0, -1 special values. …
rajanksin May 7, 2018
bb0b76f
some tests enabled
Roshrini May 7, 2018
917894b
enabling squeezenet
Roshrini May 7, 2018
b7e671b
LRN Op support
rajanksin May 8, 2018
e44960d
mul_scalar modified to take scalar input
Roshrini May 8, 2018
b918aa5
cleaning some code
Roshrini May 8, 2018
7b1e0ab
Resolving conlicts on rebase
Roshrini May 16, 2018
42c695c
Resolving rebase conflicts
Roshrini May 17, 2018
03226b3
id mapping updated for all operators
Roshrini May 17, 2018
43dad9b
save onnx models added, some code cleanup
Roshrini May 24, 2018
7cebe80
enabled more tests
Roshrini May 24, 2018
5ce301b
conv pad calc fixed
Roshrini May 30, 2018
f8c0afc
reshape op fix
Roshrini May 30, 2018
cfc081b
valueinfoproto fix, googlenet test added
Roshrini May 30, 2018
f070c22
Added support for elu, leakyRelu, prelu
rajanksin May 30, 2018
bb51c7f
Cleanup
rajanksin May 30, 2018
ae2f2c2
dilation added
Roshrini May 31, 2018
94d8614
Removed redundant code.
rajanksin May 31, 2018
f8943b3
some fixes to make export work with onx1.2.1
Roshrini May 31, 2018
1794554
Lint fixes
rajanksin May 31, 2018
628b1cd
lint fixes
rajanksin May 31, 2018
0d503e6
enabled more tests
Roshrini May 31, 2018
d6e73dc
mxnet_export_test file added
Roshrini May 31, 2018
26128a0
duplicate file deleted
Roshrini May 31, 2018
2de3d5a
reduce ops added
Roshrini Jun 1, 2018
7e56744
some small fixes
Roshrini Jun 4, 2018
dc3d8e7
some lint fixes
Roshrini Jun 4, 2018
4765b49
docstring added
Roshrini Jun 5, 2018
25566e0
Add tests for inception_v1 and inception_v2
rajanksin Jun 5, 2018
322b63a
Add CI runs for export module
rajanksin Jun 5, 2018
3de8a25
lint fixes, pooling attr fix
Roshrini Jun 5, 2018
f95f022
fix
Roshrini Jun 5, 2018
e1f324b
fix global_pool
Roshrini Jun 5, 2018
dc45f06
code cleanup
Roshrini Jun 5, 2018
17b7d85
CI run fix
rajanksin Jun 5, 2018
33e5ab6
lint fix
rajanksin Jun 5, 2018
6de4403
some code cleanup
Roshrini Jun 6, 2018
21c96c8
Added required license comments
rajanksin Jun 8, 2018
4aa962f
pad in pooling added
Roshrini Jun 6, 2018
31ba992
slicechannel notimplementederror raised
Roshrini Jun 8, 2018
6d150b4
Lint fixes
rajanksin Jun 8, 2018
db70ce3
lint fix
rajanksin Jun 9, 2018
69a3aa8
lint fix
rajanksin Jun 9, 2018
4ecd786
lint fix
rajanksin Jun 9, 2018
ab0bdc6
lint fix
rajanksin Jun 9, 2018
14c1362
Correct license statement
rajanksin Jun 11, 2018
acd3c79
Adding onnx a runtime dependency
rajanksin Jun 11, 2018
ba2d6ba
Fix import module error for string_types
rajanksin Jun 11, 2018
0829e4f
Making ONNX runtime dependency
rajanksin Jun 12, 2018
8988165
fixing some comments
Roshrini Jun 11, 2018
98d5dae
addressing some comments
Roshrini Jun 12, 2018
1ff47e1
params rename
Roshrini Jun 12, 2018
112c930
lint fixes
rajanksin Jun 12, 2018
50ade3e
fixes
Roshrini Jun 12, 2018
7d334e1
spatial disabled, path fixed
Roshrini Jun 12, 2018
ff123ee
fixing some comments
Roshrini Jun 12, 2018
7e626c7
Added support for remaining act_type(softsign, sigmoid, softrelu) in …
rajanksin Jun 12, 2018
4199ae8
changing import
Roshrini Jun 12, 2018
3d5f8be
adding some comments
Roshrini Jun 13, 2018
7412820
Add squeeze op
rajanksin Jun 13, 2018
a303eb1
Refactored logic to handle extra node(output label node) for saved mx…
rajanksin Jun 13, 2018
777144a
identity operator added
Roshrini Jun 13, 2018
4801fb3
scalar ops added
Roshrini Jun 14, 2018
c668689
minor fix for squeeze operator.
rajanksin Jun 13, 2018
20bb2fd
Renamed onnx support folders to mark it public folders
rajanksin Jun 14, 2018
f4902e1
Added support L2Normalization op
rajanksin Jun 15, 2018
84c9320
added comments and warning
Roshrini Jun 15, 2018
f36230d
added comments and warning
Roshrini Jun 15, 2018
6327847
doc API ref added
Roshrini Jun 18, 2018
83d798c
Merge branch 'onnx_export' of https://github.com/Roshrini/mxnet into …
Roshrini Jun 18, 2018
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
52 changes: 50 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,6 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



=======================================================================================
Other Licenses
=======================================================================================
Expand Down Expand Up @@ -512,3 +510,53 @@
For details, see, 3rdparty/dmlc-core/include/dmlc/concurrentqueue.h

=======================================================================================

11. ONNX Export module
For details, see, python/mxnet/contrib/onnx/_export/LICENSE

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Based on
# https://github.com/NVIDIA/mxnet_to_onnx/blob/master/mx2onnx_converter/#
# Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


2 changes: 2 additions & 0 deletions ci/docker/runtime_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ integrationtest_ubuntu_cpu_onnx() {
pytest tests/python-pytest/onnx/import/mxnet_backend_test.py
pytest tests/python-pytest/onnx/import/onnx_import_test.py
pytest tests/python-pytest/onnx/import/gluon_backend_test.py
pytest tests/python-pytest/onnx/export/onnx_backend_test.py
python tests/python-pytest/onnx/export/mxnet_export_test.py
}

integrationtest_ubuntu_gpu_python() {
Expand Down
2 changes: 2 additions & 0 deletions docs/api/python/contrib/onnx.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This document describes all the ONNX-MXNet APIs.

mxnet.contrib.onnx.import_model
mxnet.contrib.onnx.get_model_metadata
mxnet.contrib.onnx.export_model
```

## ONNX Tutorials
Expand All @@ -46,6 +47,7 @@ This document describes all the ONNX-MXNet APIs.
.. automodule:: mxnet.contrib.onnx
:members: import_model
:members: get_model_metadata
:members: export_model

```

Expand Down
5 changes: 3 additions & 2 deletions python/mxnet/contrib/onnx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
# under the License.
"""Module for ONNX model format support for Apache MXNet."""

from ._import.import_model import import_model, get_model_metadata
from ._import.import_to_gluon import import_to_gluon
from .onnx2mx.import_model import import_model, get_model_metadata
from .onnx2mx.import_to_gluon import import_to_gluon
from .mx2onnx.export_model import export_model
44 changes: 44 additions & 0 deletions python/mxnet/contrib/onnx/mx2onnx/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Based on
# https://github.com/NVIDIA/mxnet_to_onnx/blob/master/mx2onnx_converter/#
# Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 changes: 24 additions & 0 deletions python/mxnet/contrib/onnx/mx2onnx/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# coding: utf-8
"""ONNX Export module"""
from __future__ import absolute_import

from . import export_model
from . import export_onnx
from . import _op_translations
65 changes: 65 additions & 0 deletions python/mxnet/contrib/onnx/mx2onnx/_export_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""export helper functions"""
# coding: utf-8
import os
import logging
import mxnet as mx


def load_module(sym_filepath, params_filepath):
"""Loads the MXNet model file and
returns MXNet symbol and params (weights).

Parameters
----------
json_path : str
Path to the json file
params_path : str
Path to the params file

Returns
-------
sym : MXNet symbol
Model symbol object

params : params object
Model weights including both arg and aux params.
"""
if not (os.path.isfile(sym_filepath) and os.path.isfile(params_filepath)):
raise ValueError("Symbol and params files provided are invalid")
else:
try:
# reads symbol.json file from given path and
# retrieves model prefix and number of epochs
model_name = sym_filepath.rsplit('.', 1)[0].rsplit('-', 1)[0]
params_file_list = params_filepath.rsplit('.', 1)[0].rsplit('-', 1)
# Setting num_epochs to 0 if not present in filename
num_epochs = 0 if len(params_file_list) == 1 else int(params_file_list[1])
except IndexError:
logging.info("Model and params name should be in format: "
"prefix-symbol.json, prefix-epoch.params")
raise

sym, arg_params, aux_params = mx.model.load_checkpoint(model_name, num_epochs)

# Merging arg and aux parameters
params = {}
params.update(arg_params)
params.update(aux_params)

return sym, params
Loading