二维图像Dice系数计算
2022/1/3 6:15:39
本文主要是介绍二维图像Dice系数计算,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
项目场景:计算二维图像的Dice系数
问题描述:
通常我们用目标分割网络,预测结果后。为了得知网络的准确度,可以计算其Dice系数,通过比较其系数,可以得知网络的准确性。
import numpy as np import cv2 from PIL import Image if __name__ == '__main__': y_true_path = 'E:/AI-challenge/2021/results/label_show/'(这个是标签的文件地址) y_pred_path = 'E:/AI-challenge/2021/results/predict/'(这个是预测后的图像输出地址) dice_list = [] for i in range(398): y_true = np.array(Image.open(y_true_path+str(i+1)+'.jpg')) y_pred = cv2.imread(y_pred_path+str(i+1)+'.jpg',cv2.IMREAD_GRAYSCALE) y_true = y_true/255 y_pred = y_pred/255 union = y_true * y_pred dice = 2*np.sum(union)/(np.sum(y_true)+np.sum(y_pred)) dice_list.append(dice) print(i+1, ' ', dice, '\n') print(dice_list) print(np.mean(np.array(dice_list))) }
运行结果:
这样就可以求出每张图片对应的Dice系数。
这篇关于二维图像Dice系数计算的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-25Elevate Your Lead Generation Game with Maps Scraper AI
- 2024-05-15PingCAP 黄东旭参与 CCF 秀湖会议,共探开源教育未来
- 2024-05-13PingCAP 戴涛:构建面向未来的金融核心系统
- 2024-05-09flutter3.x_macos桌面os实战
- 2024-05-09Rust中的并发性:Sync 和 Send Traits
- 2024-05-08使用Ollama和OpenWebUI在CPU上玩转Meta Llama3-8B
- 2024-05-08完工标准(DoD)与验收条件(AC)究竟有什么不同?
- 2024-05-084万 star 的 NocoDB 在 sealos 上一键起,轻松把数据库编程智能表格
- 2024-05-08Mac 版Stable Diffusion WebUI的安装
- 2024-05-08解锁CodeGeeX智能问答中3项独有的隐藏技能