FID(Fréchet Inception Distance)
是用来计算真实图像与生成图像的特征向量间距离的一种度量。如果FID值越小,则相似程度越高。最好情况即是FID=0,两个图像相同。

实际计算:
参考链接:https://machinelearningmastery.com/how-to-implement-the-frechet-inception-distance-fid-from-scratch/

# example of calculating the frechet inception distance in Keras
import numpy
import os
import cv2
import argparse
import torch
import numpy as np
from scipy.linalg import sqrtm
from keras.applications.inception_v3 import InceptionV3
from keras.applications.inception_v3 import preprocess_input# os.environ["TF_CPP_MIN_LOG_LEVEL"]='2' # 只显示 warning 和 Error
os.environ["TF_CPP_MIN_LOG_LEVEL"] = '3'   # 只显示 Error# calculate frechet inception distance
def calculate_fid(model, images1, images2):# calculate activationsact1 = model.predict(images1)act2 = model.predict(images2)# calculate mean and covariance statisticsmu1, sigma1 = act1.mean(axis=0), np.cov(act1, rowvar=False)mu2, sigma2 = act2.mean(axis=0), np.cov(act2, rowvar=False)# calculate sum squared difference between meansssdiff = numpy.sum((mu1 - mu2)**2.0)# calculate sqrt of product between covcovmean = sqrtm(np.dot(sigma1, sigma2))# check and correct imaginary numbers from sqrtif np.iscomplexobj(covmean):covmean = covmean.real# calculate scorefid = ssdiff + np.trace(sigma1 + sigma2 - 2.0 * covmean)return fiddef data_list(dirPath):generated_Dataset = []real_Dataset = []for root, dirs, files in os.walk(dirPath):for filename in sorted(files):  # sorted已排序的列表副本# 判断该文件是否是目标文件if "generated" in filename:generatedPath = root + '/' + filenamegeneratedImg = cv2.imread(generatedPath).astype('float32')generated_Dataset.append(generatedImg)# 对比图片路径realPath = root + '/' + filename.replace('generated', 'real')realImg = cv2.imread(realPath).astype('float32')real_Dataset.append(realImg)return generated_Dataset, real_Datasetif __name__ == '__main__':### 参数设定parser = argparse.ArgumentParser()# parser.add_argument('--dataset_dir', type=str, default='./results/hrnet/', help='results')parser.add_argument('--dataset_dir', type=str, default='./results/ssngan/', help='results')parser.add_argument('--name', type=str, default='sketch', help='name of dataset')opt = parser.parse_args()# 数据集dirPath = os.path.join(opt.dataset_dir, opt.name)generatedImg, realImg = data_list(dirPath)dataset_size = len(generatedImg)print("数据集:", dataset_size)images1 = torch.Tensor(generatedImg)images2 = torch.Tensor(realImg)print('shape: ', images1.shape, images2.shape)# 将全部数据集导入# prepare the inception v3 modelmodel = InceptionV3(include_top=False, pooling='avg')# pre-process images(归一化)images1 = preprocess_input(images1)images2 = preprocess_input(images2)# fid between images1 and images2fid = calculate_fid(model, images1, images2)print('FID : %.3f' % fid)print('FID_average : %.3f' % (fid / dataset_size))

图像相似度的评价指标 : FID(Fréchet Inception Distance)相关推荐

  1. 图像质量评价指标FID、LPIPS、NIQE及其代码

    文章目录 FID LPIPS NIQE FID FID的全称是Fréchet Inception Distance,用于衡量两个多元正态分布的距离,数值越小越好.具体的,FID使用Inception ...

  2. Frechet Inception Distance (FID)

    How to Implement the Frechet Inception Distance (FID) for Evaluating GANs github高分项目: https://github ...

  3. FID使用(Frechet Inception Distance score)

    何为 FID? Frechet Inception 距离(FID)是评估生成图像质量的度量标准,专门用于评估生成对抗网络的性能. FID 分数由 Martin Heusel 等人于 2017 年在论文 ...

  4. 【图像识别与处理】图像相似度对比的几种办法

    对计算图像相似度的方法,本文做了如下总结,主要有三种办法: 1.PSNR峰值信噪比 PSNR(Peak Signal to Noise Ratio),一种全参考的图像质量评价指标. 简介:https: ...

  5. OpenCV 进行图像相似度对比的几种办法-【顺带附py对比学习案例】

    最近研究了下计算机视觉.图像对比参考了一下py的一些源码和思路等信息学习学习. 但是呢只能对应相似度.稍微改一改剪切了图片后的就变化差异比较大,对目前自己的需求来说不是很有作用,顺带整理分享一下. 如 ...

  6. 【图像相关】图像质量评价指标 PSNR 和 SSIM

    文章目录 PSNR SSIM 参考链接 PSNR PSNR 是 "Peak Signal to Noise Ratio" 的缩写,即峰值信噪比,是一种评价图像的客观标准,它具有局限 ...

  7. 基于Python实现图像相似度检测【100010088】

    一.实验目的和要求 基于一张样板图片,对九张其他图像进行相似度的计算,得到"最相似"的一张图片.尝试多种算法,并对图像检索方法进行探索. 要求:基于 PIL 库或者 OpenCV ...

  8. 进行图像相似度对比的几种办法

    转载自 1.直方图方法 方法描述:有两幅图像patch(当然也可是整幅图像),分别计算两幅图像的直方图,并将直方图进行归一化,然后按照某种距离度量的标准进行相似度的测量. 方法的思想:基于简单的向量相 ...

  9. 基于Python实现的图像相似度检测

    资源下载地址:https://download.csdn.net/download/sheziqiong/85610752 一.实验目的和要求 基于一张样板图片,对九张其他图像进行相似度的计算,得到& ...

  10. r语言把两个折线图图像放到一个图里_图像相似度度量

    图像相似度度量的应用场景很多,包括以图搜图,相似图像去重等多种功能,目前在项目中的场景是针对大量重复类似的图片,需要进行筛选剔除,自然需要用到图像相似度,简单调研了下图像相似度的方法,包括传统图像方法 ...

最新文章

  1. UCL葡萄酒(red white wine quality)数据集字段解释、数据导入实战
  2. 图灵——2015技术类新书TOP20
  3. Quaternion.identity是什么意思?
  4. 阿里云ECS上环境搭建(virtualenv+flask+gunicorn+supervisor+nginx)
  5. ps修改dds贴图_「干货」喜爱3D游戏动漫建模的你,必备的次世代游戏贴图技巧...
  6. one order callback frequency
  7. MySQL查询结果导出到文件
  8. 查看SELinux状态
  9. Windows下Spring3.x计划任务实现定时备份MySql数据库
  10. 以“百钱买百鸡”问题练习使用 C语言 goto 语句
  11. Linux学习笔记8
  12. wkhtmltopdf中文显示空白或者乱码方框
  13. android网易云音乐api接口,网易云音乐API分析
  14. 自建网盘教程之:使用可道云搭建私有云网盘,无需数据库,windows操作界面
  15. abaqus2018+intel fortran2019+vs2015安装全记录
  16. cst和ansys_CST、HFSS、ADS几款电磁仿真软件区别对比
  17. QT报错 error: [debug/qrc_image.cpp] Error 1
  18. 大型C语言打怪小游戏——神魔
  19. 了解资本与公司年报、财报
  20. 靶向药物丨艾美捷西妥昔单抗Cetuximab方案

热门文章

  1. word单独编辑或者删除某一页的页眉
  2. 不同IP网段连接网络打印机
  3. .netcore获取微信openid与unionid方法
  4. 如何用卡诺图化简带有约束条件的逻辑函数?
  5. ORACLE计算同比环比
  6. mac HBux连接夜神模拟器
  7. 综合布线3D虚拟仿真教学实训平台
  8. SourceGenerator入门指北
  9. PS可以快速批量修改图片尺寸吗?
  10. 51单片机学习:串口通信实验