You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by an...@apache.org on 2020/04/10 05:32:38 UTC

[incubator-tvm] branch master updated: Adding support for TFLite QnnSub operator. (#5230)

This is an automated email from the ASF dual-hosted git repository.

anijain2305 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git


The following commit(s) were added to refs/heads/master by this push:
     new 6ecfaaf  Adding support for TFLite QnnSub operator. (#5230)
6ecfaaf is described below

commit 6ecfaaff1daa40fddaab6d7b17d0563e2b318930
Author: shoubhik <sh...@gmail.com>
AuthorDate: Thu Apr 9 22:32:28 2020 -0700

    Adding support for TFLite QnnSub operator. (#5230)
---
 python/tvm/relay/frontend/tflite.py          | 7 ++++---
 tests/python/frontend/tflite/test_forward.py | 7 +++++--
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/python/tvm/relay/frontend/tflite.py b/python/tvm/relay/frontend/tflite.py
index caf8f92..d489bd3 100644
--- a/python/tvm/relay/frontend/tflite.py
+++ b/python/tvm/relay/frontend/tflite.py
@@ -926,8 +926,7 @@ class OperatorConverter(object):
         """Convert TFLite SUB"""
         # Check if the input tensor is quantized, call QNN op
         if self.is_quantized(op):
-            raise tvm.error.OpNotImplemented(
-                'TFlite quantized SUB operator is not supported yet.')
+            return self._convert_elemwise(_qnn.op.subtract, op)
         return self._convert_elemwise(_op.subtract, op)
 
     def convert_mul(self, op):
@@ -1355,7 +1354,9 @@ class OperatorConverter(object):
         if is_depthwise_conv:
             params['channels'] = int(in_channels)
             params['groups'] = int(input_c)
-            params['kernel_layout'] = 'HWOI'
+            # If number of input channels is 1, treat as normal
+            # convolution.
+            params['kernel_layout'] = 'HWIO' if input_c == 1 else 'HWOI'
         else:
             params['channels'] = int(output_channels)
             params['kernel_layout'] = 'HWIO'
diff --git a/tests/python/frontend/tflite/test_forward.py b/tests/python/frontend/tflite/test_forward.py
index 831b021..db4deb1 100644
--- a/tests/python/frontend/tflite/test_forward.py
+++ b/tests/python/frontend/tflite/test_forward.py
@@ -541,6 +541,8 @@ def test_forward_convolution():
     _test_convolution([4, 17, 17, 124], [1, 1, 124, 1], [1, 1], [1, 1], 'SAME', 'NHWC', True)
     _test_convolution([4, 17, 17, 12], [3, 3, 12, 1], [1, 1], [2, 2], 'VALID', 'NHWC', True)
     _test_convolution([4, 17, 17, 12], [3, 3, 12, 2], [1, 1], [2, 2], 'VALID', 'NHWC', True)
+    # dephtwise convolution with single input channel
+    _test_convolution([1, 76, 64, 1], [9, 5, 1, 96], [1, 1], [1, 1], 'SAME', 'NHWC', True)
 
 
 #######################################################################
@@ -902,9 +904,9 @@ def _test_add(data, fused_activation_function=None, quantized=False, qnn_op=None
 # Subtract
 # --------
 
-def _test_sub(data, fused_activation_function=None):
+def _test_sub(data, fused_activation_function=None, quantized=False, qnn_op=None):
     """ One iteration of subtract """
-    return _test_elemwise(math_ops.subtract, data, fused_activation_function)
+    return _test_elemwise(math_ops.subtract, data, fused_activation_function, quantized, qnn_op)
 #######################################################################
 # Mul
 # ---
@@ -1036,6 +1038,7 @@ def test_all_elemwise():
     _test_forward_elemwise(partial(_test_add, fused_activation_function="RELU"))
     _test_forward_elemwise(partial(_test_add, fused_activation_function="RELU6"))
     _test_forward_elemwise(_test_sub)
+    _test_forward_elemwise_quantized(_test_sub)
     _test_forward_elemwise(partial(_test_sub, fused_activation_function="RELU"))
     _test_forward_elemwise(partial(_test_sub, fused_activation_function="RELU6"))
     _test_forward_elemwise(_test_mul)