code: def add_loss_summaries(
      total_loss,
      loss,
      regul_losses_collection_key,
      name_prefix="",
      summaries_collection_key=None,
      exp_moving_avg=0.9,
      ema_num_updates=None,
  ):
      """add_loss_summaries.
  
      Add scalar summaries (raw and averages) for given losses.
  
      Generates moving average for all losses and associated summaries for
      visualizing the performance of the network.
  
      Arguments:
          total_loss: `Tensor`. The total loss (Regression loss +
              regularization losses).
          loss: `Tensor`. Regression loss.
          name_prefix: `str`. A prefix to add to the summary name.
          regul_losses_collection_key: `str`. A collection name to retrieve
              regularization losses.
          exp_moving_avg: `float`. Exponential moving average.
          ema_num_updates: `int`. Step to be used with exp moving avg.
  
      Returns:
          loss_averages_op: op for generating moving averages of losses.
      """
      # Compute the moving average of all individual losses and the total loss.
      loss_averages = tf.train.ExponentialMovingAverage(
          decay=exp_moving_avg,
          num_updates=ema_num_updates,
          name="moving_avg",
      )
      other_losses = tf.get_collection(regul_losses_collection_key)
  
      # Attach a scalar summmary to all individual losses and the total loss;
      # do the same for the averaged version of the losses.
      # Name each loss as '(raw)' and name the moving average version of the loss
      # as the original loss name.
  
      # Only add total loss, if it has more than one loss...
      if len(other_losses) > 0 and total_loss is not None:
          loss_averages_op = loss_averages.apply(
              [total_loss] + [loss] + other_losses
          )
          summ_name = "Loss_var_loss/" + name_prefix
          get_summary(
              "scalar",
              summ_name,
              loss_averages.average(total_loss),
              summaries_collection_key,
          )
          get_summary(
              "scalar",
              summ_name + "raw",
              total_loss,
              summaries_collection_key,
          )
      elif total_loss is not None:
          loss_averages_op = loss_averages.apply([loss] + other_losses)
      else:
          loss_averages_op = loss_averages.apply([loss])
  
      # For tflearn wrapper visibility
      summ_name = "Loss/" + name_prefix
      get_summary(
          "scalar",
          summ_name,
          loss_averages.average(loss),
          summaries_collection_key,
      )
      get_summary(
          "scalar", summ_name + "raw", loss, summaries_collection_key
      )
  
      for wdl in other_losses:
          # No prefix, we store every variable into their own scope
          summ_name = wdl.op.name
          get_summary(
              "scalar",
              summ_name,
              loss_averages.average(wdl),
              summaries_collection_key,
          )
          get_summary(
              "scalar", summ_name + "raw", wdl, summaries_collection_key
          )
  
      return loss_averages_op
  
file_path: tflearn/tflearn/summaries.py
imports: from __future__ import division, print_function, absolute_import
  import tensorflow.compat.v1
  from tensorflow.core.framework import summary_pb2
  from .utils import format_scope_name
label_desc: Use image node_id 7 for calling a global function with example usage: add_loss_summaries(total_loss, loss, regul_losses_collection_key, name_prefix, summaries_collection_key, exp_moving_avg, ema_num_updates) and returns: loss_averages_op