diff --git a/tensorflow/lite/python/tflite_convert.py b/tensorflow/lite/python/tflite_convert.py index 06f69315582..1b779fb4673 100644 --- a/tensorflow/lite/python/tflite_convert.py +++ b/tensorflow/lite/python/tflite_convert.py @@ -582,7 +582,8 @@ def run_main(_): if tflite_flags.conversion_summary_dir: if tflite_flags.experimental_new_converter: gen_html.gen_conversion_log_html(tflite_flags.conversion_summary_dir, - tflite_flags.post_training_quantize) + tflite_flags.post_training_quantize, + tflite_flags.output_file) else: warnings.warn( "Conversion summary will only be generated when enabling" diff --git a/tensorflow/lite/toco/logging/gen_html.py b/tensorflow/lite/toco/logging/gen_html.py index 33ac3f1a006..95ad53ad407 100644 --- a/tensorflow/lite/toco/logging/gen_html.py +++ b/tensorflow/lite/toco/logging/gen_html.py @@ -114,7 +114,8 @@ class HTMLGenerator(object): post_training_quant_enabled, dot_before, dot_after, - toco_err_log=""): + toco_err_log="", + tflite_graph_path=""): """Generates the HTML report and writes it to local directory. This function uses the fields in `toco_conversion_log_before` and @@ -137,6 +138,7 @@ class HTMLGenerator(object): toco_err_log: A string, the logs emitted by TOCO during conversion. Caller need to ensure that this string is properly anoynimized (any kind of user data should be eliminated). + tflite_graph_path: A string, the filepath to the converted TFLite model. Raises: RuntimeError: When error occurs while generating the template. @@ -183,7 +185,12 @@ class HTMLGenerator(object): html_dict[""] = post_op_profile html_dict[""] = dot_before html_dict[""] = dot_after - html_dict[""] = html_escape(toco_err_log) + if toco_err_log: + html_dict[""] = html_escape(toco_err_log) + else: + success_info = ("TFLite graph conversion successful. You can preview the " + "converted model at: ") + tflite_graph_path + html_dict[""] = html_escape(success_info) # Replace each marker (as keys of html_dict) with the actual text (as values # of html_dict) in the HTML template string. @@ -198,7 +205,8 @@ class HTMLGenerator(object): f.write(template) -def gen_conversion_log_html(conversion_log_dir, quantization_enabled): +def gen_conversion_log_html(conversion_log_dir, quantization_enabled, + tflite_graph_path): """Generates an HTML report about the conversion process. Args: @@ -210,6 +218,7 @@ def gen_conversion_log_html(conversion_log_dir, quantization_enabled): `toco_tflite_graph.dot`. quantization_enabled: A boolean, passed from the tflite converter to indicate whether post-training quantization is enabled during conversion. + tflite_graph_path: A string, the filepath to the converted TFLite model. Raises: IOError: When any of the required files doesn't exist. @@ -256,4 +265,5 @@ def gen_conversion_log_html(conversion_log_dir, quantization_enabled): html_generator.generate(toco_conversion_log_before, toco_conversion_log_after, quantization_enabled, dot_before, dot_after, - toco_conversion_log_after.toco_err_logs) + toco_conversion_log_after.toco_err_logs, + tflite_graph_path) diff --git a/tensorflow/lite/toco/logging/gen_html_test.py b/tensorflow/lite/toco/logging/gen_html_test.py index 2cabe59bf54..937e497bb54 100644 --- a/tensorflow/lite/toco/logging/gen_html_test.py +++ b/tensorflow/lite/toco/logging/gen_html_test.py @@ -60,7 +60,8 @@ class GenHtmlTest(test_util.TensorFlowTestCase): html_generator.generate(toco_conversion_log_before, toco_conversion_log_after, True, - "digraph {a -> b}", "digraph {a -> b}") + "digraph {a -> b}", "digraph {a -> b}", "", + "/path/to/flatbuffer") with _file_io.FileIO(export_path, "r") as f_export, _file_io.FileIO( resource_loader.get_path_to_datafile("testdata/generated.html"), @@ -86,7 +87,7 @@ class GenHtmlTest(test_util.TensorFlowTestCase): shutil.copy(dot_after, export_path) # Generate HTML content based on files in the test folder. - gen_html.gen_conversion_log_html(export_path, True) + gen_html.gen_conversion_log_html(export_path, True, "/path/to/flatbuffer") result_html = os.path.join(export_path, "toco_conversion_summary.html") diff --git a/tensorflow/lite/toco/logging/template.html b/tensorflow/lite/toco/logging/template.html index d1a7f216b81..bab00aae3ac 100644 --- a/tensorflow/lite/toco/logging/template.html +++ b/tensorflow/lite/toco/logging/template.html @@ -58,6 +58,7 @@
-+
-+
TFLite graph conversion successful. You can preview the converted model at: /path/to/flatbuffer