Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

more local updates

  • Loading branch information...
commit d57c4853c6853f9d4ead9a0073d49aa919772c46 1 parent e1eb505
@quantombone authored
View
102 esvm_apply_calibration.m
@@ -25,9 +25,8 @@
curids = cellfun2(@(x)x.curid,models);
end
-cls = models{1}.cls;
-
-excurids = cellfun2(@(x)x.curid,models);
+%cls = models{1}.cls;
+%excurids = cellfun2(@(x)x.curid,models);
bboxes = cell(1,length(grid));
maxos = cell(1,length(grid));
@@ -40,7 +39,7 @@
continue
end
- if length(grid{i}.extras)>0 && isfield(grid{i}.extras,'maxos')
+ if ~isempty(grid{i}.extras) && isfield(grid{i}.extras,'maxos')
maxos{i} = grid{i}.extras.maxos;
maxos{i}(grid{i}.extras.maxclass~=curcls) = 0;
end
@@ -51,8 +50,8 @@
badex = find(ismember(excurids,{curid}));
bboxes{i}(badex,:) = [];
- if length(grid{i}.extras)>0 && isfield(grid{i}.extras,'maxos')
- if length(maxos{i})>0
+ if ~isempty(grid{i}.extras) && isfield(grid{i}.extras,'maxos')
+ if ~isempty(maxos{i})
maxos{i}(badex) = [];
end
end
@@ -61,25 +60,25 @@
% 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
+% 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)
%3. raw score + 1
-if (exist('M','var') && (length(M)>0) && isfield(M,'betas') && ...
+if (exist('M','var') && (~isempty(M)) && isfield(M,'betas') && ...
~isfield(M,'neighbor_thresh'))
fprintf(1,'Applying betas to %d images:',length(bboxes));
@@ -95,10 +94,11 @@
calib_boxes = calib_boxes(oks,:);
bboxes{i} = calib_boxes;
end
-elseif exist('M','var') && length(M)>0 && isfield(M,'neighbor_thresh')
+elseif exist('M','var') && ~isempty(M) && isfield(M,'neighbor_thresh')
fprintf(1,'Applying M-matrix to %d images:',length(bboxes));
starter=tic;
+ nbrlist = cell(length(bboxes),1);
for i = 1:length(bboxes)
fprintf(1,'.');
if size(bboxes{i},1) == 0
@@ -108,7 +108,7 @@
bboxes{i}(:,end) = bboxes{i}(:,end)+1;
[xraw,nbrlist{i}] = get_box_features(bboxes{i},length(models), ...
- M.neighbor_thresh);
+ M.neighbor_thresh);
r2 = esvm_apply_M(xraw,bboxes{i},M);
bboxes{i}(:,end) = r2;
end
@@ -124,7 +124,7 @@
if size(bboxes{i},1) > 0
bboxes{i}(:,5) = 1:size(bboxes{i},1);
bboxes{i} = nms(bboxes{i},os_thresh);
- if length(grid{i}.extras)>0 && isfield(grid{i}.extras,'maxos')
+ if ~isempty(grid{i}.extras) && isfield(grid{i}.extras,'maxos')
maxos{i} = maxos{i}(bboxes{i}(:,5));
end
if exist('nbrlist','var')
@@ -134,33 +134,33 @@
end
end
-if 0
-if exist('M','var') && length(M)>0 && isfield(M,'betas')
-
- fprintf(1,'Propagating scores onto raw detections\n');
- %% propagate scores onto raw boxes
- for i = 1:length(bboxes)
- calib_boxes = calibrate_boxes(raw_boxes{i},M.betas);
- beta_scores = calib_boxes(:,end);
-
- osmat = getosmatrix_bb(bboxes{i},raw_boxes{i});
- for j = 1:size(osmat,1)
- curscores = (osmat(j,:)>.5) .* beta_scores';
- [aa,bb] = max(curscores);
- bboxes{i}(j,:) = raw_boxes{i}(bb,:);
- bboxes{i}(j,end) = aa;
- end
-
- % new_scores = beta_scores;
- % for j = 1:length(nbrlist{i})
- % new_scores(nbrlist{i}{j}) = max(new_scores(nbrlist{i}{j}),...
- % beta_scores(nbrlist{i}{j}).*...
- % bboxes{i}(nbrlist{i}{j},end));
- % end
- % bboxes{i}(:,end) = new_scores;
- end
-end
-end
+% if 0
+% if exist('M','var') && length(M)>0 && isfield(M,'betas')
+%
+% fprintf(1,'Propagating scores onto raw detections\n');
+% %% propagate scores onto raw boxes
+% for i = 1:length(bboxes)
+% calib_boxes = calibrate_boxes(raw_boxes{i},M.betas);
+% beta_scores = calib_boxes(:,end);
+%
+% osmat = getosmatrix_bb(bboxes{i},raw_boxes{i});
+% for j = 1:size(osmat,1)
+% curscores = (osmat(j,:)>.5) .* beta_scores';
+% [aa,bb] = max(curscores);
+% bboxes{i}(j,:) = raw_boxes{i}(bb,:);
+% bboxes{i}(j,end) = aa;
+% end
+%
+% % new_scores = beta_scores;
+% % for j = 1:length(nbrlist{i})
+% % new_scores(nbrlist{i}{j}) = max(new_scores(nbrlist{i}{j}),...
+% % beta_scores(nbrlist{i}{j}).*...
+% % bboxes{i}(nbrlist{i}{j},end));
+% % end
+% % bboxes{i}(:,end) = new_scores;
+% end
+% end
+% end
% Clip boxes to image dimensions since VOC testing annotation
% always fall within the image
@@ -178,11 +178,11 @@
%Create a string which summarizes the pooling type
calib_string = '';
-if exist('M','var') && length(M)>0 && isfield(M,'betas')
+if exist('M','var') && ~isempty(M) && isfield(M,'betas')
calib_string = '-calibrated';
end
-if exist('M','var') && length(M)>0 && isfield(M,'betas') && isfield(M,'w')
+if exist('M','var') && ~isempty(M) && isfield(M,'betas') && isfield(M,'w')
calib_string = [calib_string '-M'];
end
View
90 esvm_detect.m
@@ -16,7 +16,7 @@
% resstruct: Sliding window output struct with
% resstruct.bbs{:}: Detection boxes and pyramid locations
% resstruct.xs{:}: Detection features
-% t: The Feature pyramid output
+% feat_pyramid: The Feature pyramid output
%
% Copyright (C) 2011-12 by Tomasz Malisiewicz
% All rights reserved.
@@ -24,7 +24,7 @@
% This file is part of the Exemplar-SVM library and is made
% available under the terms of the MIT license (see COPYING file).
-if length(models) == 0
+if isempty(models)
resstruct.bbs{1} = zeros(0,0);
resstruct.xs{1} = zeros(0,0);
feat_pyramid = [];
@@ -77,11 +77,11 @@
function [resstruct,t] = esvm_detectdriver(I, models, ...
localizeparams)
-%If the number of specified models is greater than 20, use the
+%NOTE: If the number of specified models is greater than 20, use the
%BLOCK-based method
MAX_MODELS_BEFORE_BLOCK_METHOD = 20;
if (length(models)>MAX_MODELS_BEFORE_BLOCK_METHOD) ...
- || (length(localizeparams.nnmode)>0)
+ || (~isempty(localizeparams.nnmode))
[resstruct,t] = esvm_detectdriverBLOCK(I, models, ...
localizeparams);
return;
@@ -93,7 +93,7 @@
%NOTE: all exemplars in this set must have the same sbin
sbin = models{1}.model.init_params.sbin;
-t = get_pyramid(I, sbin, length(models), localizeparams);
+t = get_pyramid(I, sbin, localizeparams);
resstruct.padder = t.padder;
resstruct.bbs = cell(N,1);
@@ -109,6 +109,7 @@
wxs = cellfun2(@(x)reshape(x.model.x(:,1),size(x.model.w)), ...
models);
ws2 = ws;
+ special_offset = zeros(length(ws2),1);
for q = 1:length(ws2)
ws2{q} = -2*ws{q}.*wxs{q};
special_offset(q) = ws{q}(:)'*(models{q}.model.x(:,1).^2);
@@ -236,7 +237,7 @@
templates(:,:,:,i) = t;
template_masks(:,:,:,i) = repmat(double(sum(t.^2,3)>0),[1 1 features]);
- if (length(localizeparams.nnmode) > 0) || ...
+ if (~isempty(localizeparams.nnmode)) || ...
(isfield(localizeparams,'wtype') && ...
strcmp(localizeparams.wtype,'dfun')==1)
x = zeros(S(1),S(2),features);
@@ -296,7 +297,7 @@
r2 = repmat(sum(W.*(U.^2),1)',1,size(X,2));
r = (W'*(X.^2) - 2*(W.*U)'*X + r2);
r = bsxfun(@minus, r, bs);
-elseif length(localizeparams.nnmode) == 0
+elseif isempty(localizeparams.nnmode)
%nnmode 0: Apply linear classifiers by performing one large matrix
%multiplication and subtract bias
r = exemplar_matrix' * X;
@@ -311,62 +312,8 @@
U = reshape(templates_x,[],length(models));
r2 = repmat(sum(W.*(U.^2),1)',1,size(X,2));
r = - (W'*(X.^2) - 2*(W.*U)'*X + r2);
-elseif strcmp(localizeparams.nnmode,'cosangle') == 1
- %nnmode 1: Apply linear classifiers by performing one large matrix
- %multiplication and subtract bias
-
- %mf = mean(X,1);
- %X = X - repmat(mf,size(X,1),1);
- %r = exemplar_matrix' * X;
-
- exemplar_matrix = reshape(templates_x, [], size(templates_x,4));
-
- % %% do normalization for each window
- % tm = template_masks;
- % tm = reshape(tm,[],length(models));
- % ut = unique(tm','rows');
- % [tmp,utids] = ismember(tm',ut,'rows');
-
- % r = zeros(length(models),size(finalf,2));
- % for j = 1:size(ut,1)
- % fprintf(1,'!');
- % curmask = repmat(reshape(ut(j,:),...
- % [size(templates_x,1) size(templates_x,2)]),...
- % [1 1 features]);
- % hits = find(utids == j);
-
- % curf = finalf;
- % curf = curf.*repmat(curmask(:),1,size(curf,2));
- % curr = slmetric_pw(exemplar_matrix(:,hits),curf,'nrmcorr');
-
- % r(hits,:) = curr;
- % end
-
- r = slmetric_pw(exemplar_matrix, X, 'nrmcorr');
-
- %% why am I not getting perfect hits for g-mode?
- %% ANSWER: because there is a padding which we cannot enforce on
- %test-windows efficiently...This will affect the normalization of
- %the test windows
-
- % exemplar_x_matrix = reshape(templates_x,[],size(templates_x,4));
- % res = sum(exemplar_matrix .* exemplar_x_matrix,1);
- % exemplar_matrix = exemplar_matrix ./ repmat(res+eps,size(exemplar_matrix,1),1);
- % r = exemplar_matrix' * finalf;
-
- %keyboard
-
- % rrr = randperm(size(www2,2));
- % rrr = rrr(1:10);
- % r2 = slmetric_pw(www2(:,rrr),finalf,'chisq');
- % r = zeros(size(www2,2),size(finalf,2));
- % r(rrr,:) = exp(-.001*r2);
-
- %r = exemplar_matrix' * finalf;
- %r = bsxfun(@minus, r, bs);
-
else
- error(sprintf('invalid nnmode=%s\n',localizeparams.nnmode));
+ error('invalid nnmode=%s\n',localizeparams.nnmode);
end
resstruct.bbs = cell(N,1);
@@ -442,15 +389,12 @@
end
end
-function t = get_pyramid(I, sbin, N, localizeparams)
+function t = get_pyramid(I, sbin, localizeparams)
%Extract feature pyramid from variable I (which could be either an image,
%or already a feature pyramid)
if isnumeric(I)
-
- flipstring = '';
if (localizeparams.FLIP_LR == 1)
- flipstring = '@F';
I = flip_image(I);
else
%take unadulterated "aka" un-flipped image
@@ -459,9 +403,6 @@
clear t
t.size = size(I);
- %fprintf(1,'Localizing %d in I=[%dx%d@%d%s]',N,...
- % t.size(1),t.size(2),localizeparams.lpo,flipstring);
-
%Compute pyramid
[t.hog,t.scales] = featpyramid2(I, sbin, localizeparams);
t.padder = localizeparams.pyramid_padder;
@@ -471,13 +412,7 @@
minsizes = cellfun(@(x)min([size(x,1) size(x,2)]), t.hog);
t.hog = t.hog(minsizes >= t.padder*2);
- t.scales = t.scales(minsizes >= t.padder*2);
-
- %if only_compute_pyramid == 1
- % resstruct = t;
- % return;
- %end
-
+ t.scales = t.scales(minsizes >= t.padder*2);
else
fprintf(1,'Already found features\n');
@@ -490,8 +425,5 @@
else
t = I;
end
-
- %fprintf(1,'Localizing %d in I=[%dx%d@%d]',N,...
- % t.size(1),t.size(2),localizeparams.lpo);
end
View
32 esvm_detect_imageset.m
@@ -30,16 +30,15 @@
setname = '';
end
-if length(imageset) == 0
+if isempty(imageset)
grid = {};
return;
end
if save_files == 1
- fullsetname = [setname];
final_file = sprintf('%s/applied/%s-%s.mat',...
- dataset_params.localdir,fullsetname, ...
+ dataset_params.localdir,setname, ...
models{1}.models_name);
if fileexists(final_file)
@@ -60,10 +59,8 @@
% params = dataset_params.params;
% end
-fullsetname = [setname];
-
if save_files == 1
- baser = sprintf('%s/applied/%s-%s/',dataset_params.localdir,fullsetname, ...
+ baser = sprintf('%s/applied/%s-%s/',dataset_params.localdir,setname, ...
models{1}.models_name);
else
baser = '';
@@ -107,9 +104,10 @@
%% pre-load all images in a chunk
%fprintf(1,'Preloading %d images\n',length(inds{ordering(i)}));
clear Is;
- for j = 1:length(inds{ordering(i)})
- Is{j} = convert_to_I(imageset{inds{ordering(i)}(j)});
- end
+ Is = cellfun2(@(x)convert_to_I(x),imageset{inds{ordering(i)}});
+ %for j = 1:length(inds{ordering(i)})
+ % Is{j} = convert_to_I(imageset{inds{ordering(i)}(j)});
+ %end
L = length(inds{ordering(i)});
for j = 1:L
@@ -193,13 +191,13 @@
show_hits_figure(models, boxes, I);
drawnow
%pause(.1)
- else
- figure(1)
- clf
- imagesc(I)
- drawnow
- fprintf(1,'No detections in this Image\n');
- pause(.1)
+% else
+% figure(1)
+% clf
+% imagesc(I)
+% drawnow
+% fprintf(1,'No detections in this Image\n');
+% pause(.1)
end
boxes = saveboxes;
end
@@ -245,7 +243,7 @@
return;
end
-[allfiles,bb] = sort(allfiles);
+[allfiles] = sort(allfiles);
grid = esvm_load_result_grid(dataset_params, models, ...
setname, ...
allfiles);
View
40 esvm_train_exemplars.m
@@ -39,9 +39,6 @@
mkdir(DUMPDIR);
end
-%initial_directory = ...
-% sprintf('%s/%s/',dataset_params.localdir,models_name);
-
final_directory = ...
sprintf('%s/models/%s-%s/',dataset_params.localdir,...
models{1}.cls,...
@@ -52,10 +49,6 @@
mkdir(final_directory);
end
-%Find all initial files of the current class/mode
-%files = dir([initial_directory '*' cls '*.mat']);
-%files = dir([initial_directory '*000540.1*.mat']);
-
mining_params.final_directory = final_directory;
% randomize chunk orderings
@@ -78,10 +71,6 @@
allfiles = cell(length(models), 1);
parfor i = 1:length(models)
-
- %filer = sprintf('%s/%s',initial_directory, files(ordering(i)).name);
- %m = load(filer);
- %m = m.m;
m = models{i};
% Create a naming scheme for saving files
@@ -142,7 +131,7 @@
%total_mines = m.mining_stats{end}.total_mines;
if ((total_mines >= mining_params.MAX_TOTAL_MINED_IMAGES) || ...
- (length(m.mining_queue) == 0)) || ...
+ (isempty(m.mining_queue))) || ...
(m.iteration == mining_params.MAX_MINE_ITERATIONS)
keep_going = 0;
@@ -163,31 +152,31 @@
end
m = msave;
- if 0 %%dataset_params.display == 1
+ if dataset_params.display == 1
- exid = ordering(i);
- filer = sprintf('%s/%s.%s.%05d.png', DUMPDIR, 'train', ...
- m.cls,exid);
+ %exid = ordering(i);
+ %filer = sprintf('%s/%s.%s.%05d.png', DUMPDIR, 'train', ...
+ % m.cls,exid);
%if fileexists(filer)
% continue
%end
- figure(445)
- clf
+ figure(445);
+ clf;
showI = get_sv_stack(m,5,5);
- imagesc(showI)
- drawnow
+ imagesc(showI);
+ drawnow;
figure(235)
rpos = m.model.w(:)'*m.model.x-m.model.b;
rneg = m.model.w(:)'*m.model.svxs - m.model.b;
- clf
- plot(sort(rpos,'descend'),'r.')
+ clf;
+ plot(sort(rpos,'descend'),'r.');
hold on;
- plot(length(rpos)+[1:length(rneg)],rneg,'b.')
- drawnow
+ plot(length(rpos)+(1:length(rneg)),rneg,'b.');
+ drawnow;
%set(gcf,'PaperPosition',[0 0 20 20]);
%imwrite(showI,filer);
@@ -218,6 +207,7 @@
rmdir(filerlock);
end
catch
+ fprintf(1,'Cannot delete %s\n',filerlock);
end
end
@@ -226,7 +216,7 @@
return;
end
-[allfiles,bb] = sort(allfiles);
+[allfiles] = sort(allfiles);
%Load all of the initialized exemplars
CACHE_FILE = 1;
Please sign in to comment.
Something went wrong with that request. Please try again.