File size: 3,646 Bytes
d4035c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
function [conf, jobId] = bk_testAppModel(conf, varargin)
% BK_TESTAPPMODEL
%
%  modelDirs:    one for each class
%  roiDir:       where to find GT rois
%
%  Author:: Andrea Vedaldi

% AUTORIGHTS
% Copyright (C) 2008-09 Andrea Vedaldi
%
% This file is part of the VGG MKL Class and VGG MKL Det code packages,
% available in the terms of the GNU General Public License version 2.

conf_.kerDir         = '' ;
conf_.kerDb          = struct ;
conf_.trainHistDir   = '' ;
conf_.testRoiDbPath  = '' ;
conf_.testHistDir    = '' ;
conf_.modelPath      = '' ;
conf_.noClobber      = false ;

if nargin == 0, conf = conf_ ; return ; end
conf = override(conf_, conf, 1) ;

[jobId, taskId] = parallelDriver('numNodes', 1, ...
                                 'freeMemMb', 2 * 1024, ...
                                 varargin{:} );

if ~isnan(jobId) & isnan(taskId) ; return ; end

% --------------------------------------------------------------------
%                                      Process all classes and aspects
% --------------------------------------------------------------------

rand('state', 0) ;
randn('state', 0) ;

scorePath = fullfile(conf.testHistDir, 'test-scores.mat') ;
if conf.noClobber & checkFile(scorePath)
  fprintf('\tSkipping to avoid clobbering ''%s''.\n', ...
          scorePath) ;
  return ;
end
  
% --------------------------------------------------------------------
%                                                          Load pieces
% --------------------------------------------------------------------

% Test ROI DB ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fprintf('\tLoading testing ROI DB ''%s''.\n', ...
        conf.testRoiDbPath) ;
tsdb = load(conf.testRoiDbPath) ;

% Model ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fprintf('\tLoading appearance model ''%ss''.\n', ...
        conf.modelPath) ;
model  = load(conf.modelPath) ;

% Kernel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
base = loadTestMixedKernel(conf.kerDir, conf.kerDb, model.d, model.svind) ;

% ------------------------------------------------------------------
%                                                            Test it
% ------------------------------------------------------------------

scores = model.alphay' * base + model.b ;

scorePath = fullfile(conf.testHistDir, 'test-scores.mat') ;
fprintf('\tSaving scores to ''%s''.\n', scorePath) ;
ssave(scorePath, 'scores') ;

figure(100) ; clf ; hold on ;
[recall,precision,info] = pr(tsdb.labels, scores) ;
plot(recall,precision,'b-','linewidth',2) ;
grid on ;
xlim([0 1]) ;
ylim([0 1]) ;
xlabel('recall') ;
ylabel('precision') ;
title(sprintf('PR on test ROI DB - AUC: %.2f %% (%.2f %%)', ...
              info.auc, info.auc_pa08)) ;
axis square ;
drawnow ;

figPath = fullfile(conf.testHistDir, 'test-pr.eps') ;
printsize(.97 + 0.001*randn) ; % ugly hack for matlab repeat 
print('-depsc', figPath) ;

% ------------------------------------------------------------------
function base =  loadTestMixedKernel(kerDir, kernels, weights, svs)
% ------------------------------------------------------------------

base = [] ;
K = length(kernels) ;
for ki = 1:K
  kerPath = fullfile(kerDir, ['test-' kernels(ki).name '.mat']) ;
  fprintf('\tLoading kernel matrix ''%s''.\n', kerPath) ;
  kernels_ = load(kerPath) ;

  % only SVs
  kernels_.matrix = kernels_.matrix(svs, :) ;    

  % accumulate to base
  if isempty(base)
    base = zeros(size(kernels_.matrix)) ;
  end
  base = base + weights(ki) * kernels_.matrix ;  
end

info = whos('base') ;
fprintf('\tKernel matrix size %.2f GB\n', info.bytes / 1024^3) ;
clear info ;