IoU vs Dice vs F1-score
创始人
2025-06-01 10:36:48
0

除了我们熟知的miou指标外,Dice,F1-score这2个指标也是分割问题中常用的指标。

P(Precision) = TP/(TP + FP);

R(Recall) = TP/(TP + FN);

IoU = TP/(TP + FP + FN)

DICE (dice coefficient) = 2*TP/(FP + FN + 2 * TP)=2*IoU/(IoU+1)

F1-score = (2*P*R)/(P + R)=2*TP/(FP + FN + 2 * TP)=DICE

按照公式来看,其实Dice==F1-score

但是我看论文里面虽然提供的公式是我上面贴的公式,但是他们的两个数值完全不一样,甚至还相差较大。

比如:这篇论文提供了权重和代码,我测出来的两个数值也是一样的,而且代码里面的计算公式和上面贴的公式一样,但是论文中给出来的结果就不一样了。

 还有这篇,这篇没有权重但是论文里写了公式 

那么这个是怎么造成的呢?

其实这里的dice准确的说叫soft dice,出自论文V-Net: Fully Convolutional Neural Networks for Volumetric Medical Image Segmentation,

Fbeta_score=(1 + beta2)*TP/[ beta2 *(TP+FN)+(TP+FP)] = (1 + beta2)* (true * pred) / [beta2 *true + pred]

F1_score=2*TP/[(TP+FN)+(TP+FP)] = 2* (true * pred) / [true + pred]

Dice = 2* (true * pred_score) / [true*true + pred_score* pred_score]

两个公式的区别,就是Dice使用的不是预测的结果pred,而是预测的结果的得分pred_score,并且做了平方操作。

这样最终算下来,就会得到Dice>F1_score

实现代码如下,github链接GitHub - miaotianyi/pytorch-confusion-matrix: Differentiable precision, recall, F-beta score, F1 score, and dice loss for input tensors of real-valued probabilities

 

def f_beta(y_true, y_pred, reduce_axes, beta=1., epsilon=1e-6):"""Differentiable F-beta scoreF_beta = (1 + beta^2) * TP / [beta^2 * (TP + FN) + (TP + FP)]= (1 + beta^2) (true * pred) / [beta^2 * true + pred]Using this formula, we don't have to use precision and recall.F1 score is an example of F-beta score with beta=1."""beta2 = beta ** 2   # beta squarednumerator = (1 + beta2) * (y_true * y_pred).sum(reduce_axes)denominator = beta2 * y_true.sum(reduce_axes) + y_pred.sum(reduce_axes)denominator = denominator.clamp(min=epsilon)return numerator / denominatordef dice(y_true, y_pred, reduce_axes, beta=1., epsilon=1e-6):"""Compute soft dice coefficient according to V-Net paper.(https://arxiv.org/abs/1606.04797)Unlike F-beta score, dice uses squared probabilitiesinstead of probabilities themselves for denominator.Due to the squared entries, gradients will be y_true and y_pred instead of 1."""beta2 = beta ** 2   # beta squarednumerator = (1 + beta2) * (y_true * y_pred).sum(reduce_axes)denominator = beta2 * y_true.square().sum(reduce_axes) + y_pred.square().sum(reduce_axes)denominator = denominator.clamp(min=epsilon)return numerator / denominator

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
有效的括号 一、题目 给定一个只包括 '(',')','{','}'...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
【Ctfer训练计划】——(三... 作者名:Demo不是emo  主页面链接:主页传送门 创作初心ÿ...