-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpascal_train.m
69 lines (58 loc) · 1.75 KB
/
pascal_train.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
function model = pascal_train(cls, n)
% model = pascal_train(cls)
% Train a model using the PASCAL dataset.
'loading data...'
globals;
[pos, neg] = pascal_data(cls);
allNeg = neg;
cacheFeaturePyramids(pos, 8, 5); % sbin 8, interval 10
cacheFeaturePyramids(neg, 8, 5); % sbin 8, interval 10
spos = split(pos, n);
models = cell(1,n);
% train root filter using warped positives & random negatives
'training root filter...'
try
load([cachedir cls '_random']);
catch
for i=1:n
models{i} = initmodel(spos{i});
models{i} = train_old(cls, models{i}, spos{i}, neg);
end
save([cachedir cls '_random'], 'models');
end
% PUT YOUR CODE HERE
% TODO: Train the rest of the DPM (latent root position, part filters, ...)
% merge models and train using latent detections & hard negatives
'training on hard negative and latent root positions...'
try
load([cachedir cls '_hard']);
catch
model = mergemodels(models);
neg = updateNegCache(allNeg, neg, model, 4*length(pos));
model = train(cls, model, pos, neg);
save([cachedir cls '_hard'], 'model');
end
'training with parts'
% add parts and update models using latent detections & hard negatives.
try
load([cachedir cls '_parts']);
catch
for i=1:n
model = initParts(model, i, 6);
end
neg = updateNegCache(allNeg, neg, model, 4*length(pos));
model = train(cls, model, pos, neg);
save([cachedir cls '_parts', 'model');
end
'training multi iter'
% ONLY FOR MULTI-ITERATION
TRAINING_ITER = 1;
try
load([cachedir cls '_parts2']); % change this to
catch
for training_iter = 1:TRAINING_ITER
neg = updateNegCache(allNeg, neg, model, 4*length(pos));
model = train(cls, model, pos, neg);
save([cachedir cls '_parts2'], 'model');
end
end