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/07/01 19:29:44 UTC

[GitHub] [incubator-tvm] d-smirnov commented on a change in pull request #5848: [TFLite] QNN support for TFLite 2.1.0 quantized models

d-smirnov commented on a change in pull request #5848:
URL: https://github.com/apache/incubator-tvm/pull/5848#discussion_r448572493



##########
File path: python/tvm/relay/frontend/tflite.py
##########
@@ -263,21 +305,29 @@ def get_tensor_value(self, tensor_wrapper):
         except ImportError:
             raise ImportError("The tflite package must be installed")
 
+        # Read the data from the buffer. Also extract the shape.
+        # The shape is used later to reshape the data.
+        data = tensor_wrapper.buffer.DataAsNumpy()
+        shape = tensor_wrapper.tensor.ShapeAsNumpy()
+
+        # When TFLite buffer is of size 1 (scalar), then TFLite tensor shape is set to 0.
+        # Therefore, we set the shape to 1 for numpy reshape to work.  Set shape to 1 if the data is
+        # a scalar type
+        if data.size == 1 and isinstance(shape, int) and shape == 0:
+            shape = (1,)
+
+        if tensor_wrapper.tensor.Type() == TensorType.INT8:

Review comment:
       Please consider following change as well:
   ```
       def has_same_qnn_params(self, lhs_tensor, rhs_tensor):
           lhs_scale = lhs_tensor.qnn_params['scale']
           rhs_scale = rhs_tensor.qnn_params['scale']
           lhs_zero_point = lhs_tensor.qnn_params['zero_point']
           rhs_zero_point = rhs_tensor.qnn_params['zero_point']
           return np.allclose( lhs_scale.data.asnumpy(), rhs_scale.data.asnumpy(), rtol=1e-5, atol=1e-5 ) and \
                  np.allclose( lhs_zero_point.data.asnumpy(), rhs_zero_point.data.asnumpy(), rtol=1e-5, atol=1e-5 )
   
   
   ```




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