siju-samuel commented on a change in pull request #5848: URL: https://github.com/apache/incubator-tvm/pull/5848#discussion_r445531482
########## File path: python/tvm/relay/frontend/tflite.py ########## @@ -258,15 +260,18 @@ def get_tensors(self, tensors_idx_list): assert isinstance(tflite_zero_point, np.ndarray) # Tensor - Per-axis quantization - if tflite_scale.shape != (1,) and tflite_zero_point.shape != (1,): + if tflite_scale.size != 1 and tflite_zero_point.size != 1: scale = tflite_scale - # Ensure that all zero points are identical + # Ensure that all zero points are zeros zero_point = tflite_zero_point - assert all(x == zero_point[0] for x in zero_point) + if not all(x == 0 for x in zero_point): + raise tvm.error.OpAttributeInvalid(\ + "TFLite per-axis quantization restricts all zero points to be" + + " 0, but a non-zero value is observed") zero_point = int(zero_point[0]) # Scalar - Per-tensor quantization - elif tflite_scale.shape == (1,) and tflite_zero_point.shape == (1,): + elif tflite_scale.size == 1 and tflite_zero_point.size == 1: scale = float(tflite_scale[0]) zero_point = int(tflite_zero_point[0]) Review comment: error coud be due to wrong `tflite_zero_point`as well, plz print type of `tflite_zero_point` in else case. ########## File path: python/tvm/relay/frontend/tflite.py ########## @@ -298,11 +303,15 @@ 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() - # Set shape to 1 if the data is a scalar type - if data.shape == (1,) and isinstance(shape, int) and shape == 0: + # 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 Review comment: missed to add # before comment? ########## File path: python/tvm/relay/frontend/tflite.py ########## @@ -258,15 +260,18 @@ def get_tensors(self, tensors_idx_list): assert isinstance(tflite_zero_point, np.ndarray) # Tensor - Per-axis quantization - if tflite_scale.shape != (1,) and tflite_zero_point.shape != (1,): + if tflite_scale.size != 1 and tflite_zero_point.size != 1: scale = tflite_scale - # Ensure that all zero points are identical + # Ensure that all zero points are zeros zero_point = tflite_zero_point - assert all(x == zero_point[0] for x in zero_point) + if not all(x == 0 for x in zero_point): Review comment: Suggestion `if not all(x == 0 for x in zero_point):` >> `if not np.all((zero_point == 0)):` ---------------------------------------------------------------- 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