diff --git a/python/tvm/relay/frontend/tflite.py b/python/tvm/relay/frontend/tflite.py index be18bf622196b..96fcc480ad6e7 100644 --- a/python/tvm/relay/frontend/tflite.py +++ b/python/tvm/relay/frontend/tflite.py @@ -355,7 +355,23 @@ def convert_logistic(self, op): input_tensor = input_tensors[0] in_expr = self.get_expr(input_tensor.tensor_idx) + output_tensors = self.get_output_tensors(op) + assert len(output_tensors) == 1, "output tensors length should be 1" + output_tensor = output_tensors[0] + output_tensor_type = output_tensor.tensor.Type() + output_tensor_type_str = self.get_tensor_type_str(output_tensor_type) + + if input_tensor.qnn_params: + in_expr = _qnn.op.dequantize(data=in_expr, + input_scale=input_tensor.qnn_params['scale'], + input_zero_point=input_tensor.qnn_params['zero_point']) out = _op.sigmoid(in_expr) + if output_tensor.qnn_params: + out = _qnn.op.quantize(data=out, + output_scale=output_tensor.qnn_params['scale'], + output_zero_point=output_tensor.qnn_params['zero_point'], + out_dtype=output_tensor_type_str) + return out def convert_softmax(self, op): diff --git a/tests/python/frontend/tflite/test_forward.py b/tests/python/frontend/tflite/test_forward.py index 12ea429983e8c..c9ac2d73495e1 100644 --- a/tests/python/frontend/tflite/test_forward.py +++ b/tests/python/frontend/tflite/test_forward.py @@ -995,17 +995,24 @@ def test_forward_unpack(): # Logistic # -------- -def _test_logistic(data): +def _test_logistic(data, quantized=False): """ One iteration of LOGISTIC """ with tf.Graph().as_default(): - in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype) - out = math_ops.sigmoid(in_data) - compare_tflite_with_tvm(data, 'Placeholder:0', [in_data], [out]) + in_data = [array_ops.placeholder(shape=data.shape, dtype='float32', name='in_0')] + + if quantized: + inq_data = [tf.quantization.fake_quant_with_min_max_args(in_data[0], min=-100, max=100, name="inq_0")] + out = math_ops.sigmoid(inq_data) + out = tf.quantization.fake_quant_with_min_max_args(out, min=0, max=1, name="out") + compare_tflite_with_tvm(data, 'inq_0:0', inq_data, [out], quantized=True) + else: + out = math_ops.sigmoid(in_data) + compare_tflite_with_tvm(data, 'in_0:0', in_data, [out]) def test_forward_logistic(): """ LOGISTIC """ _test_logistic(np.arange(6.0, dtype=np.float32).reshape((1, 6))) - + _test_logistic(np.array(np.random.uniform(0, 255, (3, 6)), dtype=np.uint8), quantized=True) ####################################################################### # Softmax