siju-samuel commented on a change in pull request #6217:
URL: https://github.com/apache/incubator-tvm/pull/6217#discussion_r466170310



##########
File path: tests/python/frontend/tflite/test_forward.py
##########
@@ -352,21 +352,47 @@ def test_forward_split():
 # slice
 # -----
 
-def _test_slice(data, begin, size):
+def _test_slice(data, begin, size, quantized=False):
     """ One iteration of SLICE """
-    with tf.Graph().as_default():
-        in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype)
-        out = array_ops.slice(in_data, begin, size)
-        compare_tflite_with_tvm(data, 'Placeholder:0', [in_data], [out])
+    if quantized:
+        with tf.Graph().as_default():
+            data_array = np.random.uniform(0, 255, data.shape).astype('uint8')
+            in_data = array_ops.placeholder(shape=data.shape, 
dtype=data.dtype, name="in_data")
+            # Ensure that min/max for inputs and outputs are same
+            min_value = -100
+            max_value = 100
+            inq_data = tf.quantization.fake_quant_with_min_max_args(in_data, 
min=min_value,
+                                                                    
max=max_value, name='inq_data')
+            out = array_ops.slice(inq_data, begin, size)
+            out = tf.quantization.fake_quant_with_min_max_args(out, 
min=min_value,
+                                                               max=max_value, 
name="out")
+
+            # Set the input quantization range
+            input_range = {'in_data': (min_value, max_value)} if quantized 
else None
+
+            # Compare
+            compare_tflite_with_tvm(data_array, 'in_data', [in_data], [out], 
quantized=quantized, input_range=input_range)
+
+    else:
+        with tf.Graph().as_default():
+            in_data = array_ops.placeholder(shape=data.shape, 
dtype=data.dtype, name="in_data")
+            out = array_ops.slice(in_data, begin, size)
+            input_range = {'in_data': (-100, 100)} if quantized else None
+            compare_tflite_with_tvm([data], ['in_data:0'], [in_data], [out],

Review comment:
       This 2 common statements, put outside if-else block.
   

##########
File path: python/tvm/relay/frontend/tflite.py
##########
@@ -2088,6 +2088,14 @@ def convert_slice(self, op):
         input_tensor = input_tensors[0]
         in_expr = self.get_expr(input_tensor.tensor_idx)
 
+        # If the tensors are quantized, ensure that input/output qnn params 
are same.
+        if input_tensor.qnn_params:
+            output_tensors = self.get_output_tensors(op)
+            assert len(output_tensors) == 1, "There should be only 1 output 
tensor"
+            output_tensor = output_tensors[0]
+            assert self.has_same_qnn_params(input_tensor, output_tensor), \
+                    "TFLite reshape requires input and output scale and zero 
points to be equal"

Review comment:
       Tflite reshape -> Tflite slice




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to