pyanomaly/datatools/evaluate/utils.py
def psnr_error(gen_frames, gt_frames, hat=False):
    """
    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.
    """
    gen_frames = gen_frames.detach().cpu()
    gt_frames = gt_frames.detach().cpu()
    batch_num = gen_frames.shape[0]
    batch_errors = 0.0
    for i in range(batch_num):
        num_pixels = gen_frames[i].numel()
        # max_val_hat = gen_frames[i].max()
        if hat:
            max_val = gen_frames[i].max()
        else:
            max_val = gt_frames[i].max()
        square_diff = (gt_frames[i] - gen_frames[i])**2
        log_value = torch.log10(max_val ** 2 / ((1. / num_pixels) * torch.sum(square_diff)))
        image_errors = 10 * log_value
        batch_errors += image_errors
    
    batch_errors = torch.div(batch_errors, batch_num)
    return batch_errors

    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.
    
Computes the Peak Signal to Noise Ratio error between the generated images and the ground
truth images.
Computes the Peak Signal to Noise Ratio error between the generated images and the ground truth images .
def psnr_error(gen_frames, gt_frames, hat=False):
    gen_frames = gen_frames.detach().cpu()
    gt_frames = gt_frames.detach().cpu()
    batch_num = gen_frames.shape[0]
    batch_errors = 0.0
    for i in range(batch_num):
        num_pixels = gen_frames[i].numel()
        if hat:
            max_val = gen_frames[i].max()
        else:
            max_val = gt_frames[i].max()
        square_diff = (gt_frames[i] - gen_frames[i])**2
        log_value = torch.log10(max_val ** 2 / ((1. / num_pixels) * torch.sum(square_diff)))
        image_errors = 10 * log_value
        batch_errors += image_errors
    batch_errors = torch.div(batch_errors, batch_num)
    return batch_errors
def psnr_error ( gen_frames , gt_frames , hat = False ) : gen_frames = gen_frames . detach ( ) . cpu ( ) gt_frames = gt_frames . detach ( ) . cpu ( ) batch_num = gen_frames . shape [ 0 ] batch_errors = 0.0 for i in range ( batch_num ) : num_pixels = gen_frames [ i ] . numel ( ) if hat : max_val = gen_frames [ i ] . max ( ) else : max_val = gt_frames [ i ] . max ( ) square_diff = ( gt_frames [ i ] - gen_frames [ i ] ) ** 2 log_value = torch . log10 ( max_val ** 2 / ( ( 1. / num_pixels ) * torch . sum ( square_diff ) ) ) image_errors = 10 * log_value batch_errors += image_errors batch_errors = torch . div ( batch_errors , batch_num ) return batch_errors
Computes the Peak Signal to Noise Ratio error between the generated images and the ground
truth images.
Computes the Peak Signal to Noise Ratio error between the generated images and the ground truth images .
"""
    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.
    """ # max_val_hat = gen_frames[i].max()

A scalar tensor. The mean Peak Signal to Noise Ratio error over each frame in the
batch.
A scalar tensor . The mean Peak Signal to Noise Ratio error over each frame in the batch .
gen_frames
A tensor of shape [batch_size, height, width, 3]. The frames generated by the
generator model.
A tensor of shape [ batch_size height width 3 ] . The frames generated by the generator model .
gt_frames
A tensor of shape [batch_size, height, width, 3]. The ground-truth frames for
each frame in gen_frames.
A tensor of shape [ batch_size height width 3 ] . The ground - truth frames for each frame in gen_frames .
hat