Commit 2bf1ea6d authored by Ross Girshick's avatar Ross Girshick
Browse files

fix workflow of the pool5 feature explorer

parent 51511d0c
function [res_test, res_train] = rcnn_exp_train_and_test() function [res_test, res_train] = rcnn_exp_train_and_test()
% Runs an experiment that trains an R-CNN model and tests it.
% -------------------- CONFIG -------------------- % -------------------- CONFIG --------------------
net_file = './data/caffe_nets/finetune_voc_2007_trainval_iter_70k'; net_file = './data/caffe_nets/finetune_voc_2007_trainval_iter_70k';
......
...@@ -4,7 +4,7 @@ if exist('selective_search/SelectiveSearchCodeIJCV') ...@@ -4,7 +4,7 @@ if exist('selective_search/SelectiveSearchCodeIJCV')
addpath('selective_search/SelectiveSearchCodeIJCV/Dependencies'); addpath('selective_search/SelectiveSearchCodeIJCV/Dependencies');
else else
fprintf('Warning: you will need the selective search IJCV code.\n'); fprintf('Warning: you will need the selective search IJCV code.\n');
fprintf('Press any key to download it (runs ./selective_search/fetch_selective_search.sh)'); fprintf('Press any key to download it (runs ./selective_search/fetch_selective_search.sh)> ');
pause; pause;
system('./selective_search/fetch_selective_search.sh'); system('./selective_search/fetch_selective_search.sh');
addpath('selective_search/SelectiveSearchCodeIJCV'); addpath('selective_search/SelectiveSearchCodeIJCV');
...@@ -19,8 +19,9 @@ addpath('bbox_regression'); ...@@ -19,8 +19,9 @@ addpath('bbox_regression');
if exist('external/caffe/matlab/caffe') if exist('external/caffe/matlab/caffe')
addpath('external/caffe/matlab/caffe'); addpath('external/caffe/matlab/caffe');
else else
warning('Please install caffe in ./external/caffe'); warning('Please install Caffe in ./external/caffe');
end end
addpath('experiments'); addpath('experiments');
addpath('imdb'); addpath('imdb');
addpath('vis/pool5-explorer');
fprintf('R-CNN startup done\n'); fprintf('R-CNN startup done\n');
...@@ -11,11 +11,7 @@ function pool5_explorer(imdb, cache_name) ...@@ -11,11 +11,7 @@ function pool5_explorer(imdb, cache_name)
conf = rcnn_config('sub_dir', imdb.name); conf = rcnn_config('sub_dir', imdb.name);
index_file = sprintf('%s/pool5_explorer_index_%s', ... index = pool5_explorer_build_index(imdb, cache_name);
conf.cache_dir, cache_name);
% load pre-computed index into variable 'index'
load(index_file);
figures = [1 2]; figures = [1 2];
vf_sz = [8 12]; vf_sz = [8 12];
......
function pool5_explorer_build_index(imdb, cache_name) function index = pool5_explorer_build_index(imdb, cache_name)
% AUTORIGHTS % AUTORIGHTS
% --------------------------------------------------------- % ---------------------------------------------------------
% Copyright (c) 2014, Ross Girshick % Copyright (c) 2014, Ross Girshick
...@@ -23,73 +23,81 @@ conf = rcnn_config('sub_dir', imdb.name); ...@@ -23,73 +23,81 @@ conf = rcnn_config('sub_dir', imdb.name);
save_file = sprintf('%s/pool5_explorer_index_%s', ... save_file = sprintf('%s/pool5_explorer_index_%s', ...
conf.cache_dir, cache_name); conf.cache_dir, cache_name);
TOP_K = 1000; try
% Load already computed index
fprintf('trying to load: %s\n', save_file);
load(save_file);
catch
warning('Building the explorer index. This will take a long time.');
ids = imdb.image_ids; TOP_K = 1000;
% select features ids = imdb.image_ids;
sel_features = 1:(6*6*256);
index.imdb_name = imdb.name; % select features
index.images = ids; sel_features = 1:(6*6*256);
features = cell(length(sel_features), 1);
for i = 1:length(features) index.imdb_name = imdb.name;
features{i}.image_inds = []; index.images = ids;
features{i}.scores = []; features = cell(length(sel_features), 1);
features{i}.boxes = zeros(0, 4);
end
for i = 1:length(ids)
tic_toc_print('%d/%d', i, length(ids));
th = tic();
d = rcnn_load_cached_pool5_features(cache_name, ...
imdb.name, ids{i});
feat = d.feat; for i = 1:length(features)
features{i}.image_inds = [];
features{i}.scores = [];
features{i}.boxes = zeros(0, 4);
end
parfor f = sel_features for i = 1:length(ids)
threshold = min(features{f}.scores); tic_toc_print('%d/%d', i, length(ids));
if isempty(threshold) th = tic();
threshold = -inf; d = rcnn_load_cached_pool5_features(cache_name, ...
end imdb.name, ids{i});
sel_0 = find(feat(:,f) > threshold);
if isempty(sel_0) feat = d.feat;
continue;
parfor f = sel_features
threshold = min(features{f}.scores);
if isempty(threshold)
threshold = -inf;
end
sel_0 = find(feat(:,f) > threshold);
if isempty(sel_0)
continue;
end
bs = [d.boxes(sel_0,:) feat(sel_0,f)];
sel = nms(bs, 0.1);
sel = sel_0(sel);
sz = length(sel);
new_image_inds = i*ones(sz,1);
new_scores = feat(sel,f);
new_boxes = d.boxes(sel,:);
features{f}.image_inds = cat(1, features{f}.image_inds, ...
new_image_inds);
features{f}.scores = cat(1, features{f}.scores, ...
new_scores);
features{f}.boxes = cat(1, features{f}.boxes, ...
new_boxes);
[~, ord] = sort(features{f}.scores, 'descend');
if length(ord) > TOP_K
ord = ord(1:TOP_K);
end
features{f}.image_inds = features{f}.image_inds(ord);
features{f}.scores = features{f}.scores(ord);
features{f}.boxes = features{f}.boxes(ord, :);
end end
bs = [d.boxes(sel_0,:) feat(sel_0,f)]; fprintf(' %.3fs\n', toc(th));
sel = nms(bs, 0.1);
if mod(i, 50) == 0
sel = sel_0(sel); index.features = features;
sz = length(sel); save(save_file, 'index');
fprintf('checkpoint %d\n', i);
new_image_inds = i*ones(sz,1);
new_scores = feat(sel,f);
new_boxes = d.boxes(sel,:);
features{f}.image_inds = cat(1, features{f}.image_inds, ...
new_image_inds);
features{f}.scores = cat(1, features{f}.scores, ...
new_scores);
features{f}.boxes = cat(1, features{f}.boxes, ...
new_boxes);
[~, ord] = sort(features{f}.scores, 'descend');
if length(ord) > TOP_K
ord = ord(1:TOP_K);
end end
features{f}.image_inds = features{f}.image_inds(ord);
features{f}.scores = features{f}.scores(ord);
features{f}.boxes = features{f}.boxes(ord, :);
end end
fprintf(' %.3fs\n', toc(th));
if mod(i, 50) == 0 index.features = features;
index.features = features; save(save_file, 'index');
save(save_file, 'index');
fprintf('checkpoint %d\n', i);
end
end end
index.features = features;
save(save_file, 'index');
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment