Add dynamic_range_quantize to generated op_test infra.
Will add to all op_tests to get complete coverage in subsequent CLs. PiperOrigin-RevId: 316177819 Change-Id: I3fe9d13e7116aa849111a27ab38b4c1815ee82e2
This commit is contained in:
parent
e665a737f9
commit
7270ba4e6d
|
@ -32,6 +32,7 @@ def make_abs_tests(options):
|
|||
test_parameters = [{
|
||||
"input_shape": [[], [1], [2, 3], [1, 1, 1, 1], [1, 3, 4, 3],
|
||||
[3, 15, 14, 3], [3, 1, 2, 4, 6], [2, 2, 3, 4, 5, 6]],
|
||||
"dynamic_range_quantize": [False, True]
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
|
|
|
@ -103,10 +103,9 @@ def toco_convert(options, graph_def, input_tensors, output_tensors, **kwargs):
|
|||
input_arrays = [x[0] for x in input_tensors]
|
||||
data_types = [zip_test_utils.TF_TYPE_INFO[x[2]][1] for x in input_tensors]
|
||||
|
||||
if test_params.get("fully_quantize", False):
|
||||
# Read the input range for the representative dataset from parameters.
|
||||
min_value, max_value = test_params.get("input_range", (-1, 1))
|
||||
|
||||
fully_quantize = test_params.get("fully_quantize", False)
|
||||
dynamic_range_quantize = test_params.get("dynamic_range_quantize", False)
|
||||
if dynamic_range_quantize or fully_quantize:
|
||||
with tempfile.NamedTemporaryFile() as graphdef_file:
|
||||
graphdef_file.write(graph_def_str)
|
||||
graphdef_file.flush()
|
||||
|
@ -115,6 +114,12 @@ def toco_convert(options, graph_def, input_tensors, output_tensors, **kwargs):
|
|||
converter = tf.compat.v1.lite.TFLiteConverter.from_frozen_graph(
|
||||
graphdef_file.name, input_arrays, output_tensors, input_shapes)
|
||||
|
||||
converter.optimizations = [tf.lite.Optimize.DEFAULT]
|
||||
|
||||
if fully_quantize:
|
||||
# Read the input range for the representative dataset from parameters.
|
||||
min_value, max_value = test_params.get("input_range", (-1, 1))
|
||||
|
||||
def representative_dataset(input_tensors):
|
||||
calibration_inputs = []
|
||||
for _, shape, _ in input_tensors:
|
||||
|
|
Loading…
Reference in New Issue