Skip to content

Commit

Permalink
add args to tools/reval.py; fix comp_mode abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
rbgirshick committed Apr 30, 2015
1 parent 58300b5 commit fb33dba
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 18 deletions.
4 changes: 4 additions & 0 deletions lib/datasets/imdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,7 @@ def merge_roidbs(a, b):
a[i]['gt_overlaps'] = scipy.sparse.vstack([a[i]['gt_overlaps'],
b[i]['gt_overlaps']])
return a

def competition_mode(self, on):
"""Turn competition mode on or off."""
pass
8 changes: 8 additions & 0 deletions lib/datasets/pascal_voc.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ def evaluate_detections(self, all_boxes, output_dir):
comp_id = self._write_voc_results_file(all_boxes)
self._do_matlab_eval(comp_id, output_dir)

def competition_mode(self, on):
if on:
self.config['use_salt'] = False
self.config['cleanup'] = False
else:
self.config['use_salt'] = True
self.config['cleanup'] = True

if __name__ == '__main__':
d = datasets.pascal_voc('trainval', '2007')
res = d.roidb
Expand Down
51 changes: 39 additions & 12 deletions tools/reval.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,39 @@
from fast_rcnn.config import cfg
from datasets.factory import get_imdb
import cPickle
import os, sys
import os, sys, argparse
import numpy as np

def parse_args():
"""
Parse input arguments
"""
parser = argparse.ArgumentParser(description='Re-evaluate results')
parser.add_argument('output_dir', nargs=1, help='results directory',
type=str)
parser.add_argument('--rerun', dest='rerun',
help=('re-run evaluation code '
'(otherwise: results are loaded from file)'),
action='store_true')
parser.add_argument('--imdb', dest='imdb_name',
help='dataset to re-evaluate',
default='voc_2007_test', type=str)
parser.add_argument('--comp', dest='comp_mode', help='competition mode',
action='store_true')

if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)

args = parser.parse_args()
return args


def from_mats(imdb_name, output_dir):
import scipy.io as sio

imdb = get_imdb(imdb_name)

aps = []
for i, cls in enumerate(imdb.classes[1:]):
mat = sio.loadmat(os.path.join(output_dir, cls + '_pr.mat'))
Expand All @@ -37,10 +63,9 @@ def from_mats(imdb_name, output_dir):
print '~~~~~~~~~~~~~~~~~~~'


def from_dets(imdb_name, output_dir):
def from_dets(imdb_name, output_dir, comp_mode):
imdb = get_imdb(imdb_name)
imdb.config['use_salt'] = False
imdb.config['cleanup'] = False
imdb.competition_mode(comp_mode)
with open(os.path.join(output_dir, 'detections.pkl'), 'rb') as f:
dets = cPickle.load(f)

Expand All @@ -51,13 +76,15 @@ def from_dets(imdb_name, output_dir):
imdb.evaluate_detections(nms_dets, output_dir)

if __name__ == '__main__':
# 'output/top_1000/voc_2007_test/vgg_cnn_m_1024_fast_rcnn_iter_40000'
output_dir = sys.argv[1]
output_dir = os.path.abspath(os.path.join(os.path.dirname(__file__),
'..', output_dir))
imdb_name = 'voc_2007_test'
args = parse_args()

if len(sys.argv) > 2:
from_mats(imdb_name, output_dir)
output_dir = os.path.abspath(args.output_dir[0])
imdb_name = args.imdb_name

if args.comp_mode and not args.rerun:
raise ValueError('--rerun must be used with --comp')

if args.rerun:
from_dets(imdb_name, output_dir, args.comp_mode)
else:
from_dets(imdb_name, output_dir)
from_mats(imdb_name, output_dir)
8 changes: 2 additions & 6 deletions tools/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def parse_args():
help='dataset to test',
default='voc_2007_test', type=str)
parser.add_argument('--comp', dest='comp_mode', help='competition mode',
default=False, type=bool)
action='store_true')

if len(sys.argv) == 1:
parser.print_help()
Expand Down Expand Up @@ -71,10 +71,6 @@ def parse_args():
net.name = os.path.splitext(os.path.basename(args.caffemodel))[0]

imdb = get_imdb(args.imdb_name)
if args.comp_mode:
if 'use_salt' in imdb.config:
imdb.config['use_salt'] = False
if 'cleanup' in imdb.config:
imdb.config['cleanup'] = False
imdb.competition_mode(args.comp_mode)

test_net(net, imdb)

0 comments on commit fb33dba

Please sign in to comment.