You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/02/23 01:58:15 UTC

[GitHub] [tvm] wx3000 commented on a change in pull request #7498: [TENSORFLOW] Tensorflow 2.x support

wx3000 commented on a change in pull request #7498:
URL: https://github.com/apache/tvm/pull/7498#discussion_r580712245



##########
File path: python/tvm/relay/frontend/tensorflow.py
##########
@@ -3682,6 +3729,30 @@ def from_tensorflow(graph, layout="NHWC", shape=None, outputs=None):
     params : dict of str to tvm.nd.NDArray
         Dict of converted parameters stored in tvm.nd.NDArray format
     """
+    from tensorflow.python.eager.function import ConcreteFunction
+
+    if isinstance(graph, ConcreteFunction):

Review comment:
       would it be better if we create a wrapper over from_tensorflow_concrete_function() instead of overloading the parameter "graph" to be either GraphDef or ConcreteFunction? 
   
   Another question: Is ConcreteFunction the right entry point? Why not start from the saved_model format? When TVM is used to compile a model for inference, it starts from a saved_model. This way there is no need to use _build_signature_def in order to optimize the graph. Maybe _build_signature_def can be part of the test utility code.

##########
File path: python/tvm/relay/frontend/tensorflow.py
##########
@@ -3682,6 +3729,30 @@ def from_tensorflow(graph, layout="NHWC", shape=None, outputs=None):
     params : dict of str to tvm.nd.NDArray
         Dict of converted parameters stored in tvm.nd.NDArray format
     """
+    from tensorflow.python.eager.function import ConcreteFunction
+
+    if isinstance(graph, ConcreteFunction):
+        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))
+        concrete_func = graph
+        graph = convert_to_constants.convert_variables_to_constants_v2(concrete_func).graph
+        signature = _build_signature_def(graph, concrete_func.inputs, concrete_func.outputs)
+        graph_def = graph.as_graph_def()
+
+        # Some optimization
+        config = config_pb2.ConfigProto()
+        rewriter_config = config.graph_options.rewrite_options
+        rewriter_config.optimizers[:] = [
+            "debug_stripper",
+            "arithmetic",
+            "dependency",
+            "arithmetic",

Review comment:
       typo: duplicate of line 3750




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org