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 2020/03/11 13:45:48 UTC

[GitHub] [incubator-tvm] siju-samuel opened a new pull request #5041: [TFLITE]DepthToSpace and SpaceToDepth support

siju-samuel opened a new pull request #5041: [TFLITE]DepthToSpace and SpaceToDepth support
URL: https://github.com/apache/incubator-tvm/pull/5041
 
 
   @FrozenGene @wyc-ruiker @masahi @yzhliu Please help to review this PR.
   
   Thanks for contributing to TVM!   Please refer to guideline https://docs.tvm.ai/contribute/ for useful information and tips. After the pull request is submitted, please request code reviews from [Reviewers](https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers) by @ them in the pull request thread.
   

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-tvm] wyc-ruiker commented on issue #5041: [TFLITE]DepthToSpace and SpaceToDepth support

Posted by GitBox <gi...@apache.org>.
wyc-ruiker commented on issue #5041: [TFLITE]DepthToSpace and SpaceToDepth support
URL: https://github.com/apache/incubator-tvm/pull/5041#issuecomment-601742509
 
 
   When I run TFLite test scripts in Tensorflow r2.0, there is an error:
   
   >  File "test_forward.py", line 1778, in <module>
   >     test_forward_depthtospace()
   > 
   >   File "test_forward.py", line 1466, in test_forward_depthtospace
   >     _test_depthtospace(np.random.normal(size=[1, 32, 32, 4]).astype("float32"), 2)
   > 
   >   File "test_forward.py", line 1461, in _test_depthtospace
   >     compare_tflite_with_tvm(data, 'Placeholder:0', [in_data], [out])
   > 
   >   File "test_forward.py", line 181, in compare_tflite_with_tvm
   >     tflite_model_buffer = converter.convert()
   > 
   > Some of the operators in the model are not supported by the standard TensorFlow Lite runtime. If those are native TensorFlow operators, you might be able to use the extended runtime by passing --enable_select_tf_ops, or by setting target_ops=TFLITE_BUILTINS,SELECT_TF_OPS when calling tf.lite.TFLiteConverter(). Otherwise, if you have a custom implementation for them you can disable this error with --allow_custom_ops, or by setting allow_custom_ops=True when calling tf.lite.TFLiteConverter(). Here is a list of builtin operators you are using: . Here is a list of operators for which you will need custom implementations: DEPTH_TO_SPACE.
   
   But I don't know why. @siju-samuel Can you help me figure it out?

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-tvm] inadob commented on a change in pull request #5041: [TFLITE]DepthToSpace and SpaceToDepth support

Posted by GitBox <gi...@apache.org>.
inadob commented on a change in pull request #5041: [TFLITE]DepthToSpace and SpaceToDepth support
URL: https://github.com/apache/incubator-tvm/pull/5041#discussion_r391550645
 
 

 ##########
 File path: tests/python/frontend/tflite/test_forward.py
 ##########
 @@ -1420,6 +1420,43 @@ def test_forward_prelu():
     _test_prelu(np.random.uniform(-5, 5, size=(1, 32, 32, 3)).astype("float32"), np.full((3,), 0.2, dtype="float32"))
     _test_prelu(np.random.uniform(-5, 5, size=(1, 32, 32, 3)).astype("float32"), np.full((1, 1, 3), 0.2, dtype="float32"))
 
+#######################################################################
+# DepthToSpace
+# ------------
+
+def _test_depthtospace(data, block_size):
+    """ One iteration of depth_to_space operation with given data and block size """
+
+    with tf.Graph().as_default():
+        in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype)
+        out = array_ops.depth_to_space(in_data, block_size)
+        compare_tflite_with_tvm(data, 'Placeholder:0', [in_data], [out])
+
+
+def test_forward_depthtospace():
+    if package_version.parse(tf.VERSION) >= package_version.parse('1.15.0'):
+        _test_depthtospace(np.random.normal(size=[1, 32, 32, 4]).astype("float32"), 2)
+        _test_depthtospace(np.random.normal(size=[1, 16, 8, 32]).astype("float32"), 4)
+
+#######################################################################
+# SpaceToDepth
+# ------------
+
+def _test_spacetodepth(data, block_size):
+    """ One iteration of space_to_depth operation with given data and block size """
+
+    with tf.Graph().as_default():
+        in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype)
+        out = array_ops.space_to_depth(in_data, block_size)
+        compare_tflite_with_tvm(data, 'Placeholder:0', [in_data], [out])
+
+
+
+def test_forward_spacetodepth():
+    if package_version.parse(tf.VERSION) >= package_version.parse('1.14.0'):
 
 Review comment:
   Why we need this check here

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-tvm] siju-samuel commented on a change in pull request #5041: [TFLITE]DepthToSpace and SpaceToDepth support

Posted by GitBox <gi...@apache.org>.
siju-samuel commented on a change in pull request #5041: [TFLITE]DepthToSpace and SpaceToDepth support
URL: https://github.com/apache/incubator-tvm/pull/5041#discussion_r391604830
 
 

 ##########
 File path: tests/python/frontend/tflite/test_forward.py
 ##########
 @@ -1420,6 +1420,43 @@ def test_forward_prelu():
     _test_prelu(np.random.uniform(-5, 5, size=(1, 32, 32, 3)).astype("float32"), np.full((3,), 0.2, dtype="float32"))
     _test_prelu(np.random.uniform(-5, 5, size=(1, 32, 32, 3)).astype("float32"), np.full((1, 1, 3), 0.2, dtype="float32"))
 
+#######################################################################
+# DepthToSpace
+# ------------
+
+def _test_depthtospace(data, block_size):
+    """ One iteration of depth_to_space operation with given data and block size """
+
+    with tf.Graph().as_default():
+        in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype)
+        out = array_ops.depth_to_space(in_data, block_size)
+        compare_tflite_with_tvm(data, 'Placeholder:0', [in_data], [out])
+
+
+def test_forward_depthtospace():
+    if package_version.parse(tf.VERSION) >= package_version.parse('1.15.0'):
+        _test_depthtospace(np.random.normal(size=[1, 32, 32, 4]).astype("float32"), 2)
+        _test_depthtospace(np.random.normal(size=[1, 16, 8, 32]).astype("float32"), 4)
+
+#######################################################################
+# SpaceToDepth
+# ------------
+
+def _test_spacetodepth(data, block_size):
+    """ One iteration of space_to_depth operation with given data and block size """
+
+    with tf.Graph().as_default():
+        in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype)
+        out = array_ops.space_to_depth(in_data, block_size)
+        compare_tflite_with_tvm(data, 'Placeholder:0', [in_data], [out])
+
+
+
+def test_forward_spacetodepth():
+    if package_version.parse(tf.VERSION) >= package_version.parse('1.14.0'):
 
 Review comment:
   This is not needed, updated. Thanks

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-tvm] wyc-ruiker commented on issue #5041: [TFLITE]DepthToSpace and SpaceToDepth support

Posted by GitBox <gi...@apache.org>.
wyc-ruiker commented on issue #5041: [TFLITE]DepthToSpace and SpaceToDepth support
URL: https://github.com/apache/incubator-tvm/pull/5041#issuecomment-601820301
 
 
   @siju-samuel  OK....But when I run TFLite test scripts in Tensorflow r2.1 and r1.15, there is another error....
   
   > Traceback (most recent call last):
   > 
   >   File "test_forward.py", line 1795, in <module>
   >     test_all_elemwise()
   > 
   >   File "test_forward.py", line 1019, in test_all_elemwise
   >     _test_forward_elemwise(partial(_test_add, fused_activation_function="RELU6"))
   > 
   >   File "test_forward.py", line 995, in _test_forward_elemwise
   >     np.arange(1.0, 7.0, dtype=np.float32).reshape((2, 1, 1, 3))])
   > 
   >   File "test_forward.py", line 881, in _test_add
   >     return _test_elemwise(math_ops.add, data, fused_activation_function, quantized, qnn_op)
   > 
   >   File "test_forward.py", line 835, in _test_elemwise
   >     compare_tflite_with_tvm(data, ['in_0:0', 'in_1:0'], in_data, [out])
   > 
   >   File "test_forward.py", line 181, in compare_tflite_with_tvm
   >     tflite_model_buffer = converter.convert()
   > tensorflow.lite.python.convert.ConverterError: See console for info.
   > 2020-03-20 23:23:09.109906: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 2 operators, 4 arrays (0 quantized)
   > 2020-03-20 23:23:09.110077: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 2 operators, 4 arrays (0 quantized)
   > Fatal Python error: Segmentation fault
   

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-tvm] inadob commented on a change in pull request #5041: [TFLITE]DepthToSpace and SpaceToDepth support

Posted by GitBox <gi...@apache.org>.
inadob commented on a change in pull request #5041: [TFLITE]DepthToSpace and SpaceToDepth support
URL: https://github.com/apache/incubator-tvm/pull/5041#discussion_r391560660
 
 

 ##########
 File path: tests/python/frontend/tflite/test_forward.py
 ##########
 @@ -1420,6 +1420,43 @@ def test_forward_prelu():
     _test_prelu(np.random.uniform(-5, 5, size=(1, 32, 32, 3)).astype("float32"), np.full((3,), 0.2, dtype="float32"))
     _test_prelu(np.random.uniform(-5, 5, size=(1, 32, 32, 3)).astype("float32"), np.full((1, 1, 3), 0.2, dtype="float32"))
 
+#######################################################################
+# DepthToSpace
+# ------------
+
+def _test_depthtospace(data, block_size):
+    """ One iteration of depth_to_space operation with given data and block size """
+
+    with tf.Graph().as_default():
+        in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype)
+        out = array_ops.depth_to_space(in_data, block_size)
+        compare_tflite_with_tvm(data, 'Placeholder:0', [in_data], [out])
+
+
+def test_forward_depthtospace():
+    if package_version.parse(tf.VERSION) >= package_version.parse('1.15.0'):
 
 Review comment:
   I think it will be nice to add a comment to say the check is done because of the fbs schema. Some of the other checks are done because of operators changing their behaviour between versions, so it's a good idea to distinguish them from those that were just added later in the schema.

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-tvm] inadob commented on a change in pull request #5041: [TFLITE]DepthToSpace and SpaceToDepth support

Posted by GitBox <gi...@apache.org>.
inadob commented on a change in pull request #5041: [TFLITE]DepthToSpace and SpaceToDepth support
URL: https://github.com/apache/incubator-tvm/pull/5041#discussion_r391511018
 
 

 ##########
 File path: tests/python/frontend/tflite/test_forward.py
 ##########
 @@ -1420,6 +1420,43 @@ def test_forward_prelu():
     _test_prelu(np.random.uniform(-5, 5, size=(1, 32, 32, 3)).astype("float32"), np.full((3,), 0.2, dtype="float32"))
     _test_prelu(np.random.uniform(-5, 5, size=(1, 32, 32, 3)).astype("float32"), np.full((1, 1, 3), 0.2, dtype="float32"))
 
+#######################################################################
+# DepthToSpace
+# ------------
+
+def _test_depthtospace(data, block_size):
+    """ One iteration of depth_to_space operation with given data and block size """
+
+    with tf.Graph().as_default():
+        in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype)
+        out = array_ops.depth_to_space(in_data, block_size)
+        compare_tflite_with_tvm(data, 'Placeholder:0', [in_data], [out])
+
 
 Review comment:
   1 redundant line

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-tvm] tqchen merged pull request #5041: [TFLITE]DepthToSpace and SpaceToDepth support

Posted by GitBox <gi...@apache.org>.
tqchen merged pull request #5041: [TFLITE]DepthToSpace and SpaceToDepth support
URL: https://github.com/apache/incubator-tvm/pull/5041
 
 
   

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-tvm] tqchen commented on issue #5041: [TFLITE]DepthToSpace and SpaceToDepth support

Posted by GitBox <gi...@apache.org>.
tqchen commented on issue #5041: [TFLITE]DepthToSpace and SpaceToDepth support
URL: https://github.com/apache/incubator-tvm/pull/5041#issuecomment-599731942
 
 
   Thanks @inadob @FrozenGene !

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-tvm] inadob commented on a change in pull request #5041: [TFLITE]DepthToSpace and SpaceToDepth support

Posted by GitBox <gi...@apache.org>.
inadob commented on a change in pull request #5041: [TFLITE]DepthToSpace and SpaceToDepth support
URL: https://github.com/apache/incubator-tvm/pull/5041#discussion_r391510611
 
 

 ##########
 File path: tests/python/frontend/tflite/test_forward.py
 ##########
 @@ -1420,6 +1420,43 @@ def test_forward_prelu():
     _test_prelu(np.random.uniform(-5, 5, size=(1, 32, 32, 3)).astype("float32"), np.full((3,), 0.2, dtype="float32"))
     _test_prelu(np.random.uniform(-5, 5, size=(1, 32, 32, 3)).astype("float32"), np.full((1, 1, 3), 0.2, dtype="float32"))
 
+#######################################################################
+# DepthToSpace
+# ------------
+
+def _test_depthtospace(data, block_size):
+    """ One iteration of depth_to_space operation with given data and block size """
+
+    with tf.Graph().as_default():
+        in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype)
+        out = array_ops.depth_to_space(in_data, block_size)
+        compare_tflite_with_tvm(data, 'Placeholder:0', [in_data], [out])
+
+
+def test_forward_depthtospace():
+    if package_version.parse(tf.VERSION) >= package_version.parse('1.15.0'):
+        _test_depthtospace(np.random.normal(size=[1, 32, 32, 4]).astype("float32"), 2)
+        _test_depthtospace(np.random.normal(size=[1, 16, 8, 32]).astype("float32"), 4)
+
+#######################################################################
+# SpaceToDepth
+# ------------
+
+def _test_spacetodepth(data, block_size):
+    """ One iteration of space_to_depth operation with given data and block size """
+
+    with tf.Graph().as_default():
+        in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype)
+        out = array_ops.space_to_depth(in_data, block_size)
+        compare_tflite_with_tvm(data, 'Placeholder:0', [in_data], [out])
+
 
 Review comment:
   please, remove the redundant blank lines

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-tvm] siju-samuel commented on issue #5041: [TFLITE]DepthToSpace and SpaceToDepth support

Posted by GitBox <gi...@apache.org>.
siju-samuel commented on issue #5041: [TFLITE]DepthToSpace and SpaceToDepth support
URL: https://github.com/apache/incubator-tvm/pull/5041#issuecomment-601780892
 
 
   @wyc-ruiker DEPTH_TO_SPACE is not there in 2.0 schema, but its there in tf1.15 and tf 2.1 schema

----------------------------------------------------------------
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


With regards,
Apache Git Services