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

Function build_example

tensorflow/lite/testing/generate_examples_lib.py:461–550  ·  view source on GitHub ↗

Build the model with parameter values set in param_dict_real. Args: label: Label of the model (i.e. the filename in the zip). param_dict_real: Parameter dictionary (arguments to the factories make_graph and make_test_inputs) Returns: (tflite

(label, param_dict_real)

Source from the content-addressed store, hash-verified

459 return input_values, output_values
460
461 def build_example(label, param_dict_real):
462 """Build the model with parameter values set in param_dict_real.
463
464 Args:
465 label: Label of the model (i.e. the filename in the zip).
466 param_dict_real: Parameter dictionary (arguments to the factories
467 make_graph and make_test_inputs)
468 Returns:
469 (tflite_model_binary, report) where tflite_model_binary is the
470 serialized flatbuffer as a string and report is a dictionary with
471 keys `toco_log` (log of toco conversion), `tf_log` (log of tf
472 conversion), `toco` (a string of success status of the conversion),
473 `tf` (a string success status of the conversion).
474 """
475
476 np.random.seed(RANDOM_SEED)
477 report = {"toco": report_lib.NOTRUN, "tf": report_lib.FAILED}
478
479 # Build graph
480 report["tf_log"] = ""
481 report["toco_log"] = ""
482 tf.reset_default_graph()
483
484 with tf.device("/cpu:0"):
485 try:
486 inputs, outputs = make_graph(param_dict_real)
487 except (tf.errors.UnimplementedError, tf.errors.InvalidArgumentError,
488 ValueError):
489 report["tf_log"] += traceback.format_exc()
490 return None, report
491
492 sess = tf.compat.v1.Session()
493 try:
494 baseline_inputs, baseline_outputs = (make_test_inputs(
495 param_dict_real, sess, inputs, outputs))
496 except (tf.errors.UnimplementedError, tf.errors.InvalidArgumentError,
497 ValueError):
498 report["tf_log"] += traceback.format_exc()
499 return None, report
500 report["toco"] = report_lib.FAILED
501 report["tf"] = report_lib.SUCCESS
502 # Convert graph to toco
503 input_tensors = [(input_tensor.name.split(":")[0], input_tensor.shape,
504 input_tensor.dtype) for input_tensor in inputs]
505 output_tensors = [normalize_output_name(out.name) for out in outputs]
506 graph_def = freeze_graph(
507 sess,
508 tf.global_variables() + inputs +
509 outputs) if use_frozen_graph else sess.graph_def
510
511 if "split_tflite_lstm_inputs" in param_dict_real:
512 extra_toco_options.split_tflite_lstm_inputs = param_dict_real[
513 "split_tflite_lstm_inputs"]
514 tflite_model_binary, toco_log = options.tflite_convert_function(
515 options,
516 graph_def,
517 input_tensors,
518 output_tensors,

Callers 1

make_zip_of_testsFunction · 0.85

Calls 11

normalize_output_nameFunction · 0.85
build_tflite_inputsFunction · 0.85
write_examplesFunction · 0.85
write_test_casesFunction · 0.85
freeze_graphFunction · 0.70
seedMethod · 0.45
deviceMethod · 0.45
SessionMethod · 0.45
splitMethod · 0.45
global_variablesMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected