forked from vedaldi/practical-object-category-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise3.m
82 lines (63 loc) · 2.2 KB
/
exercise3.m
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
% EXERCISE3
setup ;
% Feature configuration
hogCellSize = 8 ;
numHardNegativeMiningIterations = 3 ;
minScale = -1 ;
maxScale = 3 ;
numOctaveSubdivisions = 3 ;
scales = 2.^linspace(...
minScale,...
maxScale,...
numOctaveSubdivisions*(maxScale-minScale+1)) ;
% Load data
load('data/signs-model-2.mat','w','targetClass') ;
loadData(targetClass) ;
% -------------------------------------------------------------------------
% Step 3.1: Multiple detections
% -------------------------------------------------------------------------
im = imread(testImages{3}) ;
im = im2single(im) ;
% Compute detections
[detections, scores] = detect(im, w, hogCellSize, scales) ;
% Non-maxima suppression
keep = boxsuppress(detections, scores, 0.25) ;
detections = detections(:, keep) ;
scores = scores(keep) ;
% Further keep only top detections
detections = detections(:, 1:10) ;
scores = scores(1:10) ;
% Plot top detection
figure(10) ; clf ;
imagesc(im) ; axis equal ;
hold on ;
vl_plotbox(detections, 'g', 'linewidth', 2, ...
'label', arrayfun(@(x)sprintf('%.2f',x),scores,'uniformoutput',0)) ;
title('Multiple detections') ;
% -------------------------------------------------------------------------
% Step 3.2: Detector evaluation
% -------------------------------------------------------------------------
% Find all the objects in the target image
s = find(strcmp(testImages{3}, testBoxImages)) ;
gtBoxes = testBoxes(:, s) ;
% No example is considered difficult
gtDifficult = false(1, numel(s)) ;
% PASCAL-like evaluation
matches = evalDetections(...
gtBoxes, gtDifficult, ...
detections, scores) ;
% Visualization
figure(1) ; clf ;
imagesc(im) ; axis equal ; hold on ;
vl_plotbox(detections(:, matches.detBoxFlags==+1), 'g', 'linewidth', 2) ;
vl_plotbox(detections(:, matches.detBoxFlags==-1), 'r', 'linewidth', 2) ;
vl_plotbox(gtBoxes, 'b', 'linewidth', 1) ;
axis off ;
figure(2) ; clf ;
vl_pr(matches.labels, matches.scores) ;
% -------------------------------------------------------------------------
% Step 3.3: Evaluation on multiple images
% -------------------------------------------------------------------------
figure(3) ; clf ;
matches = evaluateModel(testImages, testBoxes, testBoxImages, ...
w, hogCellSize, scales) ;