code: def calc_loss_psnr(
      gen_images, images, name, hparams=None, use_l1_loss=False
  ):
      """Calculates loss and psnr for predictions over multiple timesteps."""
      del hparams
      with tf.name_scope(name):
          loss, error, psnr_all = 0.0, 0.0, 0.0
          for _, x, gx in zip(
              range(len(gen_images)), images, gen_images
          ):
              recon_cost = mean_squared_error(x, gx)
              if use_l1_loss:
                  recon_cost = l1_error(x, gx)
  
              error_i = l1_error(x, gx)
              psnr_i = peak_signal_to_noise_ratio(x, gx)
              psnr_all += psnr_i
              error += error_i
              loss += recon_cost
  
          psnr_all /= tf.to_float(len(gen_images))
          loss /= tf.to_float(len(gen_images))
          error /= tf.to_float(len(gen_images))
  
          # if not hparams.use_tpu:
          tf.summary.scalar("psnr_all", psnr_all)
          tf.summary.scalar("loss", loss)
  
          return loss, psnr_all
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from six.moves import reduce
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import common_video
  from tensor2tensor.models.video import epva_params
  from tensor2tensor.models.video import sv2p
  from tensor2tensor.utils import contrib
  from tensor2tensor.utils import registry
  import tensorflow.compat.v1
  from tensorflow.contrib.framework.python.ops import arg_scope
  from tensorflow.contrib.slim.python.slim.nets import vgg
label_desc: Use image node_id 12 for calling a global function with example usage: calc_loss_psnr(gen_images, images, name, hparams, use_l1_loss) and returns: loss,  psnr_all