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

Function _check_tf1_flags

tensorflow/lite/python/tflite_convert.py:226–286  ·  view source on GitHub ↗

Checks the parsed and unparsed flags to ensure they are valid in 1.X. Raises an error if previously support unparsed flags are found. Raises an error for parsed flags that don't meet the required conditions. Args: flags: argparse.Namespace object containing TFLite flags. unparsed: Li

(flags, unparsed)

Source from the content-addressed store, hash-verified

224
225
226def _check_tf1_flags(flags, unparsed):
227 """Checks the parsed and unparsed flags to ensure they are valid in 1.X.
228
229 Raises an error if previously support unparsed flags are found. Raises an
230 error for parsed flags that don't meet the required conditions.
231
232 Args:
233 flags: argparse.Namespace object containing TFLite flags.
234 unparsed: List of unparsed flags.
235
236 Raises:
237 ValueError: Invalid flags.
238 """
239
240 # Check unparsed flags for common mistakes based on previous TOCO.
241 def _get_message_unparsed(flag, orig_flag, new_flag):
242 if flag.startswith(orig_flag):
243 return "\n Use {0} instead of {1}".format(new_flag, orig_flag)
244 return ""
245
246 if unparsed:
247 output = ""
248 for flag in unparsed:
249 output += _get_message_unparsed(flag, "--input_file", "--graph_def_file")
250 output += _get_message_unparsed(flag, "--savedmodel_directory",
251 "--saved_model_dir")
252 output += _get_message_unparsed(flag, "--std_value", "--std_dev_values")
253 output += _get_message_unparsed(flag, "--batch_size", "--input_shapes")
254 output += _get_message_unparsed(flag, "--dump_graphviz",
255 "--dump_graphviz_dir")
256 if output:
257 raise ValueError(output)
258
259 # Check that flags are valid.
260 if flags.graph_def_file and (not flags.input_arrays or
261 not flags.output_arrays):
262 raise ValueError("--input_arrays and --output_arrays are required with "
263 "--graph_def_file")
264
265 if flags.input_shapes:
266 if not flags.input_arrays:
267 raise ValueError("--input_shapes must be used with --input_arrays")
268 if flags.input_shapes.count(":") != flags.input_arrays.count(","):
269 raise ValueError("--input_shapes and --input_arrays must have the same "
270 "number of items")
271
272 if flags.std_dev_values or flags.mean_values:
273 if bool(flags.std_dev_values) != bool(flags.mean_values):
274 raise ValueError("--std_dev_values and --mean_values must be used "
275 "together")
276 if flags.std_dev_values.count(",") != flags.mean_values.count(","):
277 raise ValueError("--std_dev_values, --mean_values must have the same "
278 "number of items")
279
280 if (flags.default_ranges_min is None) != (flags.default_ranges_max is None):
281 raise ValueError("--default_ranges_min and --default_ranges_max must be "
282 "used together")
283

Callers 1

run_mainFunction · 0.85

Calls 2

_get_message_unparsedFunction · 0.85
countMethod · 0.45

Tested by

no test coverage detected