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()
% Runs an experiment that trains an R-CNN model and tests it.
% -------------------- CONFIG --------------------
net_file = './data/caffe_nets/finetune_voc_2007_trainval_iter_70k';
......
......@@ -4,7 +4,7 @@ if exist('selective_search/SelectiveSearchCodeIJCV')
addpath('selective_search/SelectiveSearchCodeIJCV/Dependencies');
else
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;
system('./selective_search/fetch_selective_search.sh');
addpath('selective_search/SelectiveSearchCodeIJCV');
......@@ -19,8 +19,9 @@ addpath('bbox_regression');
if exist('external/caffe/matlab/caffe')
addpath('external/caffe/matlab/caffe');
else
warning('Please install caffe in ./external/caffe');
warning('Please install Caffe in ./external/caffe');
end
addpath('experiments');
addpath('imdb');
addpath('vis/pool5-explorer');
fprintf('R-CNN startup done\n');
......@@ -11,11 +11,7 @@ function pool5_explorer(imdb, cache_name)
conf = rcnn_config('sub_dir', imdb.name);
index_file = sprintf('%s/pool5_explorer_index_%s', ...
conf.cache_dir, cache_name);
% load pre-computed index into variable 'index'
load(index_file);
index = pool5_explorer_build_index(imdb, cache_name);
figures = [1 2];
vf_sz = [8 12];
......
function pool5_explorer_build_index(imdb, cache_name)
function index = pool5_explorer_build_index(imdb, cache_name)
% AUTORIGHTS
% ---------------------------------------------------------
% Copyright (c) 2014, Ross Girshick
......@@ -23,73 +23,81 @@ conf = rcnn_config('sub_dir', imdb.name);
save_file = sprintf('%s/pool5_explorer_index_%s', ...
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
sel_features = 1:(6*6*256);
ids = imdb.image_ids;
index.imdb_name = imdb.name;
index.images = ids;
features = cell(length(sel_features), 1);
% select features
sel_features = 1:(6*6*256);
for i = 1:length(features)
features{i}.image_inds = [];
features{i}.scores = [];
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});
index.imdb_name = imdb.name;
index.images = ids;
features = cell(length(sel_features), 1);
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
threshold = min(features{f}.scores);
if isempty(threshold)
threshold = -inf;
end
sel_0 = find(feat(:,f) > threshold);
if isempty(sel_0)
continue;
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;
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
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);
fprintf(' %.3fs\n', toc(th));
if mod(i, 50) == 0
index.features = features;
save(save_file, 'index');
fprintf('checkpoint %d\n', i);
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
fprintf(' %.3fs\n', toc(th));
if mod(i, 50) == 0
index.features = features;
save(save_file, 'index');
fprintf('checkpoint %d\n', i);
end
index.features = features;
save(save_file, 'index');
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