R-CNN笔记3:rcnn_test.m文件

rcnn_test.m

function res = rcnn_test(rcnn_model, imdb, suffix)
% res = rcnn_test(rcnn_model, imdb, suffix)
%   Compute test results using the trained rcnn_model on the
%   image database specified by imdb. Results are saved
%   with an optional suffix.
%   使用由IMDB指定的图像数据库上训练的rcnn模型计算测试结果。结果会保存一个可选的后缀。

% AUTORIGHTS
% ---------------------------------------------------------
% Copyright (c) 2014, Ross Girshick
% 
% This file is part of the R-CNN code and is available 
% under the terms of the Simplified BSD License provided in 
% LICENSE. Please retain this notice and LICENSE if you use 
% this file (or any portion of it) in your project.
% ---------------------------------------------------------

conf = rcnn_config('sub_dir', imdb.name);
image_ids = imdb.image_ids;

% assume they are all the same
feat_opts = rcnn_model.training_opts;
num_classes = length(rcnn_model.classes);

if ~exist('suffix', 'var') || isempty(suffix)
  suffix = '';
else
  suffix = ['_' suffix];
end

try
  aboxes = cell(num_classes, 1);
  for i = 1:num_classes
    load([conf.cache_dir rcnn_model.classes{i} '_boxes_' imdb.name suffix]);
    aboxes{i} = boxes;
  end
catch
  aboxes = cell(num_classes, 1);
  box_inds = cell(num_classes, 1);
  for i = 1:num_classes
    aboxes{i} = cell(length(image_ids), 1);
    box_inds{i} = cell(length(image_ids), 1);
  end

  % heuristic that yields at most 100k pre-NMS boxes
  % per 2500 images
  % 启发式的在每2500幅图像上产生最多10万个pre-NMS窗口
  max_per_set = ceil(100000/2500)*length(image_ids);
  max_per_image = 100;
  top_scores = cell(num_classes, 1);
  thresh = -inf(num_classes, 1);
  box_counts = zeros(num_classes, 1);

  if ~isfield(rcnn_model, 'folds')
    folds{1} = 1:length(image_ids);
  else
    folds = rcnn_model.folds;
  end

  count = 0;
  for f = 1:length(folds)
    for i = folds{f}
      count = count + 1;
      fprintf('%s: test (%s) %d/%d\n', procid(), imdb.name, count, length(image_ids));
      d = rcnn_load_cached_pool5_features(feat_opts.cache_name, ...
          imdb.name, image_ids{i});
      if isempty(d.feat)
        continue;
      end
      d.feat = rcnn_pool5_to_fcX(d.feat, feat_opts.layer, rcnn_model);
      d.feat = rcnn_scale_features(d.feat, feat_opts.feat_norm_mean);
      % zs [n*20 single]
      zs = bsxfun(@plus, d.feat*rcnn_model.detectors(f).W, rcnn_model.detectors(f).B);

      for j = 1:num_classes
        boxes = d.boxes;
        z = zs(:,j);
        I = find(~d.gt & z > thresh(j));
        boxes = boxes(I,:);
        scores = z(I);
        % aboxes [20*1 cell]->[n*1 cell(n is images numbers)]->[m*5 single](boxes and scores)
        aboxes{j}{i} = cat(2, single(boxes), single(scores));
        [~, ord] = sort(scores, 'descend');

        ord = ord(1:min(length(ord), max_per_image));% where max_per_image = 100
        % 保存得分最高的min(length(ord), max_per_image(100))窗口
        % sboxes[20*1 cell]->[m*1 cell(m is images numbers)]->[100*5 single](boxes and scores)
        aboxes{j}{i} = aboxes{j}{i}(ord, :);
        % 保存得分最高的min(length(ord), max_per_image(100))窗口的索引
        box_inds{j}{i} = I(ord);

        box_counts(j) = box_counts(j) + length(ord);
        top_scores{j} = cat(1, top_scores{j}, scores(ord));
        top_scores{j} = sort(top_scores{j}, 'descend');
        if box_counts(j) > max_per_set
          top_scores{j}(max_per_set+1:end) = [];
          thresh(j) = top_scores{j}(end);
        end
      end
    end
  end

  for i = 1:num_classes
    % go back through and prune out detections below the found threshold
    for j = 1:length(image_ids)
      if ~isempty(aboxes{i}{j})
        I = find(aboxes{i}{j}(:,end) < thresh(i));
        aboxes{i}{j}(I,:) = [];
        box_inds{i}{j}(I,:) = [];
      end
    end

    save_file = [conf.cache_dir rcnn_model.classes{i} '_boxes_' imdb.name suffix];
    boxes = aboxes{i};
    inds = box_inds{i};
    save(save_file, 'boxes', 'inds');
    clear boxes inds;
  end
end

% ------------------------------------------------------------------------
% Peform AP evaluation
% ------------------------------------------------------------------------
for model_ind = 1:num_classes
  cls = rcnn_model.classes{model_ind};
  res(model_ind) = imdb.eval_func(cls, aboxes{model_ind}, imdb, suffix);
end

fprintf('\n~~~~~~~~~~~~~~~~~~~~\n');
fprintf('Results:\n');
aps = [res(:).ap]';
disp(aps);
disp(mean(aps));
fprintf('~~~~~~~~~~~~~~~~~~~~\n');
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如何在MATLAB中做出标签页的效果-test.m 刚才看到有会员朋友说matlab中控件少,math说ActiveX中多的是啊,于是我也就顺便打开ActiveX看看里面都有什么。突然看到个单词tabbed……难道这就是困扰我多日的标签页?(已经解决)遗憾的是不知道为什么在我这里这个Microsoft Tabbed Dialog Control 6.0(SP5)不能用,显示的错误是Error using--->feval。Error 类别未授权使用,所以我连预览也不能。哪位兄弟知道解决方法别忘了给我发个消息啊,言归正传,继续说标签页。到mathworks一搜,果然是有高人的。 关于标签页的制作给出了三种方法,第一种就不介绍给大家了,因为时间久远到现在改方法已经失效,但是也放在附件中供大家参考就是那个tab。第二种是让我眼前一亮的。使用方法是这样:首先建立一个figure,并在其中加入一个Text控件,需要注意的是这个text控件所在的位置就是将来标签页所在的位置,然后将附件中的tabpanel2.6中的文件放到figure同目录下,然后在命令行输入 tabpanel,第一个参数是figure的名字,第二个参数是刚才加入的text控件的tag。这时候等侯一下,会出现一个运行的figure和一个小面板,在面板上有几项分别是(从上到下从左到右)添加标签、编辑标签、更新标签、当前标签前移、当前标签后移、设置、信息。这是点击第一个,就可以添加标签页了,大家自己试试就明白了,然后可以设置标签的lable、尺寸、风格、排列、颜色……非常方便。如果点击编辑标签,出来一个新的GUIDE,别怀疑,就在上面添加控件就可以了,添加完保存然后回到这个小面板点击更新标签,刚才添加的控件就出现了。大家可以试试。 第三种方法是用matlab的一个函数:tabdlg,但是这个函数的使用帮助在新版本中已经没有了,因为以后的版本中要改变这个函数,不过还是有个列子是用这个函数创建标签页的,附件中的tabgui.m就是对应的程序,直接运行就可以,典型的matlab风格。各位可以仿照程序的编写方法在它的基础上创建控件。 另外还有一种方法,就是我前一阵子写程序时用的,就是与JAVA混合编程。这个就比较麻烦了,对JAVA甚至C 一窍不通的就掠过吧。这其中涉及到了JAVA的布局、容器、框架等等。附件中的text.m是对应的文件。 总是抑制不住自己冲动的心情想把好玩的东西告诉别人。见谅。 前三种方法转自mathworks 与JAVA混合的方法转自仿真论坛。 本人无才只能跟风。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值