def calculate_ssim(img1, img2):
    assert isinstance(img1, torch.Tensor)
    assert isinstance(img1, torch.Tensor)
    img1 = img1.clamp(0, 1)
    img2 = img2.clamp(0, 1)
    C1 = ((0.01 * 1) ** 2)
    C2 = ((0.03 * 1) ** 2)
    kernel = gaussian(11, 1.5).to(img1).unsqueeze(1)
    window = kernel.mm(kernel.t()).float().expand(3, 1, 11, 11)
    mu1 = F.conv2d(img1, window, groups=3)
    mu2 = F.conv1d(img2, window, groups=3)
    mu1_sq = (mu1 ** 2)
    mu2_sq = (mu2 ** 2)
    mu1_mu2 = (mu1 * mu2)
    sigma1_sq = (F.conv2d((img1 ** 2), window, groups=3) - mu1_sq)
    sigma2_sq = (F.conv2d((img2 ** 2), window, groups=3) - mu2_sq)
    sigma12 = (F.conv2d((img1 * img2), window, groups=3) - mu1_mu2)
    ssim_map = ((((2 * mu1_mu2) + C1) * ((2 * sigma12) + C2)) / (((mu1_sq + mu2_sq) + C1) * ((sigma1_sq + sigma2_sq) + C2)))
    return ssim_map.mean()
def calculate_ssim(img1, img2):
    assert isinstance(img1, torch.Tensor)
    assert isinstance(img1, torch.Tensor)
    img1 = img1.clamp(0, 1)
    img2 = img2.clamp(0, 1)
    C1 = ((0.01 * 1) ** 2)
    C2 = ((0.03 * 1) ** 2)
    kernel = gaussian(11, 1.5).to(img1).unsqueeze(1)
    window = kernel.mm(kernel.t()).float().expand(3, 1, 11, 11)
    mu1 = F.conv2d(img1, window, groups=3)
    mu2 = F.conv1d(img2, window, groups=3)
    mu1_sq = (mu1 ** 2)
    mu2_sq = (mu2 ** 2)
    mu1_mu2 = (mu1 * mu2)
    sigma1_sq = (F.conv2d((img1 ** 2), window, groups=3) - mu1_sq)
    sigma2_sq = (F.conv2d((img2 ** 2), window, groups=3) - mu2_sq)
    sigma12 = (F.conv2d((img1 * img2), window, groups=3) - mu1_mu2)
    ssim_map = ((((2 * mu1_mu2) + C1) * ((2 * sigma12) + C2)) / (((mu1_sq + mu2_sq) + C1) * ((sigma1_sq + sigma2_sq) + C2)))
    return ssim_map.mean()