*Show success info and file path to converted model when conversion succeeds.

*Show 'jump to conversion log' near conversion summary.

PiperOrigin-RevId: 278971390
Change-Id: I13c69403cff99791631e4496b3519c4d924d52d5
This commit is contained in:
Haoliang Zhang 2019-11-06 17:03:06 -08:00 committed by TensorFlower Gardener
parent d0efb06d74
commit ed5ac6ab66
5 changed files with 25 additions and 9 deletions

View File

@ -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"

View File

@ -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["<!--REPEAT_TABLE2_ROWS-->"] = post_op_profile
html_dict["<!--DOT_BEFORE_CONVERT-->"] = dot_before
html_dict["<!--DOT_AFTER_CONVERT-->"] = dot_after
html_dict["<!--TOCO_ERROR_LOG-->"] = html_escape(toco_err_log)
if toco_err_log:
html_dict["<!--TOCO_INFO_LOG-->"] = html_escape(toco_err_log)
else:
success_info = ("TFLite graph conversion successful. You can preview the "
"converted model at: ") + tflite_graph_path
html_dict["<!--TOCO_INFO_LOG-->"] = 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)

View File

@ -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")

View File

@ -58,6 +58,7 @@
<h2>Conversion Summary
<!--CONVERSION_STATUS-->
</h2>
<a href="#conversionlog">Jump to conversion log</a>
<ul class="list-group">
<li class="list-group-item">Total ops used before conversion: <!--TOTAL_OPS_BEFORE_CONVERT--></li>
@ -148,10 +149,11 @@
</div>
</div>
<a name="conversionlog"></a>
<h2>Conversion Log</h2>
<div>
<pre class="pre-scrollable">
<code><!--TOCO_ERROR_LOG--></code>
<code><!--TOCO_INFO_LOG--></code>
</pre>
</div>
</div>

View File

@ -58,6 +58,7 @@
<h2>Conversion Summary
<span class="label label-success">Success</span>
</h2>
<a href="#conversionlog">Jump to conversion log</a>
<ul class="list-group">
<li class="list-group-item">Total ops used before conversion: 9</li>
@ -148,10 +149,11 @@
</div>
</div>
<a name="conversionlog"></a>
<h2>Conversion Log</h2>
<div>
<pre class="pre-scrollable">
<code></code>
<code>TFLite graph conversion successful. You can preview the converted model at: /path/to/flatbuffer</code>
</pre>
</div>
</div>