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
def calc_loss_psnr ( gen_images , images , name , hparams = None , use_l1_loss = False ) : 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 ) ) tf . summary . scalar ( 'psnr_all' , psnr_all ) tf . summary . scalar ( 'loss' , loss ) return loss , psnr_all
Calculates loss and psnr for predictions over multiple timesteps.