code: def finalize_autosummaries() -> None:
      """Create the necessary ops to include autosummaries in TensorBoard report.
      Note: This should be done only once per graph.
      """
      global _finalized
      tfutil.assert_tf_initialized()
  
      if _finalized:
          return None
  
      _finalized = True
      tfutil.init_uninitialized_vars(
          [var for vars_list in _vars.values() for var in vars_list]
      )
  
      # Create summary ops.
      with tf.device(None), tf.control_dependencies(None):
          for name, vars_list in _vars.items():
              name_id = name.replace("/", "_")
              with tfutil.absolute_name_scope("Autosummary/" + name_id):
                  moments = tf.add_n(vars_list)
                  moments /= moments[0]
                  with tf.control_dependencies(
                      [moments]
                  ):  # read before resetting
                      reset_ops = [
                          tf.assign(var, tf.zeros(3, dtype=_dtype))
                          for var in vars_list
                      ]
                      with tf.name_scope(None), tf.control_dependencies(
                          reset_ops
                      ):  # reset before reporting
                          mean = moments[1]
                          std = tf.sqrt(
                              moments[2] - tf.square(moments[1])
                          )
                          tf.summary.scalar(name, mean)
                          if enable_custom_scalars:
                              tf.summary.scalar(
                                  "xCustomScalars/"
                                  + name
                                  + "/margin_lo",
                                  mean - std,
                              )
                              tf.summary.scalar(
                                  "xCustomScalars/"
                                  + name
                                  + "/margin_hi",
                                  mean + std,
                              )
  
      # Setup layout for custom scalars.
      layout = None
      if enable_custom_scalars:
          cat_dict = OrderedDict()
          for series_name in sorted(_vars.keys()):
              p = series_name.split("/")
              cat = p[0] if len(p) >= 2 else ""
              chart = "/".join(p[1:-1]) if len(p) >= 3 else p[-1]
              if cat not in cat_dict:
                  cat_dict[cat] = OrderedDict()
              if chart not in cat_dict[cat]:
                  cat_dict[cat][chart] = []
              cat_dict[cat][chart].append(series_name)
          categories = []
          for cat_name, chart_dict in cat_dict.items():
              charts = []
              for chart_name, series_names in chart_dict.items():
                  series = []
                  for series_name in series_names:
                      series.append(
                          layout_pb2.MarginChartContent.Series(
                              value=series_name,
                              lower="xCustomScalars/"
                              + series_name
                              + "/margin_lo",
                              upper="xCustomScalars/"
                              + series_name
                              + "/margin_hi",
                          )
                      )
                  margin = layout_pb2.MarginChartContent(series=series)
                  charts.append(
                      layout_pb2.Chart(title=chart_name, margin=margin)
                  )
              categories.append(
                  layout_pb2.Category(title=cat_name, chart=charts)
              )
          layout = summary_lib.custom_scalar_pb(
              layout_pb2.Layout(category=categories)
          )
      return layout
  
file_path: insightface/reconstruction/ostec/external/stylegan2/dnnlib/tflib/autosummary.py
imports: from collections import OrderedDict
  import numpy
  import tensorflow
  from tensorboard import summary
  from tensorboard.plugins.custom_scalar import layout_pb2
  from .None import tfutil
  from .tfutil import TfExpression
  from .tfutil import TfExpressionEx
label_desc: Use image node_id 3 for calling a global function with example usage: finalize_autosummaries() and returns: layout, None