【问题标题】:How to calculate "Average Precision and Ranking" for CBIR system如何计算 CBIR 系统的“平均精度和排名”
【发布时间】:2014-12-09 14:03:07
【问题描述】:

所以,因为我已经使用 RGB 直方图实现了基本的 cbir 系统。现在,我正在尝试生成平均精度和排名曲线。我需要知道,我的平均精度公式是否正确?以及如何计算平均排名?

Code:
% Dir: parent directory location for images folder c1, c2, c3
% inputImage: \c1\1.ppm
% For example to get P-R curve execute: CBIR('D:\visionImages','\c2\1.ppm');
function [  ] = demoCBIR( Dir,inputImage)
% Dir='D:\visionImages';
% inputImage='\c3\1.ppm';
tic;
S=strcat(Dir,inputImage);
Inp1=imread(S);
num_red_bins = 8;
num_green_bins = 8;
num_blue_bins = 8;
num_bins = num_red_bins*num_green_bins*num_blue_bins;

A = imcolourhist(Inp1, num_red_bins, num_green_bins, num_blue_bins);%input image histogram
srcFiles = dir(strcat(Dir,'\*.jpg'));  
B = zeros(num_bins, 100); % hisogram of other 100 images in category 1
ptr=1;
for i = 1 : length(srcFiles)
    filename = strcat(Dir,'\',srcFiles(i).name);
    I = imread(filename);% filter image
    B(:,ptr) = imcolourhist(I, num_red_bins, num_green_bins, num_blue_bins); 
    ptr=ptr+1;                                                   
end

%normal histogram intersection
a = size(A,2); b = size(B,2); 
K = zeros(a, b);
for i = 1:a
  Va = repmat(A(:,i),1,b);
  K(i,:) = 0.5*sum(Va + B - abs(Va - B));
end


  sims=K;
  for i=1: 100 % number of relevant images for dir 1
     relevant_IDs(i) = i;
  end

 num_relevant_images = numel(relevant_IDs);

 [sorted_sims, locs] = sort(sims, 'descend');
 locations_final = arrayfun(@(x) find(locs == x, 1), relevant_IDs);
 locations_sorted = sort(locations_final);
 precision = (1:num_relevant_images) ./ locations_sorted;
 recall = (1:num_relevant_images) / num_relevant_images;
 % generate Avg precision
 avgprec=sum(precision)/num_relevant_images;% avg precision formula
 plot(avgprec, 'b.-');
 xlabel('Category ID');
 ylabel('Average Precision');
 title('Average Precision Plot');
 axis([0 10 0 1.05]);
end 

【问题讨论】:

  • 为什么不使用标准的 trec_eval?
  • @Debasis - 虽然trec_eval 是比较精度和召回率的标准,但我相信这是必须在 MATLAB 中完成的家庭作业或某种类型的作业,因此将其转移到 @987654323 @ 不是一个选项。此外,您必须以非常具体的方式格式化您的输入。我也是 OP 正在使用的 MATLAB 中计算精度和召回率的代码的作者

标签: matlab image-processing computer-vision information-retrieval cbir


【解决方案1】:

是的,这是正确的。您只需将所有精度值相加并取平均值即可。这就是平均精度的定义。

平均精度只是一个数字(通常以百分比表示),它为您提供图像检索系统的整体性能。值越高,性能越好。 Precision-Recall 图为您提供有关系统执行方式的更详细的信息,但当您将许多图像检索系统一起比较时,平均精度很有用。无需绘制许多 PR 图来尝试比较许多检索系统的整体性能,您可以只使用一个表格来比较所有系统,并使用一个数字来指定每个系统的性能 - 即平均精度。

此外,绘制平均精度也没有任何意义。当科学论文中通常报告平均精度时,没有情节......只有一个值!我可以看到您绘制此图的唯一方法是如果您有一个条形图,其中y-axis 表示平均精度,而x-axis 表示您正在比较的检索系统。条形越高,准确度就越高。然而,一张显示所有不同检索系统的表格,每个系统都有它们的平均精度,这是非常合适的。这是大多数 CBIR 研究论文中惯用的做法。


为了解决您的其他问题,您可以使用平均精度来计算平均排名。计算您正在测试的所有检索系统的平均精度,然后根据该平均精度对它们进行排序。具有更高平均精度的系统将排名更高。

【讨论】:

    【解决方案2】:

    这是我们用来计算平均精度的。应该有一个随机化步骤,因为如果您在地面实况图像位于顶部的情况下为图像提供离散分数,您可能会遇到问题。

    function ap = computeAP(label, score, gt)
        rand_index = randperm(length(label));
        label2 = label(rand_index);
        score = score(rand_index);
        [~, sids] = sort(score, 'descend');
        label2 = label2(sids);
        ids = find(label2 == gt);
        ap = 0;
        for j = 1:length(ids)
            ap  = ap + j / (ids(j) * length(ids));
        end
        fprintf('%f \n', ap);
    end
    

    【讨论】:

    • 你能告诉我什么是“label”和“gt”吗?
    • gt 是基本事实,标签是您的算法预测的标签
    猜你喜欢
    • 2018-09-05
    • 2015-12-08
    • 2015-08-14
    • 1970-01-01
    • 2015-01-09
    • 1970-01-01
    • 2018-08-22
    • 1970-01-01
    • 2015-12-22
    相关资源
    最近更新 更多