LPIPS 图像相似性度量标准(感知损失)

可学习感知图像块相似度(Learned Perceptual Image Patch Similarity, LPIPS)

 项目主页:https://richzhang.github.io/PerceptualSimilarity/

论文地址:https://arxiv.org/abs/1801.03924

开源代码:https://github.com/richzhang/PerceptualSimilarity

可学习感知图像块相似度(Learned Perceptual Image Patch Similarity, LPIPS)也称为“感知损失”(perceptual loss),用于度量两张图像之间的差别。

来源于CVPR2018的一篇论文《The Unreasonable Effectiveness of Deep Features as a Perceptual Metric》,该度量标准学习生成图像到Ground Truth的反向映射强制生成器学习从假图像中重构真实图像的反向映射,并优先处理它们之间的感知相似度。LPIPS 比传统方法(比如L2/PSNR, SSIM, FSIM)更符合人类的感知情况LPIPS的值越低表示两张图像越相似,反之,则差异越大。

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

LPIPS 图像相似性度量标准(感知损失)

         如图表示,每一组有三张图片,由传统的评价标准如L2、SSIM、PSNR等评价结果和人体认为的大不相同,这是传统方法的弊端。如果图片平滑,那么传统的评价方式则大概率会失效。而目前GAN尤其是VAE等生成模型生成结果都过于平滑。 而最后三行的评价为深度学习的方式,可以看到,通过神经网络(非监督、自监督、监督模型)提取特征的方式,并对特征差异进行计算能够有效进行评价,而且能够和人体评价相似。【LPIPS 比传统方法(比如L2/PSNR, SSIM, FSIM)更符合人类的感知情况。】

代码

★ 完整的PSNR + SSIM + LPIPS 代码看:图像质量评价指标: PSNR 和 SSIM 和 LPIPS_马鹏森的博客-CSDN博客_psnr范围

需要先安装lpips:

pip install lpips

command:python lpips_2dirs.py -dir0 ./input_images -dir1 ./output_images

import argparse
import os
import lpips

parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--dir0', type=str, default='./input_images')
parser.add_argument('--dir1', type=str, default='./output_images')
parser.add_argument('-v','--version', type=str, default='0.1')
opt = parser.parse_args()

## Initializing the model
loss_fn = lpips.LPIPS(net='alex', version=opt.version)

# the total list of images
files = os.listdir(opt.dir0)
i = 0
total_lpips_distance = 0
average_lpips_distance = 0
for file in files:

	try:
		# Load images
		img0 = lpips.im2tensor(lpips.load_image(os.path.join(opt.dir0,file)))
		img1 = lpips.im2tensor(lpips.load_image(os.path.join(opt.dir1,file)))

		if (os.path.exists(os.path.join(opt.dir0, file)), os.path.exists(os.path.join(opt.dir1, file))):
			i = i + 1

		# Compute distance
		current_lpips_distance = loss_fn.forward(img0, img1)
		total_lpips_distance = total_lpips_distance + current_lpips_distance

		print('%s: %.3f'%(file, current_lpips_distance))

	except Exception as e:
		print(e)

average_lpips_distance = float(total_lpips_distance) / i

print("The processed iamges is ", i , "and the average_lpips_distance is: %.3f" %average_lpips_distance)

文件夹目录为:

LPIPS 图像相似性度量标准(感知损失)

 注意:其中“input_images”和“output_images”中的文件名要一一对应,它们的名字要相同,也就是“input_images”中的1.png和“output_images”中的1.png进行求LPIPS

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

有真实参照的图像质量的客观评估指标:SSIM、PSNR和LPIPS – 知乎

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
xiaoxingxing的头像xiaoxingxing管理团队
上一篇 2023年2月17日 下午9:35
下一篇 2023年2月17日 下午9:35

相关推荐