MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _convert_tf1_model

Function _convert_tf1_model

tensorflow/lite/python/tflite_convert.py:114–201  ·  view source on GitHub ↗

Calls function to convert the TensorFlow 1.X model into a TFLite model. Args: flags: argparse.Namespace object. Raises: ValueError: Invalid flags.

(flags)

Source from the content-addressed store, hash-verified

112
113
114def _convert_tf1_model(flags):
115 """Calls function to convert the TensorFlow 1.X model into a TFLite model.
116
117 Args:
118 flags: argparse.Namespace object.
119
120 Raises:
121 ValueError: Invalid flags.
122 """
123 # Create converter.
124 converter = _get_toco_converter(flags)
125 if flags.inference_type:
126 converter.inference_type = _parse_inference_type(flags.inference_type,
127 "inference_type")
128 if flags.inference_input_type:
129 converter.inference_input_type = _parse_inference_type(
130 flags.inference_input_type, "inference_input_type")
131 if flags.output_format:
132 converter.output_format = _toco_flags_pb2.FileFormat.Value(
133 flags.output_format)
134
135 if flags.mean_values and flags.std_dev_values:
136 input_arrays = converter.get_input_arrays()
137 std_dev_values = _parse_array(flags.std_dev_values, type_fn=float)
138
139 # In quantized inference, mean_value has to be integer so that the real
140 # value 0.0 is exactly representable.
141 if converter.inference_type == lite_constants.QUANTIZED_UINT8:
142 mean_values = _parse_array(flags.mean_values, type_fn=int)
143 else:
144 mean_values = _parse_array(flags.mean_values, type_fn=float)
145 quant_stats = list(zip(mean_values, std_dev_values))
146 if ((not flags.input_arrays and len(input_arrays) > 1) or
147 (len(input_arrays) != len(quant_stats))):
148 raise ValueError("Mismatching --input_arrays, --std_dev_values, and "
149 "--mean_values. The flags must have the same number of "
150 "items. The current input arrays are '{0}'. "
151 "--input_arrays must be present when specifying "
152 "--std_dev_values and --mean_values with multiple input "
153 "tensors in order to map between names and "
154 "values.".format(",".join(input_arrays)))
155 converter.quantized_input_stats = dict(zip(input_arrays, quant_stats))
156 if (flags.default_ranges_min is not None) and (flags.default_ranges_max is
157 not None):
158 converter.default_ranges_stats = (flags.default_ranges_min,
159 flags.default_ranges_max)
160
161 if flags.drop_control_dependency:
162 converter.drop_control_dependency = flags.drop_control_dependency
163 if flags.reorder_across_fake_quant:
164 converter.reorder_across_fake_quant = flags.reorder_across_fake_quant
165 if flags.change_concat_input_ranges:
166 converter.change_concat_input_ranges = (
167 flags.change_concat_input_ranges == "TRUE")
168
169 if flags.allow_custom_ops:
170 converter.allow_custom_ops = flags.allow_custom_ops
171 if flags.target_ops:

Callers 1

run_mainFunction · 0.85

Calls 12

_get_toco_converterFunction · 0.85
_parse_inference_typeFunction · 0.85
_parse_arrayFunction · 0.85
get_input_arraysMethod · 0.80
get_optionsMethod · 0.80
ValueMethod · 0.45
formatMethod · 0.45
joinMethod · 0.45
splitMethod · 0.45
addMethod · 0.45
convertMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected