forked from quantombone/exemplarsvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esvm_demo_train_voc_class_fast.m
140 lines (107 loc) · 4.58 KB
/
esvm_demo_train_voc_class_fast.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
% DEMO: PASCAL VOC "mini" training/testing script
% This function can generate a nice HTML page by calling:
% publish('esvm_demo_train_voc_class_fast.m','html')
%
% Copyright (C) 2011-12 by Tomasz Malisiewicz
% All rights reserved.
%
% This file is part of the Exemplar-SVM library and is made
% available under the terms of the MIT license (see COPYING file).
% Project homepage: https://github.com/quantombone/exemplarsvm
function [models,M] = esvm_demo_train_voc_class_fast(cls, ...
data_directory, ...
dataset_directory, ...
results_directory)
addpath(genpath(pwd));
if ~exist('cls','var')
fprintf(1,'esvm_demo_train_fast: defaulting to class=car\n');
cls = 'car';
end
if ~exist('data_directory','var')
data_directory = '/Users/tomasz/projects/pascal/';
end
if ~exist('dataset_directory','var')
dataset_directory = 'VOC2007';
end
if ~exist('results_directory','var')
%results_directory = '';
results_directory = sprintf(['/nfs/baikal/tmalisie/esvm-%s-' ...
'%s-fast/'], ...
dataset_directory, cls);
end
%data_directory = '/Users/tomasz/projects/Pascal_VOC/';
%results_directory = '/nfs/baikal/tmalisie/esvm-data/';
%data_directory = '/csail/vision-videolabelme/people/tomasz/VOCdevkit/';
%results_directory = sprintf('/csail/vision-videolabelme/people/tomasz/esvm-%s/',cls);
dataset_params = esvm_get_voc_dataset(dataset_directory,...
data_directory,...
results_directory);
dataset_params.display = 1;
%dataset_params.dump_images = 1;
% Issue warning if lock files are present
lockfiles = check_for_lock_files(results_directory);
if length(lockfiles) > 0
fprintf(1,'WARNING: %d lockfiles present in current directory\n', ...
length(lockfiles));
end
%KILL_LOCKS = 1;
%for i = 1:length(lockfiles)
% unix(sprintf('rmdir %s',lockfiles{i}));
%end
%% Set exemplar-initialization parameters
params = esvm_get_default_params;
params.model_type = 'exemplar';
params.dataset_params = dataset_params;
%Initialize exemplar stream
stream_params.stream_set_name = 'trainval';
stream_params.stream_max_ex = 1;
stream_params.must_have_seg = 0;
stream_params.must_have_seg_string = '';
stream_params.model_type = 'exemplar'; %must be scene or exemplar;
stream_params.cls = cls;
%Create an exemplar stream (list of exemplars)
e_stream_set = esvm_get_pascal_stream(stream_params, ...
dataset_params);
neg_set = esvm_get_pascal_set(dataset_params, ['train-' cls]);
%Choose a models name to indicate the type of training run we are doing
models_name = ...
[cls '-' params.init_params.init_type ...
'.' params.model_type];
initial_models = esvm_initialize_exemplars(e_stream_set, params, models_name);
%% Perform Exemplar-SVM training
train_params = params;
train_params.detect_max_scale = 0.5;
train_params.train_max_mined_images = 50;
train_params.detect_exemplar_nms_os_threshold = 1.0;
train_params.detect_max_windows_per_exemplar = 100;
%% Train the exemplars and get updated models name
[models,models_name] = esvm_train_exemplars(initial_models, ...
neg_set, train_params);
val_params = params;
val_params.detect_exemplar_nms_os_threshold = 0.5;
val_params.gt_function = @esvm_load_gt_function;
val_set_name = ['trainval+' cls];
val_set = esvm_get_pascal_set(dataset_params, val_set_name);
val_set = val_set(1:40);
%% Apply trained exemplars on validation set
val_grid = esvm_detect_imageset(val_set, models, val_params, val_set_name);
%% Perform Platt calibration and M-matrix estimation
M = esvm_perform_calibration(val_grid, val_set, models, ...
val_params);
%% Define test-set
test_params = params;
test_params.detect_exemplar_nms_os_threshold = 0.5;
test_set_name = ['test+' cls];
test_set = esvm_get_pascal_set(dataset_params, test_set_name);
test_set = test_set(1:100);
%% Apply on test set
test_grid = esvm_detect_imageset(test_set, models, test_params, test_set_name);
%% Apply calibration matrix to test-set results
test_struct = esvm_pool_exemplar_dets(test_grid, models, M, test_params);
%% Show top detections
maxk = 20;
allbbs = esvm_show_top_dets(test_struct, test_grid, test_set, models, ...
params, maxk, test_set_name);
%% Perform the exemplar evaluation
[results] = esvm_evaluate_pascal_voc(test_struct, test_grid, params, ...
test_set_name, cls, models_name);