Skip to content

Commit

Permalink
* CI Lint fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
srkreddy1238 committed Feb 28, 2021
1 parent 6df7fc2 commit 413a1d0
Show file tree
Hide file tree
Showing 6 changed files with 1,743 additions and 942 deletions.
7 changes: 1 addition & 6 deletions python/tvm/relay/frontend/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@
# pylint: disable=import-self, invalid-name, unused-argument, too-many-lines, len-as-condition, broad-except
# pylint: disable=import-outside-toplevel, redefined-builtin
"""TF: Tensorflow frontend."""
import warnings
from collections import defaultdict

# Numpy support
import numpy as np
import tvm

from .tensorflow_parser import TFParser
from .tf import tf_parser_v1 as v1

Expand All @@ -38,6 +32,7 @@
"Merge",
]


def from_tensorflow(tf_input, layout="NHWC", shape=None, outputs=None):
"""Load tensorflow graph which is a python tensorflow graph object into relay.
The companion parameters will be handled automatically.
Expand Down
18 changes: 9 additions & 9 deletions python/tvm/relay/frontend/tensorflow_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ def _load_ckpt(self):
def _build_signature_def(self, frozen_graph, input_nodes, output_nodes):
try:
from tensorflow.core.protobuf import meta_graph_pb2
except ImportError as e:
raise ImportError("Unable to import tensorflow which is required {}".format(e))
except ImportError as err:
raise ImportError("Unable to import tensorflow which is required {}".format(err))
signature = meta_graph_pb2.SignatureDef()
for input_tensor in input_nodes:
op_name = input_tensor.name.split(":")[0]
Expand Down Expand Up @@ -198,18 +198,16 @@ def _build_signature_def(self, frozen_graph, input_nodes, output_nodes):
signature.outputs[output_tensor].name = output_tensor
return signature


def _run_grappler(self, config, graph_def, graph, signature_def):
try:
from tensorflow.python.grappler import tf_optimizer
from tensorflow.python.training.saver import export_meta_graph
except ImportError as e:
raise ImportError("Unable to import tensorflow which is required {}".format(e))
except ImportError as err:
raise ImportError("Unable to import tensorflow which is required {}".format(err))
meta_graph = export_meta_graph(graph_def=graph_def, graph=graph)
meta_graph.signature_def["not_used_key"].CopyFrom(signature_def)
return tf_optimizer.OptimizeGraph(config, meta_graph)


def parse(self):
"""
Parse tensorflow models: checkpoints, saved models, and single frozen pb file.
Expand All @@ -227,11 +225,13 @@ def parse(self):
try:
from tensorflow.python.framework import convert_to_constants
from tensorflow.core.protobuf import config_pb2
except ImportError as e:
raise ImportError("Unable to import tensorflow which is required {}".format(e))
except ImportError as err:
raise ImportError("Unable to import tensorflow which is required {}".format(err))
concrete_func = self._tf_input
graph = convert_to_constants.convert_variables_to_constants_v2(concrete_func).graph
signature = self._build_signature_def(graph, concrete_func.inputs, concrete_func.outputs)
signature = self._build_signature_def(
graph, concrete_func.inputs, concrete_func.outputs
)
graph_def = graph.as_graph_def()

# Some optimization
Expand Down
Loading

0 comments on commit 413a1d0

Please sign in to comment.