-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitmodel_old.m
113 lines (103 loc) · 2.58 KB
/
initmodel_old.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
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
function model = initmodel(pos, sbin, size)
% model = initmodel(pos, sbin, size)
% Initialize model structure.
%
% If not supplied the dimensions of the model template are computed
% from statistics in the postive examples.
%
% This should be documented! :-)
% model.sbin
% model.interval
% model.numblocks
% model.numcomponents
% model.blocksizes
% model.regmult
% model.learnmult
% model.maxsize
% model.minsize
% model.rootfilters{i}
% .size
% .w
% .blocklabel
% model.partfilters{i}
% .w
% .blocklabel
% model.defs{i}
% .anchor
% .w
% .blocklabel
% model.offsets{i}
% .w
% .blocklabel
% model.components{i}
% .rootindex
% .parts{j}
% .partindex
% .defindex
% .offsetindex
% .dim
% .numblocks
% pick mode of aspect ratios
h = [pos(:).y2]' - [pos(:).y1]' + 1;
w = [pos(:).x2]' - [pos(:).x1]' + 1;
xx = -2:.02:2;
filter = exp(-[-100:100].^2/400);
aspects = hist(log(h./w), xx);
aspects = convn(aspects, filter, 'same');
[peak, I] = max(aspects);
aspect = exp(xx(I));
% pick 20 percentile area
areas = sort(h.*w);
area = areas(floor(length(areas) * 0.2));
area = max(min(area, 5000), 3000);
% pick dimensions
w = sqrt(area/aspect);
h = w*aspect;
% size of HOG features
if nargin < 4
model.sbin = 8;
else
model.sbin = sbin;
end
% size of root filter
if nargin < 5
model.rootfilters{1}.size = [round(h/model.sbin) round(w/model.sbin)];
else
model.rootfilters{1}.size = size;
end
% set up offset
model.offsets{1}.w = 0;
model.offsets{1}.blocklabel = 1;
model.blocksizes(1) = 1;
model.regmult(1) = 0;
model.learnmult(1) = 20;
model.lowerbounds{1} = -100;
% set up root filter
model.rootfilters{1}.w = zeros([model.rootfilters{1}.size 31]);
height = model.rootfilters{1}.size(1);
% root filter is symmetric
width = ceil(model.rootfilters{1}.size(2)/2);
model.rootfilters{1}.blocklabel = 2;
model.blocksizes(2) = width * height * 31;
model.regmult(2) = 1;
model.learnmult(2) = 1;
model.lowerbounds{2} = -100*ones(model.blocksizes(2),1);
% set up one component model
model.components{1}.rootindex = 1;
model.components{1}.rootidx = 1;
model.components{1}.offsetindex = 1;
model.components{1}.offsetidx = 1;
model.components{1}.parts = {};
model.components{1}.dim = 2 + model.blocksizes(1) + model.blocksizes(2);
model.components{1}.numblocks = 2;
% initialize the rest of the model structure
model.numparts = 6;
model.interval = 10;
model.numcomponents = 1;
model.numblocks = 2;
model.partfilters = {};
model.defs = {};
model.maxsize = model.rootfilters{1}.size;
model.minsize = model.rootfilters{1}.size;
model.padx = ceil(model.maxsize(2)/2+1);
model.pady = ceil(model.maxsize(1)/2+1);