From 0e3720c9aba21c8572f26f67f86c81821bf353d6 Mon Sep 17 00:00:00 2001 From: Deyu Huang Date: Thu, 31 Mar 2022 15:02:19 +0800 Subject: [PATCH] Add commit value to onnx file and clean up part of code (#1897) * add commit value to onnx file, remove expired code and add License in generating version.py Signed-off-by: Deyu Huang Co-authored-by: Guenther Schmuelling * change onnx repo master to main Signed-off-by: Deyu Huang * fix comments Signed-off-by: Deyu Huang Co-authored-by: Guenther Schmuelling --- setup.py | 3 ++- .../model_source/densenet_1/densenet_1.py | 3 --- .../model_source/densenet_1/subpixel.py | 2 -- tests/test_onnx_shape_inference.py | 2 +- tf2onnx/__init__.py | 3 +-- tf2onnx/graph.py | 13 +++++++------ tf2onnx/optimizer/const_fold_optimizer.py | 2 +- tf2onnx/optimizer/loop_optimizer.py | 2 +- tf2onnx/version.py | 3 ++- tools/aggregate-patterns.py | 2 +- tools/graphtool.py | 2 +- tools/profile_conversion_time.py | 2 +- 12 files changed, 18 insertions(+), 21 deletions(-) diff --git a/setup.py b/setup.py index e13df27cb..ae654b152 100644 --- a/setup.py +++ b/setup.py @@ -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())))) diff --git a/tests/keras2onnx_applications/model_source/densenet_1/densenet_1.py b/tests/keras2onnx_applications/model_source/densenet_1/densenet_1.py index f8e8d9b56..de4998e92 100644 --- a/tests/keras2onnx_applications/model_source/densenet_1/densenet_1.py +++ b/tests/keras2onnx_applications/model_source/densenet_1/densenet_1.py @@ -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 diff --git a/tests/keras2onnx_applications/model_source/densenet_1/subpixel.py b/tests/keras2onnx_applications/model_source/densenet_1/subpixel.py index 610079bde..a771621a9 100644 --- a/tests/keras2onnx_applications/model_source/densenet_1/subpixel.py +++ b/tests/keras2onnx_applications/model_source/densenet_1/subpixel.py @@ -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 diff --git a/tests/test_onnx_shape_inference.py b/tests/test_onnx_shape_inference.py index 4e4efa5df..6272fa2ff 100644 --- a/tests/test_onnx_shape_inference.py +++ b/tests/test_onnx_shape_inference.py @@ -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): diff --git a/tf2onnx/__init__.py b/tf2onnx/__init__.py index 1bc667bd0..f1bdd6508 100644 --- a/tf2onnx/__init__.py +++ b/tf2onnx/__init__.py @@ -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 diff --git a/tf2onnx/graph.py b/tf2onnx/graph.py index e6b4f5657..18a16269b 100644 --- a/tf2onnx/graph.py +++ b/tf2onnx/graph.py @@ -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 @@ -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] + } if "opset_imports" not in kwargs: opsets = [helper.make_opsetid(constants.ONNX_DOMAIN, self._opset)] opsets.append(constants.AI_ONNX_ML_OPSET) @@ -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: @@ -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 diff --git a/tf2onnx/optimizer/const_fold_optimizer.py b/tf2onnx/optimizer/const_fold_optimizer.py index 5e0e4f769..cc806f4a0 100644 --- a/tf2onnx/optimizer/const_fold_optimizer.py +++ b/tf2onnx/optimizer/const_fold_optimizer.py @@ -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: diff --git a/tf2onnx/optimizer/loop_optimizer.py b/tf2onnx/optimizer/loop_optimizer.py index 8936df5a2..b028893fb 100644 --- a/tf2onnx/optimizer/loop_optimizer.py +++ b/tf2onnx/optimizer/loop_optimizer.py @@ -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__() diff --git a/tf2onnx/version.py b/tf2onnx/version.py index ff7beba94..f799c9af3 100644 --- a/tf2onnx/version.py +++ b/tf2onnx/version.py @@ -1,4 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 + version = '1.10.0' -git_version = '219e00c073f6e73fba7335630dcf1f96cc82c983' +git_version = '0065af6273eac0e911a0e75eab1cdf6be1c9ac7b' diff --git a/tools/aggregate-patterns.py b/tools/aggregate-patterns.py index a0e882dc9..df0e771e4 100644 --- a/tools/aggregate-patterns.py +++ b/tools/aggregate-patterns.py @@ -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 diff --git a/tools/graphtool.py b/tools/graphtool.py index 5083ecaed..c71daa98f 100644 --- a/tools/graphtool.py +++ b/tools/graphtool.py @@ -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 diff --git a/tools/profile_conversion_time.py b/tools/profile_conversion_time.py index 4e72b9496..0590937ae 100644 --- a/tools/profile_conversion_time.py +++ b/tools/profile_conversion_time.py @@ -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