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

Add commit value to onnx file and clean up some code #1897

Merged
merged 3 commits into from
Mar 31, 2022
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
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ def finalize_options(self):
pass

def run(self):
alv2_license = '# SPDX-License-Identifier: Apache-2.0\n\n'
with open(os.path.join(SRC_DIR, 'version.py'), 'w') as f:
f.write(dedent('''
f.write(alv2_license + dedent('''
version = '{version}'
git_version = '{git_version}'
'''.format(**dict(VersionInfo._asdict()))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
- [Densely Connected Convolutional Networks](https://arxiv.org/pdf/1608.06993.pdf)
- [The One Hundred Layers Tiramisu: Fully Convolutional DenseNets for Semantic Segmentation](https://arxiv.org/pdf/1611.09326.pdf)
'''
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division

import warnings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# From https://github.com/titu1994/DenseNet/blob/master/subpixel.py
# Modifications Copyright (c) Microsoft.

from __future__ import absolute_import

from mock_keras2onnx.proto import keras
from keras import backend as K
from keras.engine import Layer
Expand Down
2 changes: 1 addition & 1 deletion tests/test_onnx_shape_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ONNXShapeInferenceTests(Tf2OnnxBackendTestBase):
"""
Test shape inference, it's just a subset of all cases that can be inferred shape.
For more information, please refer to onnx shape inference test:
https://github.com/onnx/onnx/blob/master/onnx/test/shape_inference_test.py
https://github.com/onnx/onnx/blob/main/onnx/test/shape_inference_test.py
"""

def _run_test_case(self, graph, feed_dict):
Expand Down
3 changes: 1 addition & 2 deletions tf2onnx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"tfonnx", "shape_inference", "schemas", "tf_utils", "tf_loader", "convert"]

import onnx
from .version import version as __version__
from .version import git_version, version as __version__
from . import verbose_logging as logging
from tf2onnx import tfonnx, utils, graph, graph_builder, graph_matcher, shape_inference, schemas, convert # pylint: disable=wrong-import-order
#from tf2onnx import tf_utils, tf_loader
13 changes: 7 additions & 6 deletions tf2onnx/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import numpy as np

from onnx import helper, numpy_helper, shape_inference, AttributeProto, TensorProto
from tf2onnx import utils, __version__
from tf2onnx import utils, __version__, git_version
from tf2onnx.utils import make_name, port_name, find_opset
from tf2onnx import optimizer
from tf2onnx.schemas import get_schema, infer_onnx_shape_dtype
Expand Down Expand Up @@ -1189,9 +1189,10 @@ def make_model(self, graph_doc, optimize=False, graph_name="tf2onnx", external_t
graph = self.make_graph(graph_doc, graph_name, external_tensor_storage)

if "producer_name" not in kwargs:
kwargs = {"producer_name": "tf2onnx",
"producer_version": __version__}

kwargs = {
"producer_name": "tf2onnx",
"producer_version": __version__ + " " + git_version[:6]
hwangdeyu marked this conversation as resolved.
Show resolved Hide resolved
}
if "opset_imports" not in kwargs:
opsets = [helper.make_opsetid(constants.ONNX_DOMAIN, self._opset)]
opsets.append(constants.AI_ONNX_ML_OPSET)
Expand Down Expand Up @@ -1605,7 +1606,7 @@ def safe_remove_nodes(self, to_delete):
self.remove_node(n.name)

def is_safe_to_remove_nodes(self, to_delete, outputs_to_ignore=None):
"""Returns true if the outputs of all the nodes in to_delete have no third-party nodes consuming them"""
"""Returns true if the outputs of all the nodes in to_delete have no third-party nodes consuming them."""
delete_set = set(to_delete)
outputs_to_ignore_set = set(outputs_to_ignore or [])
for n in delete_set:
Expand Down Expand Up @@ -1660,7 +1661,7 @@ def optimize_model_proto(onnx_model_proto, catch_errors=True, return_graph=False

@staticmethod
def get_onnx_model_properties(onnx_model_proto):
"""Get ModelProto properties"""
"""Get ModelProto properties."""
kwargs = {}
if onnx_model_proto.HasField('ir_version'):
kwargs["ir_version"] = onnx_model_proto.ir_version
Expand Down
2 changes: 1 addition & 1 deletion tf2onnx/optimizer/const_fold_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _fold_unsqueeze(node, graph):
dims_out = len(shape_in) + len(axes)
axes = [i if i >= 0 else i + dims_out for i in axes]
# calculate the shape of output accroding to onnx Unsqueeze's spec
# https://github.com/onnx/onnx/blob/master/docs/Operators.md#Unsqueeze
# https://github.com/onnx/onnx/blob/main/docs/Operators.md#Unsqueeze
shape_in = iter(shape_in)
shape_out = [None] * dims_out
for ind in axes:
Expand Down
2 changes: 1 addition & 1 deletion tf2onnx/optimizer/loop_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class LoopOptimizer(GraphOptimizerBase):
"""Loop Optimizer."""

# a lot of terms used here come from loop's onnx spec
# https://github.com/onnx/onnx/blob/master/docs/Operators.md#Loop
# https://github.com/onnx/onnx/blob/main/docs/Operators.md#Loop
def __init__(self): # pylint: disable=useless-super-delegation
super(LoopOptimizer, self).__init__()

Expand Down
3 changes: 2 additions & 1 deletion tf2onnx/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# SPDX-License-Identifier: Apache-2.0


version = '1.10.0'
git_version = '219e00c073f6e73fba7335630dcf1f96cc82c983'
git_version = '0065af6273eac0e911a0e75eab1cdf6be1c9ac7b'
2 changes: 1 addition & 1 deletion tools/aggregate-patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def get_args():
parser.add_argument("--fold", action="store_true", help="fold smaller sub graphs")
parser.add_argument("--max-nodes", type=int, default=6, help="number of max nodes in a pattern")
parser.add_argument("--min-frequency", type=int, default=2, help="show patterns number seen at least this")
parser.add_argument("infile", nargs="*", help='event files')
parser.add_argument("--infile", nargs="*", help="event files")
args = parser.parse_args()
return args

Expand Down
2 changes: 1 addition & 1 deletion tools/graphtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

def get_args():
parser = argparse.ArgumentParser()
parser.add_argument("infile", nargs="*", help='event files')
parser.add_argument("infile", nargs="*", help="event files")
args = parser.parse_args()
return args

Expand Down
2 changes: 1 addition & 1 deletion tools/profile_conversion_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def profile(profiler="none", name="MobileNet", show_all=False):
print("create(%r, %r)" % (profiler, name))
graph_def, model = create(name)
print("profile(%r, %r)" % (profiler, name))
if profiler == 'none':
if profiler == "none":
convert(graph_def, model)
elif profiler == "spy":
# py-spy record -r 10 -o profile.svg -- python conversion_time.py spy
Expand Down