Skip to content

Commit

Permalink
Helper functions for quantize and dequantize.
Browse files Browse the repository at this point in the history
  • Loading branch information
inadob committed Jan 31, 2020
1 parent 041ecc8 commit 70dfaf6
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions python/tvm/relay/frontend/tflite.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,23 @@ def is_quantized(self, op):
first_tensor = input_tensors[0]
return first_tensor.qnn_params is not None

def quantize(self, expr, tensor_to_quantize):
""" Helper function to quantize a tensor with Relay """
tensor_type = tensor_to_quantize.tensor.Type()
tensor_type_str = self.get_tensor_type_str(tensor_type)
quantized = _qnn.op.quantize(data=expr,
output_scale=tensor_to_quantize.qnn_params['scale'],
output_zero_point=tensor_to_quantize.qnn_params['zero_point'],
out_dtype=tensor_type_str)
return quantized

def dequantize(self, expr, tensor):
""" Helper function to dequantize a tensor with Relay """
dequantized = _qnn.op.dequantize(data=expr,
input_scale=tensor.qnn_params['scale'],
input_zero_point=tensor.qnn_params['zero_point'])
return dequantized

def convert_conv2d(self, op):
"""Convert TFLite conv2d"""
return self.convert_conv(op, "conv2d")
Expand Down

0 comments on commit 70dfaf6

Please sign in to comment.