显著性检测模型评价指标(一)——ROC曲线和AUC

显著性检测模型评价指标(一)——ROC曲线和AUC

  • 一、准备知识
  • 二、ROC曲线和AUC
  • 三、matlab代码

本人最近在做视觉显著性检测相关的工作,决定把自己的学习经历形成文字,希望对读者有所帮助。
笔者才疏学浅,文章中如有不当之处,还请读者指正,在此表示感谢。

一、准备知识

在了解什么是ROC曲线和AUC之前,首先要具备一些准备知识。
想象一个二元分类问题,在实际的数据中,一部分数据标签为1(正),剩下的数据标签为0(负)。现在有一个模型,要对该问题的结果进行预测,将其中一部分数据预测为1(正),另一部分数据预测为0(负)。那么存在以下定义:

TP(True Positive) :预测值为正,且真实值为正。
FP(False Positive) :预测值为正,但真实值为负。
TPR(True Positive Rate) :TPR=TP/(TP+FN),真正率。实际为正且被正确预测为正 与 实际为正 的比例。
FPR(False Positive Rate):FPR=FP/(FP+TN),假正率。实际为负但被错误预测为正 与 实际为负 的比例。

二、ROC曲线和AUC

了解上述准备知识以后,显著性检测模型的ROC曲线如何获得呢?
假设已经存在一个模型,对一幅图像进行检测后,将得到一张Saliency Map(SM),一般的数据集会附带根据真实测试者所得到的Fixation Map(FM,即所谓的真值)。FM会将图像中的显著性区域标记为1(或255),将非显著性区域标记为0。而SM得到的是一幅0到255之间的灰度图。我们把0到255中的每一个灰度值当作一个阈值,对SM图像进行分类,若像素在阈值之上,则标记为1(或255),在阈值之下标记为0。这样对于每个阈值,可以计算出对应的TPR和FPR。遍历0到255,则会产生256组TPR及其对应的FPR。将这256组数据以FPR为横轴,TPR为纵轴画出,即可得到ROC曲线(Receiver Operating Characteristic)。计算ROC曲线下的面积,即可得到AUC(Area Under ROC Curve)。AUC的值越大,表示该模型效果越好。

三、matlab代码

以下给出计算AUC的matlab代码。
该代码作者信息请见注释,如有使用请注明出处。
在此给出下载地址。

% created: Tilke Judd, Oct 2009
% updated: Zoya Bylinskii, Aug 2014

% This measures how well the saliencyMap of an image predicts the ground
% truth human fixations on the image. 

% ROC curve created by sweeping through threshold values 
% determined by range of saliency map values at fixation locations;
% true positive (tp) rate correspond to the ratio of saliency map values above 
% threshold at fixation locations to the total number of fixation locations
% false positive (fp) rate correspond to the ratio of saliency map values above 
% threshold at all other locations to the total number of posible other
% locations (non-fixated image pixels)

function [score,tp,fp,allthreshes] = AUC_Judd(saliencyMap, fixationMap, jitter, toPlot)
% saliencyMap is the saliency map
% fixationMap is the human fixation map (binary matrix)
% jitter = 1 will add tiny non-zero random constant to all map locations
% to ensure ROC can be calculated robustly (to avoid uniform region)
% if toPlot=1, displays ROC curve

if nargin < 4, toPlot = 0; end
if nargin < 3, jitter = 1; end
score = nan;

% If there are no fixations to predict, return NaN
if ~any(fixationMap)
    disp('no fixationMap');
    return
end 

% make the saliencyMap the size of the image of fixationMap
if size(saliencyMap, 1)~=size(fixationMap, 1) || size(saliencyMap, 2)~=size(fixationMap, 2)
    saliencyMap = imresize(saliencyMap, size(fixationMap));
end

% jitter saliency maps that come from saliency models that have a lot of
% zero values.  If the saliency map is made with a Gaussian then it does 
% not need to be jittered as the values are varied and there is not a large 
% patch of the same value. In fact jittering breaks the ordering 
% in the small values!
if jitter
    % jitter the saliency map slightly to distrupt ties of the same numbers
    saliencyMap = saliencyMap+rand(size(saliencyMap))/10000000;
end

% normalize saliency map
saliencyMap = (saliencyMap-min(saliencyMap(:)))/(max(saliencyMap(:))-min(saliencyMap(:)));

if sum(isnan(saliencyMap(:)))==length(saliencyMap(:))
    disp('NaN saliencyMap');
    return
end

S = saliencyMap(:);
F = fixationMap(:);
   
Sth = S(F>0); % sal map values at fixation locations
Nfixations = length(Sth);
Npixels = length(S);

allthreshes = sort(Sth, 'descend'); % sort sal map values, to sweep through values
tp = zeros(Nfixations+2,1);
fp = zeros(Nfixations+2,1);
tp(1)=0; tp(end) = 1; 
fp(1)=0; fp(end) = 1;

for i = 1:Nfixations
    thresh = allthreshes(i);
    aboveth = sum(S >= thresh); % total number of sal map values above threshold
    tp(i+1) = i / Nfixations; % ratio sal map values at fixation locations above threshold
    fp(i+1) = (aboveth-i) / (Npixels - Nfixations); % ratio other sal map values above threshold
end 

score = trapz(fp,tp);
allthreshes = [1;allthreshes;0];

if toPlot
    subplot(121); imshow(saliencyMap, []); title('SaliencyMap with fixations to be predicted');
    hold on;
    [y, x] = find(fixationMap);
    plot(x, y, '.r');
    subplot(122); plot(fp, tp, '.b-');   title(['Area under ROC curve: ', num2str(score)])
end

你可能感兴趣的:(视觉显著性)