当前位置:   article > 正文

Python计算图像评价指标--Lpips_python 照片质量评分

python 照片质量评分

https://github.com/richzhang/PerceptualSimilarity

源代码链接如上

我的方法是首先安装lpips包

pip install lpips

安装成功之后,新建.py文件命名为lpips1文件

  1. # coding=gbk
  2. import cv2
  3. import lpips
  4. import torchvision.transforms as transforms
  5. import torch
  6. # 载入指标模型
  7. loss_fn_alex = lpips.LPIPS(net='alex') # best forward scores
  8. loss_fn_vgg = lpips.LPIPS(net='vgg') # closer to "traditional" perceptual loss, when used for optimization
  9. # 读取图片
  10. test1 = cv2.imread('1.png')
  11. test2 = cv2.imread('2.png')
  12. # 分割目标图片
  13. test1_org = test1[:, :512, :] / 255 # 原始图片
  14. test1_res = test1[:, 512:1024, :] / 255 # 模型输出结果
  15. test1_label = test1[:, 1024:1536, :] / 255 # label图片
  16. test2_org = test2[:, :512, :] / 255
  17. test2_res = test2[:, 512:1024, :] / 255
  18. test2_label = test2[:, 1024:1536, :] / 255
  19. # 转为tensor
  20. transf = transforms.ToTensor()
  21. test1_org = transf(test1_org)
  22. test1_res = transf(test1_res)
  23. test1_label = transf(test1_label)
  24. test2_org = transf(test2_org)
  25. test2_res = transf(test2_res)
  26. test2_label = transf(test2_label)
  27. # 转换数据类型
  28. test1_orgg = test1_org.to(torch.float32)
  29. test1_ress = test1_res.to(torch.float32)
  30. test1_labell = test1_label.to(torch.float32)
  31. test2_orgg = test2_org.to(torch.float32)
  32. test2_ress = test2_res.to(torch.float32)
  33. test2_labell = test2_label.to(torch.float32)
  34. # 测试
  35. d11 = loss_fn_alex(test1_ress, test1_labell)
  36. d12 = loss_fn_alex(test1_ress, test2_labell)
  37. print('d11:', d11)
  38. print('d12:', d12)
  39. d22 = loss_fn_alex(test2_ress, test2_labell)
  40. d21 = loss_fn_alex(test2_ress, test1_labell)
  41. print('d22:', d22)
  42. print('d121:', d21)

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/192891
推荐阅读
相关标签
  

闽ICP备14008679号