<filename>evaluation/quantitive_metrics/peak_signal_to_noise_ratio.py
import tensorflow as tf
from evaluation.shared import log10
def prepare_psnr(inputs_flat_shape):
    def psnr(inputs, x_logits):
        imageB = tf.sigmoid(x_logits)
        imageA = inputs
        imageB = tf.reshape(imageB, tf.TensorShape(inputs_flat_shape))
        imageA = tf.reshape(imageA, tf.TensorShape(inputs_flat_shape))

        """
        Computes the Peak Signal to Noise Ratio error between the generated images and the ground
        truth images.
    
        @param gen_frames: A tensor of shape [batch_size, height, width, 3]. The frames generated by the generator model.
        @param gt_frames: A tensor of shape [batch_size, height, width, 3]. The ground-truth frames for each frame in gen_frames.
        @return: A scalar tensor. The mean Peak Signal to Noise Ratio error over each frame in the batch.
        """

        num_pixels = tf.cast(inputs_flat_shape[1] * inputs_flat_shape[2] * inputs_flat_shape[3], dtype='float')
        square_diff = tf.square(imageA - imageB)

        batch_errors = 10 * log10(1 / ((1 / num_pixels) * tf.reduce_sum(square_diff, [1, 2, 3])))
        return tf.reduce_mean(batch_errors)
    return psnr
