示例#1
0
def _selective_search_IJCV_top_k(split, year, top_k):
    """Return an imdb that uses the top k proposals from the selective search
    IJCV code.
    """
    imdb = pascal_voc(split, year)
    imdb.roidb_handler = imdb.selective_search_IJCV_roidb
    imdb.config["top_k"] = top_k
    return imdb
示例#2
0
# --------------------------------------------------------

"""Factory method for easily getting imdbs by name."""

__sets = {}

from datasets.pascal_voc import pascal_voc
from datasets.coco import coco
from datasets.grotoap2 import grotoap2
import numpy as np

# Set up voc_<year>_<split> using selective search "fast" mode
for year in ['2007', '2012']:
    for split in ['train', 'val', 'trainval', 'test']:
        name = 'voc_{}_{}'.format(year, split)
        __sets[name] = (lambda split=split, year=year: pascal_voc(split, year))

# Set up coco_2014_<split>
for year in ['2014']:
    for split in ['train', 'val', 'minival', 'valminusminival']:
        name = 'coco_{}_{}'.format(year, split)
        __sets[name] = (lambda split=split, year=year: coco(split, year))

# Set up coco_2015_<split>
for year in ['2015']:
    for split in ['test', 'test-dev']:
        name = 'coco_{}_{}'.format(year, split)
        __sets[name] = (lambda split=split, year=year: coco(split, year))

# Set up grotoap2
for split in ['train', 'val', 'trainval', 'test']:
示例#3
0
  def evaluate_detections(self, all_boxes, output_dir):
    self._write_voc_results_file(all_boxes)
    self._do_python_eval(output_dir)
    if self.config['matlab_eval']:
      self._do_matlab_eval(output_dir)
    if self.config['cleanup']:
      for cls in self._classes:
        if cls == '__background__':
          continue
        filename = self._get_voc_results_file_template().format(cls)
        os.remove(filename)

  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__':
  from datasets.pascal_voc import pascal_voc

  d = pascal_voc('trainval', '2007')
  res = d.roidb
  from IPython import embed;

  embed()
示例#4
0
    def evaluate_detections(self, all_boxes, output_dir):
        self._write_voc_results_file(all_boxes)
        self._do_python_eval(output_dir)
        if self.config["matlab_eval"]:
            self._do_matlab_eval(output_dir)
        if self.config["cleanup"]:
            for cls in self._classes:
                if cls == "__background__":
                    continue
                filename = self._get_voc_results_file_template().format(cls)
                os.remove(filename)

    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__":
    from datasets.pascal_voc import pascal_voc

    d = pascal_voc("trainval", "2007")
    res = d.roidb
    from IPython import embed

    embed()
示例#5
0
def _selective_search_IJCV_top_k(split, year, top_k):
    """Return an imdb that uses the top k proposals from the selective search
    IJCV code.
    """
    imdb = pascal_voc(split, year)
    imdb.roidb_handler = imdb.selective_search_IJCV_roidb
    imdb.config['top_k'] = top_k
    return imdb

# Set up voc_<year>_<split> using selective search "fast" mode
for year in ['2007', '2012','1207']:
    for split in ['train', 'val', 'trainval', 'test']:
        name = 'voc_{}_{}'.format(year, split)
        __sets[name] = (lambda split=split, year=year:
                pascal_voc(split, year))

# Set up voc_<year>_<split>_top_<k> using selective search "quality" mode
# but only returning the first k boxes
for top_k in np.arange(1000, 11000, 1000):
    for year in ['2007', '2012','1207']:
        for split in ['train', 'val', 'trainval', 'test']:
            name = 'voc_{}_{}_top_{:d}'.format(year, split, top_k)
            __sets[name] = (lambda split=split, year=year, top_k=top_k:
                    _selective_search_IJCV_top_k(split, year, top_k))

def get_imdb(name):
    """Get an imdb (image database) by name."""
    if not __sets.has_key(name):
        raise KeyError('Unknown dataset: {}'.format(name))
    return __sets[name]()
示例#6
0
"""Factory method for easily getting imdbs by name."""

__sets = {}

from datasets.pascal_voc import pascal_voc
from datasets.coco import coco
import numpy as np

# Set up voc_<year>_<split> using selective search "fast" mode
for year in ['2007', '2012']:
    for split in ['train', 'val', 'trainval', 'test']:
        name = 'voc_{}_{}'.format(year, split)

        __sets[name] = (lambda split=split, year=year:
                pascal_voc(split, year))

__sets["ak47_train"] = (lambda split='train', year='ak47': pascal_voc(split, year))
__sets["ships_train"] = (lambda split='train', year='ships': pascal_voc(split, year))


# Set up voc_<year>_<split>_top_<k> using selective search "quality" mode
# but only returning the first k boxes
for top_k in np.arange(1000, 11000, 1000):
    for year in ['2007', '2012']:
        for split in ['train', 'val', 'trainval', 'test']:
            name = 'voc_{}_{}_top_{:d}'.format(year, split, top_k)
            __sets[name] = (lambda split=split, year=year, top_k=top_k:
                    _selective_search_IJCV_top_k(split, year, top_k))

# Set up coco_2014_<split>
示例#7
0
# --------------------------------------------------------
"""Factory method for easily getting imdbs by name."""

__sets = {}

from datasets.pascal_voc import pascal_voc
from datasets.coco import coco
from datasets.imagenet import imagenet
from datasets.our_dataset import our_dataset
import numpy as np

# Set up voc_<year>_<split> using selective search "fast" mode
for year in ['2007', '2012', '0712']:
    for split in ['train', 'val', 'trainval', 'test']:
        name = 'voc_{}_{}'.format(year, split)
        __sets[name] = (lambda split=split, year=year: pascal_voc(split, year))

for split in ['train', 'val']:
    name = 'imagenet_{}'.format(split)
    devkit_path = '/scratch0/ILSVRC/devkit/'
    data_path = '/scratch0/ILSVRC2015/'
    __sets[name] = (lambda split=split, devkit_path=devkit_path, data_path=
                    data_path: imagenet(split, devkit_path, data_path))
    print name
    print __sets[name]

# for our dataset

__sets['our_dataset'] = (
    lambda image_set='our_dataset', data_path=
    '/sdb/duyong/Datasets/objDetData/train/samples', img_list=
示例#8
0
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

__sets = {}
from datasets.pascal_voc import pascal_voc
from datasets.icpr import icpr_imdb
#from datasets.coco import coco

import numpy as np

# Set up voc_<year>_<split> 
for year in ['2007', '2012']:
  for split in ['train', 'val', 'trainval', 'test']:
    name = 'voc_{}_{}'.format(year, split)
    __sets[name] = (lambda split=split, year=year: pascal_voc(split, year))

for year in ['2007', '2012']:
  for split in ['train', 'val', 'trainval', 'test']:
    name = 'voc_{}_{}_diff'.format(year, split)
    __sets[name] = (lambda split=split, year=year: pascal_voc(split, year, use_diff=True))

# Set up icpr_<year>_<split> 
for year in ['2018']:
  for split in ['trainval', 'test']:
    name = 'icpr_{}_{}'.format(year, split)
    __sets[name] = (lambda split=split, year=year: icpr_imdb(split, year, use_diff = False))

# Set up coco_2014_<split>
for year in ['2014']:
  for split in ['train', 'val', 'minival', 'valminusminival', 'trainval']:
示例#9
0
               .format(self._devkit_path, self._get_comp_id(),
                       self._image_set, output_dir)
        print('Running:\n{}'.format(cmd))
        status = subprocess.call(cmd, shell=True)

    def evaluate_detections(self, all_boxes, output_dir):
        self._write_voc_results_file(all_boxes)
        self._do_python_eval(output_dir)
        if self.config['matlab_eval']:
            self._do_matlab_eval(output_dir)
        if self.config['cleanup']:
            for cls in self._classes:
                if cls == '__background__':
                    continue
                filename = self._get_voc_results_file_template().format(cls)
                os.remove(filename)

    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__':
    from datasets.pascal_voc import pascal_voc
    d = pascal_voc('train', '2007')
    res = d.roidb
    from IPython import embed; embed()
示例#10
0
        print('Running:\n{}'.format(cmd))
        status = subprocess.call(cmd, shell=True)

    def evaluate_detections(self, all_boxes, output_dir):
        self._write_voc_results_file(all_boxes)
        self._do_python_eval(output_dir)
        if self.config['matlab_eval']:
            self._do_matlab_eval(output_dir)
        if self.config['cleanup']:
            for cls in self._classes:
                if cls == '__background__':
                    continue
                filename = self._get_voc_results_file_template().format(cls)
                os.remove(filename)

    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__':
    from datasets.pascal_voc import pascal_voc
    d = pascal_voc('trainval', '2007')
    res = d.roidb
    from IPython import embed
    embed()
示例#11
0
# --------------------------------------------------------
"""Factory method for easily getting imdbs by name."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

__sets = {}
from datasets.pascal_voc import pascal_voc
from datasets.coco import coco
import numpy as np

# Set up voc_<year>_<split>
for year in ['2007', '2012']:
    for split in ['train', 'val', 'trainval', 'test']:
        name = 'voc_{}_{}'.format(year, split)
        __sets[name] = (lambda split=split, year=year: pascal_voc(split, year))
for year in ['2007', '2012']:
    for split in ['train', 'val', 'trainval', 'test']:
        name = 'voc_{}_{}_diff'.format(year, split)
        __sets[name] = (lambda split=split, year=year: pascal_voc(
            split, year, use_diff=True))

# Set up coco_2014_<split>
for year in ['2014']:
    for split in ['train', 'val', 'minival', 'valminusminival', 'trainval']:
        name = 'coco_{}_{}'.format(year, split)
        __sets[name] = (lambda split=split, year=year: coco(split, year))

# Set up coco_2015_<split>
for year in ['2015']:
    for split in ['test', 'test-dev']:
示例#12
0
    def __init__(self, image_set, year, devkit_path=None, shuffled=None):
        
        imdb.__init__(self, 'merged_' + image_set)
        self._year = year
        self._image_set = image_set
        self._anno_set_dir = image_set
        if "val" in image_set:
            self._image_set_dir = "val"
            if "val1" in image_set:
                self._anno_set_dir = "val1"
            if "val2" in image_set:
                self._anno_set_dir = "val2"
        elif "train" in image_set:
            self._anno_set_dir = "train"
        elif "test" in image_set:
            self._anno_set_dir = "test"
        
        if image_set == "train":
            self.imdbs = [imagenet(image_set),\
                        coco(image_set, '2015'),\
                        cam2(image_set,'2017'),\
                        sun(image_set,'2012'),\
                        caltech(image_set,'2009'),\
                        kitti(image_set,'2013'),\
                        inria(image_set,'2005'),\
                        pascal_voc(image_set,'2007'),\
                        pascal_voc(image_set,'2012')]
        elif image_set == "test":
            self.imdbs = [imagenet('val'),\
                        coco('test-dev', '2015'),\
                        cam2('all','2017'),\
                        sun('test','2012'),\
                        caltech('test','2009'),\
                        kitti('val','2013'),\
                        inria('all','2005'),\
                        pascal_voc('test','2007')]

        self.roidbs = [None for _ in range(len(self.datasets))]
        for idx,imdb in enumerate(self.imdbs):
            self.roidbs[idx] = get_training_roidb(imdb)

        self._devkit_path = self._get_default_path() if devkit_path is None \
                            else devkit_path
        self._data_path = os.path.join(self._devkit_path, 'VOC' + self._year)
        self._classes = ('__background__', # always index 0
                         'voc',
                         'imagenet',
                         'caltech',
                         'coco',
                         'sun',
                         'kitti',
                         'inria',
                         'cam2')
        self._class_to_ind = dict(zip(self.classes, xrange(self.num_classes)))
        self._image_ext = '.jpg'
        self._image_index = self._load_image_set_index()
        # Default to roidb handler
        self._roidb_handler = self.selective_search_roidb
        self._salt = str(uuid.uuid4())
        self._comp_id = 'comp4'

        # PASCAL specific config options
        self.config = {'cleanup'     : True,
                       'use_salt'    : True,
                       'use_diff'    : False,
                       'matlab_eval' : False,
                       'rpn_file'    : None,
                       'min_size'    : 2}

        assert os.path.exists(self._devkit_path), \
                'VOCdevkit path does not exist: {}'.format(self._devkit_path)
        assert os.path.exists(self._data_path), \
                'Path does not exist: {}'.format(self._data_path)
示例#13
0
class merged(imdb):

    def __init__(self, image_set, year, devkit_path=None, shuffled=None):
        
        imdb.__init__(self, 'merged_' + image_set)
        self._year = year
        self._image_set = image_set
        self._anno_set_dir = image_set
        if "val" in image_set:
            self._image_set_dir = "val"
            if "val1" in image_set:
                self._anno_set_dir = "val1"
            if "val2" in image_set:
                self._anno_set_dir = "val2"
        elif "train" in image_set:
            self._anno_set_dir = "train"
        elif "test" in image_set:
            self._anno_set_dir = "test"
        
        if image_set == "train":
            self.imdbs = [imagenet(image_set),\
                        coco(image_set, '2015'),\
                        cam2(image_set,'2017'),\
                        sun(image_set,'2012'),\
                        caltech(image_set,'2009'),\
                        kitti(image_set,'2013'),\
                        inria(image_set,'2005'),\
                        pascal_voc(image_set,'2007'),\
                        pascal_voc(image_set,'2012')]
        elif image_set == "test":
            self.imdbs = [imagenet('val'),\
                        coco('test-dev', '2015'),\
                        cam2('all','2017'),\
                        sun('test','2012'),\
                        caltech('test','2009'),\
                        kitti('val','2013'),\
                        inria('all','2005'),\
                        pascal_voc('test','2007')]

        self.roidbs = [None for _ in range(len(self.datasets))]
        for idx,imdb in enumerate(self.imdbs):
            self.roidbs[idx] = get_training_roidb(imdb)

        self._devkit_path = self._get_default_path() if devkit_path is None \
                            else devkit_path
        self._data_path = os.path.join(self._devkit_path, 'VOC' + self._year)
        self._classes = ('__background__', # always index 0
                         'voc',
                         'imagenet',
                         'caltech',
                         'coco',
                         'sun',
                         'kitti',
                         'inria',
                         'cam2')
        self._class_to_ind = dict(zip(self.classes, xrange(self.num_classes)))
        self._image_ext = '.jpg'
        self._image_index = self._load_image_set_index()
        # Default to roidb handler
        self._roidb_handler = self.selective_search_roidb
        self._salt = str(uuid.uuid4())
        self._comp_id = 'comp4'

        # PASCAL specific config options
        self.config = {'cleanup'     : True,
                       'use_salt'    : True,
                       'use_diff'    : False,
                       'matlab_eval' : False,
                       'rpn_file'    : None,
                       'min_size'    : 2}

        assert os.path.exists(self._devkit_path), \
                'VOCdevkit path does not exist: {}'.format(self._devkit_path)
        assert os.path.exists(self._data_path), \
                'Path does not exist: {}'.format(self._data_path)

    def image_path_at(self, i):
        """
        Return the absolute path to image i in the image sequence.
        """
        return self.image_path_from_index(self._image_index[i])

    def image_path_from_index(self, index):
        """
        Construct an image path from the image's "index" identifier.
        """
        image_path = os.path.join(self._data_path, 'JPEGImages',
                                  index + self._image_ext)
        assert os.path.exists(image_path), \
                'Path does not exist: {}'.format(image_path)
        return image_path

    def _load_image_set_index(self):
        """
        Load the indexes listed in this dataset's image set file.
        """
        # Example path to image set file:
        # self._devkit_path + /VOCdevkit2007/VOC2007/ImageSets/Main/val.txt
        image_set_file = os.path.join(self._data_path, 'ImageSets', 'Main',
                                      self._image_set + '.txt')
        assert os.path.exists(image_set_file), \
                'Path does not exist: {}'.format(image_set_file)
        with open(image_set_file) as f:
            image_index = [x.strip() for x in f.readlines()]
        return image_index

    def _get_default_path(self):
        """
        Return the default path where PASCAL VOC is expected to be installed.
        """
        return os.path.join(cfg.DATA_DIR, 'VOCdevkit' + self._year)

    def gt_roidb(self):
        """
        Return the database of ground-truth regions of interest.

        This function loads/saves from/to a cache file to speed up future calls.
        """
        cache_file = os.path.join(self.cache_path, self.name + '_gt_roidb.pkl')
        if os.path.exists(cache_file):
            with open(cache_file, 'rb') as fid:
                roidb = cPickle.load(fid)
            print '{} gt roidb loaded from {}'.format(self.name, cache_file)
            return roidb

        
        _image_path = []
        _image_index = []
        gt_roidb = []
        for dataset in datasets:
            _image_path += dataset._image_path
            _image_index_ = dataset._image_index
            for idx,ind in enumerate(_image_index):
                _image_index[idx] = index(ind,dataset.name)
            gt_roidb += np.repeat(self._class_to_ind(dataset['name']),\
                                [dataset['num_imgs']],axis=0)

        with open(cache_file, 'wb') as fid:
            cPickle.dump(gt_roidb, fid, cPickle.HIGHEST_PROTOCOL)
        print 'wrote gt roidb to {}'.format(cache_file)

        return gt_roidb

    def image_path_from_index(self,index):
        """
        Construct an image path from the image's "index" identifier.
        """
        if index.dataset
        image_path = os.path.join(self._data_path, 'JPEGImages',
                                  index + self._image_ext)
        assert os.path.exists(image_path), \
                'Path does not exist: {}'.format(image_path)
        return image_path

        
    def _load_pascal_annotation(self, index):
        """
        Load image and bounding boxes info from XML file in the PASCAL VOC
        format.
        """
        filename = os.path.join(self._data_path, 'Annotations', index + '.xml')
        tree = ET.parse(filename)
        objs = tree.findall('object')
        if not self.config['use_diff']:
            # Exclude the samples labeled as difficult
            non_diff_objs = [
                obj for obj in objs if int(obj.find('difficult').text) == 0]
            # if len(non_diff_objs) != len(objs):
            #     print 'Removed {} difficult objects'.format(
            #         len(objs) - len(non_diff_objs))
            objs = non_diff_objs
        num_objs = len(objs)

        boxes = np.zeros((num_objs, 4), dtype=np.uint16)
        gt_classes = np.zeros((num_objs), dtype=np.int32)
        overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32)
        # "Seg" area for pascal is just the box area
        seg_areas = np.zeros((num_objs), dtype=np.float32)

        # Load object bounding boxes into a data frame.
        for ix, obj in enumerate(objs):
            bbox = obj.find('bndbox')
            # Make pixel indexes 0-based
            x1 = float(bbox.find('xmin').text) - 1
            y1 = float(bbox.find('ymin').text) - 1
            x2 = float(bbox.find('xmax').text) - 1
            y2 = float(bbox.find('ymax').text) - 1
            #cls = self._class_to_ind['person']
            cls = self._class_to_ind[obj.find('name').text.lower().strip()]
            boxes[ix, :] = [x1, y1, x2, y2]
            gt_classes[ix] = cls
            overlaps[ix, cls] = 1.0
            seg_areas[ix] = (x2 - x1 + 1) * (y2 - y1 + 1)

        overlaps = scipy.sparse.csr_matrix(overlaps)

        return {'boxes' : boxes,
                'gt_classes': gt_classes,
                'gt_overlaps' : overlaps,
                'flipped' : False,
                'seg_areas' : seg_areas}

    def _get_comp_id(self):
        comp_id = (self._comp_id + '_' + self._salt if self.config['use_salt']
            else self._comp_id)
        return comp_id

    def _get_voc_results_file_template(self):
        # VOCdevkit/results/VOC2007/Main/<comp_id>_det_test_aeroplane.txt
        filename = self._get_comp_id() + '_det_' + self._image_set + '_{:s}.txt'
        path = os.path.join(
            self._devkit_path,
            'results',
            'VOC' + self._year,
            'Main',
            filename)
        return path

    def _write_voc_results_file(self, all_boxes):
        for cls_ind, cls in enumerate(self.classes):
            count = 0
            skip_count = 0
            det_count = 0
            if cls == '__background__':
                continue
            print 'Writing {} VOC results file'.format(cls)
            filename = self._get_voc_results_file_template().format(cls)
            #det_count = 0
            #count = 0
            with open(filename, 'wt') as f:
                for im_ind, index in enumerate(self.image_index):
                    dets = all_boxes[cls_ind][im_ind]
                    #det_count = det_count + dets.size
                    #print("{} : {}".format(cls,dets.size))
                    if len(dets) == 0:
                        skip_count+=1
                        continue
                    # the VOCdevkit expects 1-based indices

                    for k in xrange(dets.shape[0]):
                        #count = count + 1
                        f.write('{:s} {:.3f} {:.1f} {:.1f} {:.1f} {:.1f}\n'.
                                format(index, dets[k, -1],
                                       dets[k, 0] + 1, dets[k, 1] + 1,
                                       dets[k, 2] + 1, dets[k, 3] + 1))
            #TODO : verify if the "+1" if is correct
            #print "Wrote {} annotations to {}".format(count,filename)
            #print "The number of non-zero det classes: {}".format(det_count)
            #print("{}: skipped {} of {}".format(cls_ind,skip_count,len(all_boxes[cls_ind])))

    def _do_python_eval(self, output_dir = 'output'):
        annopath = os.path.join(
            self._devkit_path,
            'VOC' + self._year,
            'Annotations',
            '{:s}.xml')
        imagesetfile = os.path.join(
            self._devkit_path,
            'VOC' + self._year,
            'ImageSets',
            'Main',
            self._image_set + '.txt')
        cachedir = os.path.join(self._devkit_path, 'annotations_cache',self._anno_set_dir)
        aps = []
        # The PASCAL VOC metric changed in 2010
        use_07_metric = True if int(self._year) < 2010 else False
        print 'VOC07 metric? ' + ('Yes' if use_07_metric else 'No')
        if not os.path.isdir(output_dir):
            os.mkdir(output_dir)
        for i, cls in enumerate(self._classes):
            if cls == '__background__':
                continue
            filename = self._get_voc_results_file_template().format(cls)
            rec, prec, ap, ovthresh = voc_eval(
                filename, annopath, imagesetfile, cls, cachedir, ovthresh=0.5,
                use_07_metric=use_07_metric)
            aps += [ap]
        aps = np.array(aps)
        results_fd = open("./results_voc.txt","w")
        for kdx in range(len(ovthresh)):
            #print('{0:.3f}@{1:.2f}'.format(ap[kdx],ovthresh[kdx]))
            print('Mean AP = {:.4f} @ {:.2f}'.format(np.mean(aps[:,kdx]),ovthresh[kdx]))
        print('~~~~~~~~')
        print('Results:')
        count_ = 1
        sys.stdout.write('{0:>15} (#):'.format("class AP"))
        results_fd.write('{0:>15} (#):'.format("class AP"))
        for thsh in ovthresh:
            sys.stdout.write("\t{:>5}{:.3f}".format("@",thsh))
            results_fd.write("\t{:>5}{:.3f}".format("@",thsh))
        sys.stdout.write("\n")
        results_fd.write("\n")
        for ap in aps:
            sys.stdout.write('{:>15} ({}):'.format(self._classes[count_],count_))
            results_fd.write('{:>15} ({}):'.format(self._classes[count_],count_))
            for kdx in range(len(ovthresh)):
                sys.stdout.write('\t{0:>10.5f}'.format(ap[kdx],ovthresh[kdx]))
                results_fd.write('\t{0:>10.5f}'.format(ap[kdx],ovthresh[kdx]))
            sys.stdout.write('\n')
            results_fd.write('\n')
            count_ +=1
        sys.stdout.write('{:>15}:'.format("mAP"))
        results_fd.write('{:>15}:'.format("mAP"))
        for kdx in range(len(ovthresh)):
            sys.stdout.write('\t{:10.5f}'.format(np.mean(aps[:,kdx])))
            results_fd.write('\t{:10.5f}'.format(np.mean(aps[:,kdx])))
            #print('{0:.3f}@{1:.2f}'.format(ap[kdx],ovthresh[kdx]))
            #print('mAP @ {:.2f}: {:.5f} '.format(ovthresh[kdx],np.mean(aps[:,kdx])))
        sys.stdout.write('\n')
        results_fd.write('\n')
        print('~~~~~~~~')
        print('')
        print('--------------------------------------------------------------')
        print('Results computed with the **unofficial** Python eval code.')
        print('Results should be very close to the official MATLAB eval code.')
        print('Recompute with `./tools/reval.py --matlab ...` for your paper.')
        print('-- Thanks, The Management')
        print('--------------------------------------------------------------')

    def _do_matlab_eval(self, output_dir='output'):
        print '-----------------------------------------------------'
        print 'Computing results with the official MATLAB eval code.'
        print '-----------------------------------------------------'
        path = os.path.join(cfg.ROOT_DIR, 'lib', 'datasets',
                            'VOCdevkit-matlab-wrapper')
        cmd = 'cd {} && '.format(path)
        cmd += '{:s} -nodisplay -nodesktop '.format(cfg.MATLAB)
        cmd += '-r "dbstop if error; '
        cmd += 'voc_eval(\'{:s}\',\'{:s}\',\'{:s}\',\'{:s}\'); quit;"' \
               .format(self._devkit_path, self._get_comp_id(),
                       self._image_set, output_dir)
        print('Running:\n{}'.format(cmd))
        status = subprocess.call(cmd, shell=True)

    def evaluate_detections(self, all_boxes, output_dir):
        self._write_voc_results_file(all_boxes)
        self._do_python_eval(output_dir)
        if self.config['matlab_eval']:
            self._do_matlab_eval(output_dir)
        if self.config['cleanup']:
            for cls in self._classes:
                if cls == '__background__':
                    continue
                filename = self._get_voc_results_file_template().format(cls)
                os.remove(filename)

    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__':
    from datasets.pascal_voc import pascal_voc
    d = pascal_voc('trainval', '2007')
    res = d.roidb
    from IPython import embed; embed()
示例#14
0
            'train', 'val', 'trainval_taipei', 'trainval_shanghai',
            'trainval_shanghai80', 'val_shanghai', 'val_jackson',
            'trainval_jackson80', 'trainval_jackson100', 'trainval_jackson',
            'trainval_jacksonallobject', 'trainval', 'test', 'trainval_res101',
            'trainval_coral', 'trainval_coralpascal', 'trainval_coralcoco',
            'trainval_coralcocob', 'trainvalb', 'trainval_coralcoco10',
            'trainval_coral80', 'trainval_coralcoco30', 'trainval_coralcoco50',
            'trainval_coralcoco100', 'trainval_coralcoco250',
            'trainval_coralcoco500', 'trainval_coralcoco1000',
            'trainval_coralcoco4000', 'trainval_coralcoco8000',
            'trainval_coralcocodif'
    ]:
        name = 'voc_{}_{}'.format(year, split)
        if 'trainval' in split:
            __sets[name] = (
                lambda split=split, year=year: pascal_voc(split, year))
        elif 'val' in split:
            __sets[name] = (
                lambda split=split, year=year: pascal_voc(split, year))
#        print("split:",split)
#    elif split =='trainval_res101':
#        __sets[name] = (lambda split=split, year=year: pascal_voc(split, year, res101=True))
#    elif split =='trainval_coral':
#        __sets[name] = (lambda split=split, year=year: pascal_voc(split, year, coral=True))
#    elif split =='trainval_shanghai':
#        __sets[name] = (lambda split=split, year=year: pascal_voc(split, year, shanghai=True))
#    elif split =='trainval_shanghai80':
#        __sets[name] = (lambda split=split, year=year: pascal_voc(split, year, shanghai=True, cococlass=True))
#    elif split =='val_shanghai':
#        __sets[name] = (lambda split=split, year=year: pascal_voc(split, year, shanghai=True))
#    elif split =='trainval_taipei':
示例#15
0
def _selective_search_IJCV_top_k(split, year, top_k):
    """Return an imdb that uses the top k proposals from the selective search
    IJCV code.
    """
    imdb = pascal_voc(split, year)
    imdb.roidb_handler = imdb.selective_search_IJCV_roidb
    imdb.config['top_k'] = top_k
    return imdb

# Set up voc_<year>_<split> using selective search "fast" mode
for year in ['2007', '2012', '0712']:
    for split in ['train', 'val', 'trainval', 'test']:
        name = 'voc_{}_{}'.format(year, split)
        __sets[name] = (lambda split=split, year=year:
                pascal_voc(split, year))


# Set up kittivoc
    for split in ['train', 'val', 'trainval', 'test']:
        name = 'kittivoc_{}'.format(split)
        print(name)
        __sets[name] = (lambda split=split: kittivoc(split))
# Set up mmsvoc
for split in ['train', 'val', 'trainval', 'test']:
    name = 'mmsvoc_{}'.format(split)
    print(name)
    __sets[name] = (lambda split=split: mmsvoc(split))

#for split in ['train', 'val', 'trainval', 'test']:
#    name = 'mmsvoctest_{}'.format(split)