Permalink
Browse files

update function names again

  • Loading branch information...
1 parent 54ad76c commit 0ffe88d67c77bd0cfce101f031bba99327b4058b @quantombone quantombone committed Jan 18, 2012
@@ -1,7 +1,9 @@
-function esvm_apply_and_show_exemplars(imageset, models, M)
+function esvm_apply_and_show_exemplars(imageset, models, M, params)
% We apply the ensemble of Exemplar-SVMs represented by [models,M] onto
% the sequence of images [imageset], and display images without
-% saving anything
+% saving anything. Takes as input optional [params], which default
+% to the default ones.
+%
% Copyright (C) 2011-12 by Tomasz Malisiewicz
% All rights reserved.
%
@@ -36,7 +38,10 @@ function esvm_apply_and_show_exemplars(imageset, models, M)
end
end
-params = esvm_get_default_params;
+if ~exist('params','var')
+ params = esvm_get_default_params;
+end
+
params.calibration_propagate_onto_raw = 1;
for i = 1:length(imageset)
%Get local detections
View
@@ -12,6 +12,13 @@
%% Download and load pre-trained VOC2007 bus models
[models, M, test_set] = esvm_download_models(cls);
+params = esvm_get_default_params;
+
+%We can speed things (2x) up by turning of detections on image flips
+%params.detect_add_flip = 0;
+
+%We can also speed things up by taking a subset of models
+%[models,M] = esvm_subset_of_models(models,M,1:100);
%If VOC is locally installed, let models point to local images, not URLs
local_dir = '/Users/tomasz/projects/pascal/VOCdevkit/';
@@ -21,19 +28,21 @@
%% Load one image, and apply bus detector
I1 = imread('000858.jpg');
-esvm_apply_and_show_exemplars(I1, models, M);
+esvm_apply_and_show_exemplars(I1, models, M, params);
%% Create an array of images, and apply bus detector
I2 = imread('009021.jpg');
I3 = imread('009704.jpg');
Iarray = {I2, I3};
-esvm_apply_and_show_exemplars(Iarray, models, M);
+esvm_apply_and_show_exemplars(Iarray, models, M, params);
%% Create URL-based set of images, and apply bus detector
+
%Show image filepaths
cat(1,test_set{1:5})
+
%Apply detector
-esvm_apply_and_show_exemplars(test_set(1:5), models, M);
+esvm_apply_and_show_exemplars(test_set(1:5), models, M, params);
%% Set image path directory, and apply bus detector
Idirectory = '/v2/SUN/Images/b/bus_depot/outdoor/';
@@ -45,7 +54,7 @@
MAXDIM = 500;
Ilist = cellfun2(@(x)(@()imresize_max(convert_to_I(x),MAXDIM)), ...
Ilist);
- esvm_apply_and_show_exemplars(Ilist, models, M);
+ esvm_apply_and_show_exemplars(Ilist, models, M, params);
else
fprintf(1,'Note: not applying because %s is not a directory\n',...
Idirectory);
@@ -12,38 +12,44 @@
addpath(genpath(pwd))
%% Create a synthetic dataset of circles on a random background
-Npos = 100;
-Nneg = 100;
+Npos = 20;
+Nneg = 20;
[pos_set,neg_set] = esvm_generate_dataset(Npos,Nneg);
+models_name = 'circle';
+
%% Set exemplar-initialization parameters
params = esvm_get_default_params;
params.init_params.sbin = 4;
params.init_params.MAXDIM = 6;
params.model_type = 'exemplar';
params.dataset_params.display = 1;
+
%if localdir is commented out, no local saving happens
-%params.dataset_params.localdir = '/nfs/baikal/tmalisie/synthetic/';
+params.dataset_params.localdir = '/nfs/baikal/tmalisie/synthetic/';
%%Initialize exemplar stream
stream_params.stream_set_name = 'trainval';
-stream_params.stream_max_ex = 20;
+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
-%assign pos_set as variable
+%assign pos_set as variable, because we need it for visualization
stream_params.pos_set = pos_set;
+stream_params.cls = models_name;
%% Get the positive stream
e_stream_set = esvm_get_pascal_stream(stream_params, ...
params.dataset_params);
+% break it up into a set of held out negatives, and the ones used
+% for mining
val_neg_set = neg_set((Nneg/2+1):end);
neg_set = neg_set(1:((Nneg/2)));
%% Initialize Exemplars
initial_models = esvm_initialize_exemplars(e_stream_set, params, ...
- 'initial');
+ models_name);
%% Set exemplar-svm training parameters
train_params = params;
@@ -52,38 +58,38 @@
train_params.detect_exemplar_nms_os_threshold = 1.0;
train_params.detect_max_windows_per_exemplar = 100;
-train_params.CACHE_FILE = 1;
%% Perform Exemplar-SVM training
[models] = esvm_train_exemplars(initial_models, ...
neg_set, train_params);
+%% Create validation set from positives and extra negatives
val_params = params;
val_params.detect_exemplar_nms_os_threshold = 0.5;
val_params.gt_function = @esvm_load_gt_function;
val_set = cat(1, pos_set(:), val_neg_set(:));
-val_params.val_set = val_set;
val_set_name = 'valset';
%% 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, models, val_params);
+M = esvm_perform_calibration(val_grid, val_set, models, val_params);
%% Define test-set
+Ntest = 20;
test_params = params;
test_params.detect_exemplar_nms_os_threshold = 0.5;
-Ntest = 200;
[stream_test] = esvm_generate_dataset(Ntest);
test_set = cellfun2(@(x)x.I, stream_test);
+test_set_name = 'testset';
%% Apply on test set
-test_grid = esvm_detect_imageset(test_set, models, test_params);
+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);
+ params, maxk, test_set_name);
View
@@ -254,30 +254,31 @@
sizes2 = cellfun(@(x)x.model.hg_size(2),models);
S = [max(sizes1(:)) max(sizes2(:))];
-templates = zeros(S(1),S(2),features,length(models));
-templates_x = zeros(S(1),S(2),features,length(models));
-template_masks = zeros(S(1),S(2),features,length(models));
+fsize = params.init_params.features();
+templates = zeros(S(1),S(2),fsize,length(models));
+templates_x = zeros(S(1),S(2),fsize,length(models));
+template_masks = zeros(S(1),S(2),fsize,length(models));
for i = 1:length(models)
- t = zeros(S(1),S(2),features);
+ t = zeros(S(1),S(2),fsize);
t(1:models{i}.model.hg_size(1),1:models{i}.model.hg_size(2),:) = ...
models{i}.model.w;
templates(:,:,:,i) = t;
- template_masks(:,:,:,i) = repmat(double(sum(t.^2,3)>0),[1 1 features]);
+ template_masks(:,:,:,i) = repmat(double(sum(t.^2,3)>0),[1 1 fsize]);
if (~isempty(params.nnmode)) || ...
(isfield(params,'wtype') && ...
strcmp(params.wtype,'dfun')==1)
- x = zeros(S(1),S(2),features);
+ x = zeros(S(1),S(2),fsize);
x(1:models{i}.model.hg_size(1),1:models{i}.model.hg_size(2),:) = ...
reshape(models{i}.model.x(:,1),models{i}.model.hg_size);
templates_x(:,:,:,i) = x;
end
end
-%maskmat = repmat(template_masks,[1 1 1 features]);
+%maskmat = repmat(template_masks,[1 1 1 fsize]);
%maskmat = permute(maskmat,[1 2 4 3]);
%templates_x = templates_x .* maskmat;
@@ -288,7 +289,7 @@
pyr_N = cellfun(@(x)prod([size(x,1) size(x,2)]-S+1),t.hog);
sumN = sum(pyr_N);
-X = zeros(S(1)*S(2)*features,sumN);
+X = zeros(S(1)*S(2)*fsize,sumN);
offsets = cell(length(t.hog), 1);
uus = cell(length(t.hog),1);
vvs = cell(length(t.hog),1);
@@ -298,7 +299,7 @@
s = size(t.hog{i});
NW = s(1)*s(2);
ppp = reshape(1:NW,s(1),s(2));
- curf = reshape(t.hog{i},[],features);
+ curf = reshape(t.hog{i},[],fsize);
b = im2col(ppp,[S(1) S(2)]);
offsets{i} = b(1,:);
@@ -317,7 +318,7 @@
uus = cat(2,uus{:});
vvs = cat(2,vvs{:});
-% m.model.w = zeros(S(1),S(2),features);
+% m.model.w = zeros(S(1),S(2),fsize);
% m.model.b = 0;
% temp_params = params;
% temp_params.detect_save_features = 1;
@@ -150,7 +150,6 @@
allfiles{i} = m;
end
-
% %Print the bounding box overlap between the initial window and
% %the final window
% finalos = getosmatrix_bb(m.gt_box, m.model.bb(1,:));
@@ -162,7 +161,7 @@
%Show the initialized exemplars
if params.dataset_params.display == 1
- show_exemplar_frames({m}, 1, params.dataset_params);
+ esvm_show_exemplar_frames({m}, 1, params.dataset_params);
drawnow
snapnow;
end
View
@@ -1,4 +1,4 @@
-function M = esvm_perform_calibration(grid, models, params, CACHE_FILES)
+function M = esvm_perform_calibration(grid, val_set, models, params)
% 1. Perform LABOO calibration procedure and 2. Learn a combination
% matrix M which multiplexes the detection results (by compiling
% co-occurrence statistics on true positives)
@@ -10,20 +10,14 @@
% available under the terms of the MIT license (see COPYING file).
% Project homepage: https://github.com/quantombone/exemplarsvm
-if isfield(params,'CACHE_BETAS') && params.CACHE_BETAS==1%~exist('CACHE_FILES','var')
- CACHE_FILES = 1;
-else
- CACHE_FILES = 0;
-end
-
%% Perform calibration
-betas = esvm_perform_platt_calibration(grid, models, ...
- params, CACHE_FILES);
+betas = esvm_perform_platt_calibration(grid, val_set, models, ...
+ params);
+%% Estimate the co-occurrence matrix M
if ~(isfield(params,'SKIP_M') && params.SKIP_M==1)
- %% Estimate the co-occurrence matrix M
- [M] = esvm_estimate_M(grid, models, params, CACHE_FILES);
-
+ M = esvm_estimate_M(grid, models, params);
end
+%concatenate results
M.betas = betas;
View
@@ -1,13 +1,11 @@
function allbbs = esvm_show_top_dets(test_struct, grid, ...
test_set, models, params, ...
maxk, set_name)
-
-
% Show maxk top detections for [models] where [grid] is the set of
% detections from the set [test_set], [test_struct] contains final
-% boxes after calibration and is obtained from applying calibration
-% If [set_name] is present, then results are saved based on naming
-% convention into www/ subfolder
+% boxes after pooling and calibration. If [dataset_params.localdir] is
+% present, then results are saved based on naming convention into a
+% "www" subfolder. maxk is the number of top detections we show
%
% NOTE: this function requires some cleanup, but is functional
%
@@ -20,13 +18,13 @@
allbbs = [];
-if exist('set_name','var') && length(set_name)>0
+if length(params.dataset_params.localdir) > 0
CACHE_FILES = 1;
else
CACHE_FILES = 0;
- set_name = '';
end
+
%Default exemplar-inpainting show mode
%SHOW_MODE = 1;
@@ -111,18 +109,20 @@
wwwdir = sprintf('%s/www/%s.%s%s/',params.dataset_params.localdir,...
set_name, ...
models{1}.models_name,test_struct.calib_string);
- if ~exist(wwwdir,'dir') && exist('CACHE_FILES','var') && (CACHE_FILES == 1)
+ if ~exist(wwwdir,'dir') && (CACHE_FILES == 1)
mkdir(wwwdir);
end
- filer = sprintf('%s/%05d%s',wwwdir,k,suffix);
+ filer = sprintf('%s/%05d%s.png',wwwdir,k,suffix);
filerlock = [filer '.lock'];
- if 0 %fileexists(filer) || (mymkdir_dist(filerlock) == 0)
+
+ if CACHE_FILES && (fileexists(filer) || (mymkdir_dist(filerlock) == 0))
counter = counter + 1;
+ fprintf(1,'Already showed detection # %d, score=%.3f\n', k, bbs(bb(counter),end));
continue
end
- fprintf(1,'Showing top detection %d\n', k);
+ fprintf(1,'Showing detection # %d, score=%.3f\n', k, bbs(bb(counter),end));
allbbs(k,:) = bbs(bb(counter),:);
curb = bb(counter);
@@ -235,9 +235,9 @@
drawnow
snapnow
- if exist('CACHE_FILES','var') && CACHE_FILES == 1
+ if CACHE_FILES == 1
%print(gcf,'-depsc2',filer);
- print(gcf,'-dpng',[filer '.png']);
+ print(gcf,'-dpng',filer);
%finalfile = strrep(filer,'.eps','.pdf');
%unix(sprintf('zsh "ps2pdf -dEPSCrop -dPDFSETTINGS=/prepress %s %s"',...
% filer,finalfile));
@@ -246,7 +246,7 @@
% unix(sprintf('rm %s',filer));
%end
- if exist(filerlock,'dir')
+ if CACHE_FILES && exist(filerlock,'dir')
rmdir(filerlock);
end
end
Oops, something went wrong.

0 comments on commit 0ffe88d

Please sign in to comment.