LPIPS图像相似性度量标准:The Unreasonable Effectiveness of Deep Features as a Perceptual Metric

LPIPS图像相似性度量标准:The Unreasonable Effectiveness of Deep Features as a Perceptual Metric

一、感知相似性

二、传统度量和深度学习法

三、原理

四、测试和代码

五、测试结果

六、参考文献

一、 感知相似性

人类可以快速评估两幅图像之间的感知相似性,但是底层过程非常复杂。
纹理图像包含了纹理颜色、纹理基元等丰富的图像信息。在计算机视觉研究领域中,人们使用感知

相似性来度量不同纹理之间的相似程度,研究人类对纹理图像的视觉感知。纹理相似性度量广泛应用于纹理识别和材质识别,是对象识别和场景理解的关键技术之一。研究人员通过计算特征之间的距离度量估计纹理感知相似性。
近年来,对图像网络分类进行训练的VGG网络的特性作为图像合成的训练损失具有显著的作用。

二、传统度量和深度学习法

将左右的两个图像块和中间的图像块进行比较:

LPIPS图像相似性度量标准:The Unreasonable Effectiveness of Deep Features as a Perceptual Metric

如图表示,每一组有三张图片,由传统的评价标准如L2、SSIM、PSNR等评价结果和人体认为的大不相同,这是传统方法的弊端。如果图片平滑,那么传统的评价方式则大概率会失效。而目前GAN尤其是VAE等生成模型生成结果都过于平滑。

而最后三行的评价为深度学习的方式,可以看到,通过神经网络(非监督、自监督、监督模型)提取特征的方式,并对特征差异进行计算能够有效进行评价,而且能够和人体评价相似。

三、原理

LPIPS图像相似性度量标准:The Unreasonable Effectiveness of Deep Features as a Perceptual Metric

LPIPS图像相似性度量标准:The Unreasonable Effectiveness of Deep Features as a Perceptual Metric

公式如下:(因此实际中,公式不开方)

LPIPS图像相似性度量标准:The Unreasonable Effectiveness of Deep Features as a Perceptual Metric

当w值为1时,即公式计算余弦距离。

论文中将LPIPS分为三类:

• Lin :固定预训练网络,学习线性权重 w

• Tune :从预预训练模型初始化,并对整个网络进行微调

• Scratch :使用高斯分布的权重进行初始化网络,并对整个网络进行训练。

四、测试和代码

1、python环境下安装 pip install lpips

2、准备好图片,注意:图片读取后应归一化,且注意数据类型,见代码。我的图片如下所示,为1536*512大小。你可以直接载入你自己的图片。我们比较的是模型结果和目标结果。

LPIPS图像相似性度量标准:The Unreasonable Effectiveness of Deep Features as a Perceptual Metric

3、代码:(注意可以选择预训练网络模型为alex或者vgg,这里我选择的是alex)

#coding=gbk
import cv2
import lpips
import torchvision.transforms as transforms
import torch
#载入指标模型
loss_fn_alex = lpips.LPIPS(net='alex') # best forward scores
loss_fn_vgg = lpips.LPIPS(net='vgg') # closer to "traditional" perceptual loss, when used for optimization

#读取图片
test1 = cv2.imread('test_picture_117.png')
test2 = cv2.imread('test_picture_124.png')
#分割目标图片
test1_org = test1[:,:512,:]/255 #原始图片
test1_res = test1[:,512:1024,:]/255 #模型输出结果
test1_label = test1[:,1024:1536,:]/255 #label图片

test2_org = test2[:,:512,:]/255
test2_res = test2[:,512:1024,:]/255
test2_label = test2[:,1024:1536,:]/255

#转为tensor
transf = transforms.ToTensor()

test1_org = transf(test1_org)
test1_res = transf(test1_res)
test1_label = transf(test1_label)
test2_org = transf(test2_org)
test2_res = transf(test2_res)
test2_label = transf(test2_label)

#转换数据类型
test1_orgg = test1_org.to(torch.float32)
test1_ress = test1_res.to(torch.float32)
test1_labell = test1_label.to(torch.float32)
test2_orgg = test2_org.to(torch.float32)
test2_ress = test2_res.to(torch.float32)
test2_labell =test2_label.to(torch.float32)

#测试
d11 = loss_fn_alex(test1_ress, test1_labell)
d12 = loss_fn_alex(test1_ress, test2_labell)
print('d11:',d11)
print('d12:',d12)

d22 = loss_fn_alex(test2_ress, test2_labell)
d21 = loss_fn_alex(test2_ress, test1_labell)
print('d22:',d22)
print('d121:',d21)

五、测试结果

值越小越好。d11、d22表示生成结果和对应的label之间的LPIPS距离,d12、d21为生成结果和非对应label结果。可见对应的情况下值应当低且实际结果如下所示,事实确实如此。

LPIPS图像相似性度量标准:The Unreasonable Effectiveness of Deep Features as a Perceptual Metric

六、参考文献

https://arxiv.org/pdf/1801.03924.pdf

• The Unreasonable Effectiveness of Deep Features as a Perceptual Metric

原创文章:LPIPS图像相似性度量标准:The Unreasonable Effectiveness of Deep Features as a Perceptual Metric_Alocus_的博客-CSDN博客_lpips度量

Original: https://blog.csdn.net/Crystal_remember/article/details/119959954
Author: Alocus_
Title: LPIPS图像相似性度量标准:The Unreasonable Effectiveness of Deep Features as a Perceptual Metric

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/688606/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球