位置:- 正文

GAN评价指标代码(FID、LPIPS、MS-SSIM)(评价指标mae)

编辑:rootadmin
GAN评价指标代码(FID、LPIPS、MS-SSIM) GAN评价指标代码(FID、LPIPS、MS-SSIM写在前面FIDLPIPSMS-SSIM写在后面写在前面

推荐整理分享GAN评价指标代码(FID、LPIPS、MS-SSIM)(评价指标mae),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:评价指标计算公式,gan评价标准,评价指标f1,评价指标mae,评价指标公式,评价指标mae,评价指标什么意思,评价指标系统,内容如对您有帮助,希望把文章链接给更多的朋友!

科研需要,对GAN生成的图片要做定量评价,因此总结一些自己要用到的一些评价指标。

FID

官方链接:https://github.com/mseitzer/pytorch-fid

描述:FID越小,表示生成图片越多样、质量越好。

步骤: (1)先下载pytorch-fid

pip install pytorch-fid

(2)执行命令

python -m pytorch_fid path/dataset1/test/images path/dataset2/test/imagesGAN评价指标代码(FID、LPIPS、MS-SSIM)(评价指标mae)

参数: path/dataset1/test/images是真实图像路径 path/dataset2/test/images是生成图像路径

注意: 有个额外的参数--dims N,其中 N 是特征的维度,一共有64、192、768、2048(默认)这四种,表示的是使用Inception的哪一层去测试,一般默认都是2048即最终平均池化特征去测试。 但是官方说如果测试的样本少于2048个可以用–dims这个参数,但这会改变FID分数的大小,因此只有–dims相同时跑出来的分数才有可比性。 不过我看TensorFlow那边的FID说,建议使用10,000的最小样本量来计算 FID,否则会低估生成器的真实FID。所以如果样本量太少建议不使用FID这个指标。

LPIPS

官方链接:https://github.com/richzhang/PerceptualSimilarity 描述:LPIPS越高意味着图片与原图更多不同,越低意味着与原图更相似

步骤: (1)下载LPIPS代码 (2)执行命令

python lpips_2dirs.py -d0 imgs/ex_dir0 -d1 imgs/ex_dir1 -o imgs/example_dists.txt --use_gpu

参数: -d0是真实图像路径 -d1是生成图像路径 -o是输出的结果保存位置

MS-SSIM

链接:https://blog.csdn.net/m0_63642362/article/details/123297405 描述:接近1的值表示更好的图像质量,接近0的值表示较差的质量

代码 把生成图片放在imgs/fake_img路径下,把真实图片放在imgs/real_img路径下,然后运行即可

import osimport cv2import paddlefrom paddle_msssim import ssim, ms_ssimdef file_name(file_dir): img_path_list = [] for root, dirs, files in os.walk(file_dir): for file in files: img_path_list.append((os.path.join(root, file),file)) return img_path_listdef imread(img_path): img = cv2.imread(img_path) return paddle.to_tensor(img.transpose(2, 0, 1)[None, ...], dtype=paddle.float32)if __name__ == '__main__': file_dir = 'imgs/fake_img' # 伪造图像路径 target_dir = 'imgs/real_img' # 真实图像路径 img_path_list = file_name(file_dir) target_path_list = file_name(target_dir) d = 0 for i in range(img_path_list.__len__()): (img_path, img_name) = img_path_list[i] (target_path, target_name) = target_path_list[i] print(img_path) print(target_path) fake = imread(img_path) real = imread(target_path) distance = ms_ssim(real, fake).cpu().numpy() print(distance) d += distanceprint('average ms_ssim')print(d/img_path_list.__len__())写在后面

你笑我徒劳,而我一个人在路上,走完的四季,确实你永远体会不到的风景。 -----《愿有人陪你颠沛流离》

本文链接地址:https://www.jiuchutong.com/zhishi/289004.html 转载请保留说明!
下一篇链接:https://www.jiuchutong.com/zhishi/289005.html
免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络