pytorch_ssim.ssim() TypeError: conv2d() received an invalid combination of arguments - got (Tensor,

目录

情况

原因A:批输入图片

原因B:图像尺寸不一致

SSIM简介


情况

 batch_ssim = pytorch_ssim.ssim(img1, img2).item()

TypeError: conv2d() received an invalid combination of arguments - got (Tensor, Tensor, padding=float, groups=int), but expected one of:

  • (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)
  • (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)

原因A:批输入图片

该函数目前只接受一对图片作为输入,而不是整个epoch,因此在验证集批处理大小> 1 的情况下不可用。

The format of the input data is as follows:
torch.Size([4, 3, 256, 256])
torch.float32
torch.Size([4, 3, 256, 256])
torch.float32

解决:

循环每个图像以获取 SSIM 值

原因B:图像尺寸不一致

解决:resize

SSIM简介

结构相似性指数(SSIM)度量从一幅图像中提取3个关键特征:

  • 亮度

  • 对比度

  • 结构

  • 与其在全局范围内应用上述度量值(即一次在图像上的所有区域),不如在局部范围内应用这些度量值(即在图像的小部分中,然后取整体的平均值)。

    这种方法通常被称为平均结构相似度指数。

  • 使用一个11x11圆对称高斯加权函数(基本上就是一个11x11矩阵,其值来自高斯分布)在整个图像上逐像素移动。在每一步中,在局部窗口内计算局部统计信息和SSIM索引。

  • 只需取所有局部SSIM值的平均值,就得到了全局的 SSIM值。

猜你喜欢

转载自blog.csdn.net/qq_28838891/article/details/128362038
今日推荐