Skip to content
Snippets Groups Projects
Commit bd90015c authored by Ross Girshick's avatar Ross Girshick
Browse files

output directory

parent bb46c698
No related branches found
No related tags found
No related merge requests found
function res = voc_eval(path, comp_id, test_set, rm_res)
function res = voc_eval(path, comp_id, test_set, output_dir, rm_res)
VOCopts = get_voc_opts(path);
VOCopts.testset = test_set;
for i = 1:length(VOCopts.classes)
cls = VOCopts.classes{i};
res(i) = voc_eval_cls(cls, VOCopts, comp_id, rm_res);
res(i) = voc_eval_cls(cls, VOCopts, comp_id, output_dir, rm_res);
end
fprintf('\n~~~~~~~~~~~~~~~~~~~~\n');
......@@ -15,7 +15,7 @@ disp(aps);
disp(mean(aps));
fprintf('~~~~~~~~~~~~~~~~~~~~\n');
function res = voc_eval_cls(cls, VOCopts, comp_id, rm_res)
function res = voc_eval_cls(cls, VOCopts, comp_id, output_dir, rm_res)
test_set = VOCopts.testset;
year = VOCopts.dataset(4:end);
......@@ -36,12 +36,12 @@ if do_eval
[recall, prec, ap] = VOCevaldet(VOCopts, comp_id, cls, true);
ap_auc = xVOCap(recall, prec);
% % force plot limits
% ylim([0 1]);
% xlim([0 1]);
% force plot limits
ylim([0 1]);
xlim([0 1]);
% print(gcf, '-djpeg', '-r0', ...
% [conf.cache_dir cls '_pr_' imdb.name suffix '.jpg']);
print(gcf, '-djpeg', '-r0', ...
[output_dir '/' cls '_pr.jpg']);
end
fprintf('!!! %s : %.4f %.4f\n', cls, ap, ap_auc);
......@@ -50,8 +50,8 @@ res.prec = prec;
res.ap = ap;
res.ap_auc = ap_auc;
%save([conf.cache_dir cls '_pr_' imdb.name '_py'], ...
% 'res', 'recall', 'prec', 'ap', 'ap_auc');
save([output_dir '/' cls '_pr.mat'], ...
'res', 'recall', 'prec', 'ap', 'ap_auc');
if rm_res
delete(res_fn);
......
......@@ -67,7 +67,7 @@ class imdb(object):
def default_roidb(self):
raise NotImplementedError
def evaluate_detections(self, all_boxes):
def evaluate_detections(self, all_boxes, output_dir=None):
"""
all_boxes is a list of length number-of-classes.
Each list element is a list of length number-of-images.
......
......@@ -232,7 +232,7 @@ class pascal_voc(datasets.imdb):
dets[k, 2] + 1, dets[k, 3] + 1))
return comp_id
def _do_matlab_eval(self, comp_id):
def _do_matlab_eval(self, comp_id, output_dir='output'):
rm_results = self.config['cleanup']
path = os.path.join(os.path.dirname(__file__),
......@@ -240,15 +240,15 @@ class pascal_voc(datasets.imdb):
cmd = 'cd {} && '.format(path)
cmd += 'matlab -nodisplay -nodesktop '
cmd += '-r "dbstop if error; '
cmd += 'voc_eval(\'{:s}\', \'{:s}\', \'{:s}\', {:d}); quit;"' \
cmd += 'voc_eval(\'{:s}\',\'{:s}\',\'{:s}\',\'{:s}\',{:d}); quit;"' \
.format(self._devkit_path, comp_id,
self._image_set, int(rm_results))
self._image_set, output_dir, int(rm_results))
print('Running:\n{}'.format(cmd))
status = subprocess.call(cmd, shell=True)
def evaluate_detections(self, all_boxes):
def evaluate_detections(self, all_boxes, output_dir):
comp_id = self._write_voc_results_file(all_boxes)
self._do_matlab_eval(comp_id)
self._do_matlab_eval(comp_id, output_dir)
if __name__ == '__main__':
d = datasets.pascal_voc('trainval', '2007')
......
......@@ -4,6 +4,7 @@ import fast_rcnn_test
import caffe
import argparse
import sys
import os
def parse_args():
"""
......@@ -33,6 +34,7 @@ if __name__ == '__main__':
caffe.set_mode_gpu()
caffe.set_device(args.gpu_id)
net = caffe.Net(args.prototxt, args.caffemodel, caffe.TEST)
net.name = os.path.splitext(os.path.basename(args.caffemodel))[0]
import datasets.pascal_voc
imdb = datasets.pascal_voc('test', '2007')
......
......@@ -10,6 +10,7 @@ import utils.cython_nms
import cPickle
import heapq
import utils.blob
import os
def _get_image_blob(im):
im_pyra = []
......@@ -204,6 +205,13 @@ def test_net(net, imdb):
all_boxes = [[[] for _ in xrange(num_images)]
for _ in xrange(imdb.num_classes)]
# Output directory will be something like:
# output/vgg16_fast_rcnn_iter_40000/voc_2007_test/
output_dir = os.path.join(os.path.dirname(__file__), 'output',
net.name, imdb.name)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# timers
_t = {'im_detect' : Timer(), 'misc' : Timer()}
......@@ -251,12 +259,12 @@ def test_net(net, imdb):
inds = np.where(all_boxes[j][i][:, -1] > thresh[j])[0]
all_boxes[j][i] = all_boxes[j][i][inds, :]
# TODO(rbg): need to have an output directory to save results in
with open('dets.pkl', 'wb') as f:
det_file = os.path.join(output_dir, 'detections.pkl')
with open(det_file, 'wb') as f:
cPickle.dump(all_boxes, f, cPickle.HIGHEST_PROTOCOL)
print 'Applying NMS to all detections'
nms_dets = _apply_nms(all_boxes, conf.TEST_NMS)
print 'Evaluating detections'
imdb.evaluate_detections(nms_dets)
imdb.evaluate_detections(nms_dets, output_dir)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment