(gen_frames, gt_frames)
return tf.reduce_mean(batch_errors)
Computes the Sharpness Difference 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 Sharpness Difference error over each frame in the batch.
Computes the Sharpness Difference error between the generated images and the ground truth
    images.
Computes the Sharpness Difference error between the generated images and the ground truth images .
def sharp_diff_error(gen_frames, gt_frames):
    """
    Computes the Sharpness Difference 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 Sharpness Difference error over each frame in the batch.
    """
    shape = tf.shape(gen_frames)
    num_pixels = tf.to_float(shape[1] * shape[2] * shape[3])

    # gradient difference
    # create filters [-1, 1] and [[1],[-1]] for diffing to the left and down respectively.
    # TODO: Could this be simplified with one filter [[-1, 2], [0, -1]]?
    pos = tf.constant(np.identity(3), dtype=tf.float32)
    neg = -1 * pos
    filter_x = tf.expand_dims(tf.pack([neg, pos]), 0)  # [-1, 1]
    filter_y = tf.pack([tf.expand_dims(pos, 0), tf.expand_dims(neg, 0)])  # [[1],[-1]]
    strides = [1, 1, 1, 1]  # stride of (1, 1)
    padding = 'SAME'

    gen_dx = tf.abs(tf.nn.conv2d(gen_frames, filter_x, strides, padding=padding))
    gen_dy = tf.abs(tf.nn.conv2d(gen_frames, filter_y, strides, padding=padding))
    gt_dx = tf.abs(tf.nn.conv2d(gt_frames, filter_x, strides, padding=padding))
    gt_dy = tf.abs(tf.nn.conv2d(gt_frames, filter_y, strides, padding=padding))

    gen_grad_sum = gen_dx + gen_dy
    gt_grad_sum = gt_dx + gt_dy

    grad_diff = tf.abs(gt_grad_sum - gen_grad_sum)

    batch_errors = 10 * log10(1 / ((1 / num_pixels) * tf.reduce_sum(grad_diff, [1, 2, 3])))
    return tf.reduce_mean(batch_errors)
def sharp_diff_error ( gen_frames , gt_frames ) : shape = tf . shape ( gen_frames ) num_pixels = tf . to_float ( shape [ 1 ] * shape [ 2 ] * shape [ 3 ] ) # gradient difference # create filters [-1, 1] and [[1],[-1]] for diffing to the left and down respectively. # TODO: Could this be simplified with one filter [[-1, 2], [0, -1]]? pos = tf . constant ( np . identity ( 3 ) , dtype = tf . float32 ) neg = - 1 * pos filter_x = tf . expand_dims ( tf . pack ( [ neg , pos ] ) , 0 ) # [-1, 1] filter_y = tf . pack ( [ tf . expand_dims ( pos , 0 ) , tf . expand_dims ( neg , 0 ) ] ) # [[1],[-1]] strides = [ 1 , 1 , 1 , 1 ] # stride of (1, 1) padding = 'SAME' gen_dx = tf . abs ( tf . nn . conv2d ( gen_frames , filter_x , strides , padding = padding ) ) gen_dy = tf . abs ( tf . nn . conv2d ( gen_frames , filter_y , strides , padding = padding ) ) gt_dx = tf . abs ( tf . nn . conv2d ( gt_frames , filter_x , strides , padding = padding ) ) gt_dy = tf . abs ( tf . nn . conv2d ( gt_frames , filter_y , strides , padding = padding ) ) gen_grad_sum = gen_dx + gen_dy gt_grad_sum = gt_dx + gt_dy grad_diff = tf . abs ( gt_grad_sum - gen_grad_sum ) batch_errors = 10 * log10 ( 1 / ( ( 1 / num_pixels ) * tf . reduce_sum ( grad_diff , [ 1 , 2 , 3 ] ) ) ) return tf . reduce_mean ( batch_errors )