import torch


def psnr(gt, img):
    """
    calculate psnr between two images
    :param gt: groundtruth image
    :param img: inference image
    :return: psnr
    """
    mse = torch.mean( (gt - img) ** 2 )
    if mse < 1.0e-10:
        return 100
    PIXEL_MAX = 1.0
    return 20 * torch.log10(PIXEL_MAX / torch.sqrt(mse))