我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用datasets.imdb()。
def selective_search_IJCV_roidb(self): """ Return the database of selective search regions of interest. Ground-truth ROIs are also included. This function loads/saves from/to a cache file to speed up future calls. """ cache_file = os.path.join(self.cache_path, '{:s}_selective_search_IJCV_top_{:d}_roidb.pkl'. format(self.name, self.config['top_k'])) if os.path.exists(cache_file): with open(cache_file, 'rb') as fid: roidb = cPickle.load(fid) print '{} ss roidb loaded from {}'.format(self.name, cache_file) return roidb gt_roidb = self.gt_roidb() ss_roidb = self._load_selective_search_IJCV_roidb(gt_roidb) roidb = datasets.imdb.merge_roidbs(gt_roidb, ss_roidb) with open(cache_file, 'wb') as fid: cPickle.dump(roidb, fid, cPickle.HIGHEST_PROTOCOL) print 'wrote ss roidb to {}'.format(cache_file) return roidb
def combined_roidb(imdb_names): def get_roidb(imdb_name): imdb = get_imdb(imdb_name) print 'Loaded dataset `{:s}` for training'.format(imdb.name) roidb = get_training_roidb(imdb) return roidb roidbs = [get_roidb(s) for s in imdb_names.split('+')] roidb = roidbs[0] if len(roidbs) > 1: for r in roidbs[1:]: roidb.extend(r) imdb = datasets.imdb(imdb_names) else: imdb = get_imdb(imdb_names) return imdb, roidb
def __init__(self, image_set, devkit_path=None): datasets.imdb.__init__(self,image_set)#imageset ?train test self._image_set = image_set self._devkit_path = devkit_path self._data_path = os.path.join(self._devkit_path) self._classes = ('__background__','car','person','bike', 'truck', 'van', 'tram', 'misc')#???? self._class_to_ind = dict(zip(self.classes, xrange(self.num_classes)))#????{'__background__':'0','car':'1'} if self._image_set=='KakouTrain': self._image_index = self._load_image_set_index('KITTI_train_list.txt')#?????? elif self._image_set=='KakouTest': self._image_index = self._load_image_set_index('KITTI_val_list.txt')#?????? # Default to roidb handler self._roidb_handler = self.selective_search_roidb # PASCAL specific config options self.config = {'cleanup' : True, 'use_salt' : True, 'top_k' : 2000, 'use_diff' : False, 'rpn_file' : None} 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 selective_search_roidb(self):#???? cache_file = os.path.join(self.cache_path,self.name + '_selective_search_roidb.pkl') if os.path.exists(cache_file): #???cache_file???????.pkl?? with open(cache_file, 'rb') as fid: roidb = cPickle.load(fid) print '{} ss roidb loaded from {}'.format(self.name, cache_file) return roidb if self._image_set !='KakouTest': gt_roidb = self.gt_roidb() ss_roidb = self._load_selective_search_roidb(gt_roidb) roidb = datasets.imdb.merge_roidbs(gt_roidb, ss_roidb) else: roidb = self._load_selective_search_roidb(None) with open(cache_file, 'wb') as fid: cPickle.dump(roidb, fid, cPickle.HIGHEST_PROTOCOL) print 'wrote ss roidb to {}'.format(cache_file) return roidb
def __init__(self, image_set, year, devkit_path=None): datasets.imdb.__init__(self, 'voc_' + year + '_' + image_set) self._year = year self._image_set = image_set 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 = ('aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor') 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 # PASCAL specific config options self.config = {'cleanup' : True, 'use_salt' : True, 'use_diff' : False, 'top_k' : 2000} 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 selective_search_roidb(self): """ Return the database of selective search regions of interest. Ground-truth ROIs are also included. This function loads/saves from/to a cache file to speed up future calls. """ cache_file = os.path.join(self.cache_path, self.name + '_selective_search_roidb.pkl') if os.path.exists(cache_file): with open(cache_file, 'rb') as fid: roidb = cPickle.load(fid) print '{} ss roidb loaded from {}'.format(self.name, cache_file) return roidb if int(self._year) == 2007 or self._image_set != 'test': gt_roidb = self.gt_roidb() # ss_roidb = self._load_selective_search_roidb(gt_roidb) # roidb = datasets.imdb.merge_roidbs(gt_roidb, ss_roidb) roidb = self._load_selective_search_roidb(gt_roidb) else: roidb = self._load_selective_search_roidb(None) with open(cache_file, 'wb') as fid: cPickle.dump(roidb, fid, cPickle.HIGHEST_PROTOCOL) print 'wrote ss roidb to {}'.format(cache_file) return roidb
def __init__(self, image_set, year, devkit_path=None, image_type = 'images'): datasets.imdb.__init__(self, 'nyud2_' + image_type + '_' + year + '_' + image_set) self._year = year self._devkit_path = self._get_default_path() if devkit_path is None \ else devkit_path self._data_path = os.path.join(self._devkit_path, 'data') self._classes = ('__background__', # always index 0 'bathtub', 'bed', 'bookshelf', 'box', 'chair', 'counter', 'desk', 'door', 'dresser', 'garbage-bin', 'lamp', 'monitor', 'night-stand', 'pillow', 'sink', 'sofa', 'table', 'television', 'toilet'); self._class_to_ind = dict(zip(self.classes, xrange(self.num_classes))) self._image_type = image_type; self._image_set = image_set; self._image_ext = '.png' self._image_index = self._load_image_set_index() # Default to roidb handler self._roidb_handler = self.mcg_roidb # PASCAL specific config options self.config = {'cleanup' : True, 'use_salt' : True, 'top_k' : 2000} 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 mcg_roidb(self): """ Return the database of selective search regions of interest. Ground-truth ROIs are also included. This function loads/saves from/to a cache file to speed up future calls. """ cache_file = os.path.join(self.cache_path, self.name + '_mcg_roidb.pkl') if os.path.exists(cache_file): with open(cache_file, 'rb') as fid: roidb = cPickle.load(fid) print '{} ss roidb loaded from {}'.format(self.name, cache_file) return roidb if True: gt_roidb = self.gt_roidb() ss_roidb = self._load_mcg_roidb(gt_roidb) roidb = datasets.imdb.merge_roidbs(gt_roidb, ss_roidb) else: roidb = self._load_mcg_roidb(None) with open(cache_file, 'wb') as fid: cPickle.dump(roidb, fid, cPickle.HIGHEST_PROTOCOL) print 'wrote mcg roidb to {}'.format(cache_file) return roidb
def __init__(self, image_set, year, devkit_path=None): datasets.imdb.__init__(self, 'voc_' + year + '_' + image_set) self._year = year self._image_set = image_set 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 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor') 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 # PASCAL specific config options self.config = {'cleanup' : True, 'use_salt' : True, 'top_k' : 2000} 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 selective_search_roidb(self): """ Return the database of selective search regions of interest. Ground-truth ROIs are also included. This function loads/saves from/to a cache file to speed up future calls. """ cache_file = os.path.join(self.cache_path, self.name + '_selective_search_roidb.pkl') if os.path.exists(cache_file): with open(cache_file, 'rb') as fid: roidb = cPickle.load(fid) print '{} ss roidb loaded from {}'.format(self.name, cache_file) return roidb if int(self._year) == 2007 or self._image_set != 'test': gt_roidb = self.gt_roidb() ss_roidb = self._load_selective_search_roidb(gt_roidb) roidb = datasets.imdb.merge_roidbs(gt_roidb, ss_roidb) else: roidb = self._load_selective_search_roidb(None) with open(cache_file, 'wb') as fid: cPickle.dump(roidb, fid, cPickle.HIGHEST_PROTOCOL) print 'wrote ss roidb to {}'.format(cache_file) return roidb
def __init__(self, image_set, year, devkit_path=None): datasets.imdb.__init__(self, 'voc_' + year + '_' + image_set) self._year = year self._image_set = image_set 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 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor') 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 # PASCAL specific config options self.config = {'cleanup' : True, 'use_salt' : True, 'top_k' : 2000, 'use_diff' : False, 'rpn_file' : None} 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 rpn_roidb(self): if int(self._year) == 2007 or self._image_set != 'test': gt_roidb = self.gt_roidb() rpn_roidb = self._load_rpn_roidb(gt_roidb) roidb = datasets.imdb.merge_roidbs(gt_roidb, rpn_roidb) else: roidb = self._load_rpn_roidb(None) return roidb
def __init__(self, image_set, year, devkit_path=None): datasets.imdb.__init__(self, 'voc_' + year + '_' + image_set) self._year = year self._image_set = image_set 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 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor') 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.gt_roidb self._comp_id = 'comp4' # PASCAL specific config options self.config = {'cleanup' : True, 'use_salt' : True} 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 __init__(self, image_set, year, devkit_path=None): datasets.imdb.__init__(self, 'coco_' + year + '_' + image_set) # COCO specific config options self.config = {'top_k' : 2000, 'use_salt' : True, 'cleanup' : True, 'crowd_thresh' : 0.7, 'min_size' : 2} # name, paths self._year = year self._image_set = image_set self._data_path = self._get_default_path() if devkit_path is None \ else devkit_path # load COCO API, classes, class <-> id mappings self._COCO = COCO(self._get_ann_file()) cats = self._COCO.loadCats(self._COCO.getCatIds()) self._classes = tuple(['__background__'] + [c['name'] for c in cats]) self._class_to_ind = dict(zip(self.classes, xrange(self.num_classes))) self._class_to_coco_cat_id = dict(zip([c['name'] for c in cats], self._COCO.getCatIds())) self._image_index = self._load_image_set_index() # Default to roidb handler self._roidb_handler = self.gt_roidb self.competition_mode(False) self._data_name = image_set + year # e.g., "val2014" if self._data_name == 'test-dev2015': self._data_name_path = 'test2015' else: self._data_name_path = self._data_name
def parse_args(): """ Parse input arguments """ parser = argparse.ArgumentParser(description='Train RON network') parser.add_argument('--gpu', dest='gpu_id', help='GPU device id to use [0]', default=0, type=int) parser.add_argument('--solver', dest='solver', help='solver prototxt', default=None, type=str) parser.add_argument('--iters', dest='max_iters', help='number of iterations to train', default=300000, type=int) parser.add_argument('--weights', dest='model', help='initialize with pretrained model weights', default=None, type=str) parser.add_argument('--cfg', dest='cfg_file', help='optional config file', default=None, type=str) parser.add_argument('--imdb', dest='imdb_name', help='dataset to train on', default='voc_2007_trainval', type=str) parser.add_argument('--batchsize', dest='batchsize', help='batch size used to train', default=20, type=int) if len(sys.argv) == 1: parser.print_help() sys.exit(1) args = parser.parse_args() return args
def region_proposal_roidb(self): """ Return the database of regions of interest. Ground-truth ROIs are also included. This function loads/saves from/to a cache file to speed up future calls. """ cache_file = os.path.join(self.cache_path, self.name + '_' + cfg.REGION_PROPOSAL + '_region_proposal_roidb.pkl') if os.path.exists(cache_file): with open(cache_file, 'rb') as fid: roidb = cPickle.load(fid) print '{} roidb loaded from {}'.format(self.name, cache_file) return roidb if self._image_set != 'test': gt_roidb = self.gt_roidb() print 'Loading region proposal network boxes...' model = cfg.REGION_PROPOSAL rpn_roidb = self._load_rpn_roidb(gt_roidb, model) print 'Region proposal network boxes loaded' roidb = datasets.imdb.merge_roidbs(rpn_roidb, gt_roidb) else: print 'Loading region proposal network boxes...' model = cfg.REGION_PROPOSAL roidb = self._load_rpn_roidb(None, model) print 'Region proposal network boxes loaded' print '{} region proposals per image'.format(self._num_boxes_proposal / len(self.image_index)) with open(cache_file, 'wb') as fid: cPickle.dump(roidb, fid, cPickle.HIGHEST_PROTOCOL) print 'wrote roidb to {}'.format(cache_file) return roidb
def region_proposal_roidb(self): """ Return the database of regions of interest. Ground-truth ROIs are also included. This function loads/saves from/to a cache file to speed up future calls. """ cache_file = os.path.join(self.cache_path, self.name + '_' + cfg.SUBCLS_NAME + '_' + cfg.REGION_PROPOSAL + '_region_proposal_roidb.pkl') if os.path.exists(cache_file): with open(cache_file, 'rb') as fid: roidb = cPickle.load(fid) print '{} roidb loaded from {}'.format(self.name, cache_file) return roidb if self._image_set != 'test': gt_roidb = self.gt_roidb() print 'Loading region proposal network boxes...' model = cfg.REGION_PROPOSAL rpn_roidb = self._load_rpn_roidb(gt_roidb, model) print 'Region proposal network boxes loaded' roidb = datasets.imdb.merge_roidbs(rpn_roidb, gt_roidb) else: print 'Loading region proposal network boxes...' model = cfg.REGION_PROPOSAL roidb = self._load_rpn_roidb(None, model) print 'Region proposal network boxes loaded' print '{} region proposals per image'.format(self._num_boxes_proposal / len(self.image_index)) with open(cache_file, 'wb') as fid: cPickle.dump(roidb, fid, cPickle.HIGHEST_PROTOCOL) print 'wrote roidb to {}'.format(cache_file) return roidb
def region_proposal_roidb(self): """ Return the database of regions of interest. Ground-truth ROIs are also included. This function loads/saves from/to a cache file to speed up future calls. """ cache_file = os.path.join(self.cache_path, self.name + '_' + cfg.SUBCLS_NAME + '_' + cfg.REGION_PROPOSAL + '_region_proposal_roidb.pkl') if os.path.exists(cache_file): with open(cache_file, 'rb') as fid: roidb = cPickle.load(fid) print '{} roidb loaded from {}'.format(self.name, cache_file) return roidb if self._image_set != 'testing': gt_roidb = self.gt_roidb() print 'Loading region proposal network boxes...' if self._image_set == 'trainval': model = cfg.REGION_PROPOSAL + '_trainval/' else: model = cfg.REGION_PROPOSAL + '_train/' rpn_roidb = self._load_rpn_roidb(gt_roidb, model) print 'Region proposal network boxes loaded' roidb = datasets.imdb.merge_roidbs(rpn_roidb, gt_roidb) else: print 'Loading region proposal network boxes...' model = cfg.REGION_PROPOSAL + '_trainval/' roidb = self._load_rpn_roidb(None, model) print 'Region proposal network boxes loaded' print '{} region proposals per image'.format(self._num_boxes_proposal / len(self.image_index)) with open(cache_file, 'wb') as fid: cPickle.dump(roidb, fid, cPickle.HIGHEST_PROTOCOL) print 'wrote roidb to {}'.format(cache_file) return roidb
def __init__(self, image_set, year, devkit_path=None): datasets.imdb.__init__(self, 'voc_' + year + '_' + image_set) self._year = year self._image_set = image_set 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 = ('aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor') 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, 'top_k' : 2000} 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 __init__(self, image_set, year, devkit_path=None): print(image_set) datasets.imdb.__init__(self, 'tattc_' + year) self._year = year self._image_set = image_set self._devkit_path = self._get_default_path() if devkit_path is None \ else devkit_path print(self._devkit_path) self._data_path = os.path.join(self._devkit_path, self._year) print(self._data_path) self._classes = ('__background__', # always index 0, total 2 'tattoo') self._class_to_ind = dict(zip(self.classes, xrange(self.num_classes))) print(self._class_to_ind) self._image_ext = '.jpg' self._image_index = self._load_image_set_index() self._index_to_fname = self._load_fname_index() # Default to roidb handler self._roidb_handler = self.selective_search_roidb # PASCAL specific config options self.config = {'cleanup' : True, 'use_salt' : True, 'top_k' : 2000, 'use_diff' : False, 'rpn_file' : None} assert os.path.exists(self._devkit_path), \ 'devkit path does not exist: {}'.format(self._devkit_path) assert os.path.exists(self._data_path), \ 'Path does not exist: {}'.format(self._data_path)
def __init__(self, image_set, year, devkit_path=None): print('[tattic_voc init]') print(image_set) datasets.imdb.__init__(self, 'tattc_voc_' + year) self._year = year self._image_set = image_set self._devkit_path = self._get_default_path() if devkit_path is None \ else devkit_path self._data_path = os.path.join(self._devkit_path) self._classes = ('__background__', # always index 0, total 22 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor', 'tattoo') 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 # TATTC specific config options self.config = {'cleanup' : True, 'use_salt' : True, 'top_k' : 2000, 'use_diff' : False, 'rpn_file' : None} 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)