4343body {font-family: sans-serif; background-color: #fa0;}
4444table {background-color: #eca;}
4545th {background-color: black; color: white;}
46+ /* Constrain table cells to a max size and make them scrollable. */
47+ .data-table td {
48+ max-width: 900px;
49+ }
50+ .data-table .cell-content {
51+ max-height: 200px;
52+ overflow: auto;
53+ white-space: pre-wrap;
54+ word-break: break-all;
55+ }
4656h1 {
4757 background-color: ffaa00;
4858 padding:5px;
@@ -284,6 +294,27 @@ def __call__(self, x):
284294 return html
285295
286296
297+ def QuantizationMapper (q ):
298+ """Pretty-print the quantization dictionary, truncating large arrays."""
299+ if not q :
300+ return ""
301+
302+ items_str = []
303+ for key , value in q .items ():
304+ key_str = repr (key )
305+ # In TFLite, quantization arrays can be large.
306+ if isinstance (value , list ) and len (value ) > 20 :
307+ head = value [:10 ]
308+ tail = value [- 10 :]
309+ value_str = (f"[{ ', ' .join (map (repr , head ))} , ..., "
310+ f"{ ', ' .join (map (repr , tail ))} ]" )
311+ else :
312+ value_str = repr (value )
313+ items_str .append (f"{ key_str } : { value_str } " )
314+
315+ return f"{{{ ', ' .join (items_str )} }}"
316+
317+
287318def GenerateGraph (subgraph_idx , g , opcode_mapper ):
288319 """Produces the HTML required to have a d3 visualization of the dag."""
289320
@@ -359,8 +390,8 @@ def GenerateTableHtml(items, keys_to_print, display_index=True):
359390 An html table.
360391 """
361392 html = ""
362- # Print the list of items
363- html += "<table><tr >\n "
393+ # Print the list of items
394+ html += "<table class='data-table' >\n "
364395 html += "<tr>\n "
365396 if display_index :
366397 html += "<th>index</th>"
@@ -375,7 +406,7 @@ def GenerateTableHtml(items, keys_to_print, display_index=True):
375406 for h , mapper in keys_to_print :
376407 val = tensor [h ] if h in tensor else None
377408 val = val if mapper is None else mapper (val )
378- html += "<td>%s </td>\n " % val
409+ html += "<td><div class='cell-content'>%s</div> </td>\n " % val
379410
380411 html += "</tr>\n "
381412 html += "</table>\n "
@@ -465,11 +496,13 @@ def create_html(tflite_input, input_is_filepath=True): # pylint: disable=invali
465496 toplevel_stuff = [("filename" , None ), ("version" , None ),
466497 ("description" , None )]
467498
468- html += "<table>\n "
499+ html += "<table class='data-table' >\n "
469500 for key , mapping in toplevel_stuff :
470501 if not mapping :
471502 mapping = lambda x : x
472- html += "<tr><th>%s</th><td>%s</td></tr>\n " % (key , mapping (data .get (key )))
503+ val = mapping (data .get (key ))
504+ html += ("<tr><th>%s</th><td><div class='cell-content'>%s</div></td></tr>\n "
505+ % (key , val ))
473506 html += "</table>\n "
474507
475508 # Spec on what keys to display
@@ -493,7 +526,7 @@ def create_html(tflite_input, input_is_filepath=True): # pylint: disable=invali
493526 tensor_keys_to_display = [("name" , NameListToString ),
494527 ("type" , TensorTypeToName ), ("shape" , None ),
495528 ("shape_signature" , None ), ("buffer" , None ),
496- ("quantization" , None )]
529+ ("quantization" , QuantizationMapper )]
497530
498531 html += "<h2>Subgraph %d</h2>\n " % subgraph_idx
499532
0 commit comments