Skip to content

Commit

Permalink
lots of file updates
Browse files Browse the repository at this point in the history
  • Loading branch information
quantombone committed Jan 18, 2012
1 parent ff2ff5e commit 9cdb797
Show file tree
Hide file tree
Showing 23 changed files with 295 additions and 194 deletions.
2 changes: 1 addition & 1 deletion esvm_demo_train_synthetic.m
Expand Up @@ -59,7 +59,7 @@

val_params = params;
val_params.detect_exemplar_nms_os_threshold = 0.5;
val_params.gt_function = @get_pascal_anno_function;
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';
Expand Down
14 changes: 7 additions & 7 deletions esvm_demo_train_voc_class_fast.m
Expand Up @@ -39,9 +39,9 @@
%results_directory = sprintf('/csail/vision-videolabelme/people/tomasz/esvm-%s/',cls);


dataset_params = get_voc_dataset(dataset_directory,...
data_directory,...
results_directory);
dataset_params = esvm_get_voc_dataset(dataset_directory,...
data_directory,...
results_directory);
%dataset_params.display = 1;
%dataset_params.dump_images = 1;

Expand Down Expand Up @@ -75,7 +75,7 @@
e_stream_set = esvm_get_pascal_stream(stream_params, ...
dataset_params);

neg_set = get_pascal_set(dataset_params, ['train-' cls]);
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 = ...
Expand All @@ -94,19 +94,19 @@

% val_params = params;
% val_params.detect_exemplar_nms_os_threshold = 0.5;
% val_params.gt_function = @get_pascal_anno_function;
% val_params.gt_function = @esvm_load_gt_function;
% val_params.CACHE_BETAS = 1;

% val_set_name = ['trainval+' cls];

% val_set = get_pascal_set(dataset_params, val_set_name);
% val_set = esvm_get_pascal_set(dataset_params, val_set_name);
% val_set = val_set(1:10);

%% Define test-set
test_params = params;
test_params.detect_exemplar_nms_os_threshold = 0.5;
test_set_name = ['trainval+' cls];
test_set = get_pascal_set(dataset_params, test_set_name);
test_set = esvm_get_pascal_set(dataset_params, test_set_name);
test_set = test_set(1:100);

%% Train the exemplars and get updated models name
Expand Down
19 changes: 2 additions & 17 deletions esvm_pool_exemplar_dets.m
@@ -1,6 +1,6 @@
function final = esvm_pool_exemplar_dets(grid, models, M, params)
%% Perform detection post-processing and pool detection boxes
%(which will then be ready to go into the PASCAL evaluation code)
% Perform detection post-processing and pool detection boxes
% (which will then be ready to go into the PASCAL evaluation code)
% If there are overlap scores associated with boxes, then they are
% also kept track of propertly, even after NMS.
%
Expand Down Expand Up @@ -65,21 +65,6 @@

raw_boxes = bboxes;

% perform within-exemplar NMS
% NOTE: this is already done during detection time
% if 0
% fprintf(1,'applying exemplar nms\n');
% for i = 1:length(bboxes)
% if size(bboxes{i},1) > 0
% bboxes{i}(:,5) = 1:size(bboxes{i},1);
% bboxes{i} = nms_within_exemplars(bboxes{i},.5);
% if length(grid{i}.extras)>0 && isfield(grid{i}.extras,'os')
% maxos{i} = maxos{i}(bboxes{i}(:,5));
% end
% end
% end
% end

%Perform score rescaling
%1. no scaling
%2. platt's calibration (sigmoid scaling)
Expand Down
23 changes: 12 additions & 11 deletions esvm_script_train_voc_class.m
Expand Up @@ -34,9 +34,9 @@
%data_directory = '/csail/vision-videolabelme/people/tomasz/VOCdevkit/';
%results_directory = sprintf('/csail/vision-videolabelme/people/tomasz/esvm-%s/',cls);

dataset_params = get_voc_dataset(dataset_directory, ...
data_directory, ...
results_directory);
dataset_params = esvm_get_voc_dataset(dataset_directory, ...
data_directory, ...
results_directory);
%dataset_params.display = 1;
%dataset_params.dump_images = 1;

Expand Down Expand Up @@ -74,7 +74,7 @@
dataset_params);


neg_set = get_pascal_set(dataset_params, ['train-' cls]);
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 = ...
Expand All @@ -93,18 +93,18 @@

val_params = params;
val_params.detect_exemplar_nms_os_threshold = 0.5;
val_params.gt_function = @get_pascal_anno_function;
val_params.gt_function = @esvm_load_gt_function;
val_params.CACHE_BETAS = 1;

val_set_name = ['trainval'];

val_set = get_pascal_set(dataset_params, val_set_name);
val_set = esvm_get_pascal_set(dataset_params, val_set_name);

%% Define test-set
test_params = params;
test_params.detect_exemplar_nms_os_threshold = 0.5;
test_set_name = ['test'];
test_set = get_pascal_set(dataset_params, test_set_name);
test_set = esvm_get_pascal_set(dataset_params, test_set_name);

%% Train the exemplars and get updated models name
[models,models_name] = esvm_train_exemplars(initial_models, ...
Expand All @@ -122,11 +122,12 @@
%% Apply calibration matrix to test-set results
test_struct = esvm_pool_exemplar_dets(test_grid, models, M, test_params);

%% Show top 20 detections as exemplar-inpainting results
maxk = 20;
allbbs = esvm_show_top_dets(test_struct, test_grid, test_set, models, ...
params, maxk, test_set_name);
params, maxk, test_set_name);

[results] = evaluate_pascal_voc_grid(test_struct, test_grid, ...
params, test_set_name, cls, ...
models_name);
%% Perform the exemplar evaluation
[results] = esvm_evaluate_pascal_voc(test_struct, test_grid, params, ...
test_set_name, cls, models_name);

2 changes: 1 addition & 1 deletion esvm_train_exemplars.m
Expand Up @@ -186,7 +186,7 @@

% figure(445);
% clf;
% showI = get_sv_stack(m,5,5);
% showI = esvm_show_det_stack(m,5,5);
% imagesc(showI);
% title('Exemplar and Top Dets');
% drawnow;
Expand Down
24 changes: 0 additions & 24 deletions internal/esvm_estimate_M.m
Expand Up @@ -56,8 +56,6 @@

curcls = models{1}.cls;

%curcls = find(ismember(params.dataset_params.classes,models{1}.cls));

fprintf(1,' -Computing Box Features:');
starter=tic;
for i = 1:length(grid)
Expand Down Expand Up @@ -100,31 +98,10 @@
end
end



if 0
%% clip boxes to image
fprintf(1,'clipping boxes\n');
for i = 1:length(boxes)
boxes{i} = clip_to_image(boxes{i},grid{i}.imbb);
end
end

lens = cellfun(@(x)size(x,1),boxes);
boxes(lens==0) = [];
maxos(lens==0) = [];

%already nms-ed within exemplars (but not within LR flips)
%%NOTE: should this be turned on?
if 0
for i = 1:length(boxes)
boxes{i}(:,5) = 1:size(boxes{i},1);
boxes{i} = nms_within_exemplars(boxes{i},.5);
maxos{i} = maxos{i}(boxes{i}(:,5));
boxes{i}(:,5) = i;
end
end

K = length(models);
N = sum(cellfun(@(x)size(x,2),maxos));

Expand Down Expand Up @@ -225,7 +202,6 @@
%old way: works better!
C(cur,exids(i)) = C(cur,exids(i)) + os(i)*(os(i) >= count_thresh) / ...
length(cur);

end

for i = 1:K
Expand Down
2 changes: 1 addition & 1 deletion internal/esvm_evaluate_pascal_voc.m
@@ -1,4 +1,4 @@
function [results] = evaluate_pascal_voc_grid(test_struct, grid, ...
function [results] = esvm_evaluate_pascal_voc(test_struct, grid, ...
params, ...
target_directory, cls, ...
models_name)
Expand Down
126 changes: 124 additions & 2 deletions internal/esvm_get_model_wiggles.m
@@ -1,5 +1,6 @@
function model = populate_wiggles(I, model, NWIGGLES)
%Get wiggles
function model = esvm_get_model_wiggles(I, model, NWIGGLES)
%Get wiggles of a model and populate model with them

xxx = replica_hits(I, model.init_params.sbin, model.bb(1,:), ...
model.hg_size, NWIGGLES, model);

Expand All @@ -9,3 +10,124 @@
model.w = model.w - mean(model.w(:));
%model.b = -100;
model.b = 0;

function xxx = replica_hits(I, sbin, bb, hg_size, N_WIGGLES, savemodel)
%% Given an image, an sbin, and the location of the detection window
%% encoded as bb, create N_WIGGLES wiggles by perturbing image content
%% inside the frame

%% Tomasz Malisiewicz (tomasz@cmu.edu)

if ~exist('N_WIGGLES','var')
N_WIGGLES = 100;
end

I = im2double(I);

NEWPAD = 5; %ceil(max(hg_size(1),hg_size(2))/2);

u = bb(9);
v = bb(10);

if bb(7) == 1
I = flip_image(I);
end

lilI = resize(I,bb(8));
fprintf(1,'Warning: using esvm_features directly\n');
f = esvm_features(lilI,sbin);
f = padarray(f,[NEWPAD NEWPAD 0]);
xxx_base = f(u-2+(1:hg_size(1)),v-2+(1:hg_size(2)),:);

%%% NOW DO WIGGLES WITHOUT A SLIDE!
xxx = zeros(prod(hg_size),N_WIGGLES);
xxx(:,1) = xxx_base(:);
for iii = 2:N_WIGGLES
%fprintf(1,'$');

%Add random noise
curI = lilI + .02*randn(size(lilI));

%Perform random gaussian smoothing
randsigma = .1+rand;
curI = (imfilter(curI,fspecial('gaussian',[9 9],randsigma)));

%Perform random shift
cx = floor(3*rand)-1;
cy = floor(3*rand)-1;
curI = circshift2(curI,[cx cy]);

% rrr = ceil(rand*4);
% if rrr == 1
% TOP = floor(rand*size(curI,1)*.3);
% curI(1:TOP,:,:) = 0;
% elseif rrr == 2
% BOT = floor(rand*size(curI,1)*.3);
% curI(end-BOT:end,:,:) = 0;
% elseif rrr == 3
% LEFT = floor(rand*size(curI,2)*.3);
% curI(:,1:LEFT,:) = 0;
% else
% RIGHT = floor(rand*size(curI,2)*.3);
% curI(:,end-RIGHT:end,:) = 0;
% end

f = esvm_features(curI,sbin);
f = padarray(f,[NEWPAD NEWPAD 0]);
x = f(u-2+(1:hg_size(1)),v-2+(1:hg_size(2)),:);
xxx(:,iii) = x(:);
if 0
figure(444)
clf
imagesc(max(0.0,min(1.0,curI)))
drawnow
pause
end
end

% return

% clear sg;
% cxs = 1:5:16;
% cys = 1:5:16;
% xxx = zeros(prod(size(w)),0);
% for cxi = 1:length(cxs)
% for cyj = 1:length(cys)
% cx = cxs(cxi);
% cy = cys(cyj);

% curI = I(cx:end,cy:end,:);

% if rand>.5
% curI = rgb2gray(curI);
% curI = repmat(curI,[1 1 3]);
% end
% %curI = curI + .3*randn(size(curI));
% %curI = max(0.0,min(1.0,curI));
% randsigma = .1+rand*2;
% curI = (imfilter(curI,fspecial('gaussian',[9 9],randsigma)));
% curI = min(max(curI,0.0),1.0);

% [rs,t] = localizemeHOG(curI,...
% sbin,...
% {w},...
% {b},...
% -1.0,1,10,1);
% if 0
% mask = zeros(size(w,1),size(w,2));
% [coarse_boxes] = extract_bbs_from_rs(rs, curI, ...
% sbin, mask);
% bbb = coarse_boxes(1,:);
% (bbb(3)-bbb(1)+1) / (bbb(4)-bbb(2)+1)
% figure(44)
% clf
% imagesc(curI)
% plot_bbox(coarse_boxes(1,:))
% pause
% end
% fprintf(1,'\n');
% maxer=max(rs.score_grid{1});
% sg(cxi,cyj) = maxer;
% xxx(:,end+1) = rs.support_grid{1}{1};
% end
% end
17 changes: 12 additions & 5 deletions internal/esvm_get_pascal_set.m
@@ -1,4 +1,4 @@
function bg = get_pascal_set(VOCopts, target_directory, class)
function bg = esvm_get_pascal_set(VOCopts, target_directory, class)
% Get a subset of PASCAL dataset (as defined in VOCopts) from the
% 'train', 'trainval', or 'test' subsets ('both' refers to
% 'trainval'+'test')
Expand All @@ -7,11 +7,18 @@
% if class is "-car" chose only images not containing cars
% returns:
% [bg]: a cell array of images, such that I=convert_to_I(bg{i});
%
% 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

if (nargin == 2) && strcmp(target_directory,'both')
bg = cat(1, ...
get_pascal_set(VOCopts, 'trainval'),...
get_pascal_set(VOCopts, 'test'));
esvm_get_pascal_set(VOCopts, 'trainval'),...
esvm_get_pascal_set(VOCopts, 'test'));
return;
end

Expand All @@ -27,7 +34,7 @@

td = target_directory(1:has_marker(1)-1);
cl = target_directory(has_marker(1):end);
bg = get_pascal_set(VOCopts, td, cl);
bg = esvm_get_pascal_set(VOCopts, td, cl);
return;
end

Expand Down Expand Up @@ -65,7 +72,7 @@
end
neg_set = neg_set(gt==1);
else
error(sprintf(['Invalid class %s passed to get_pascal_set: must' ...
error(sprintf(['Invalid class %s passed to esvm_get_pascal_set: must' ...
' start with plus or minus sign'], class));
end

Expand Down

0 comments on commit 9cdb797

Please sign in to comment.