def _accumulate_results(self, runner, results, num_examples): # accumulate on the master for worker_idx in range(1, runner.local_size): worker_file = osp.join(runner.work_dir, 'temp_{}.pkl'.format(worker_idx)) tmp_results = load(worker_file) for idx in range(num_examples): adjusted_idx = idx * runner.local_size + worker_idx results[adjusted_idx] = tmp_results[adjusted_idx] print('cleaning up', worker_file) os.remove(worker_file) # cleanup self.evaluate(runner, results)
def fromfile(filename): filename = osp.abspath(osp.expanduser(filename)) check_file_exist(filename) if filename.endswith('.py'): module_name = osp.basename(filename)[:-3] if '.' in module_name: raise ValueError('Dots are not allowed in config file path.') config_dir = osp.dirname(filename) sys.path.insert(0, config_dir) mod = import_module(module_name) sys.path.pop(0) cfg_dict = { name: value for name, value in mod.__dict__.items() if not name.startswith('__') } elif filename.endswith(('.yml', '.yaml', '.json')): cfg_dict = load(filename) else: raise IOError('Only py/yml/yaml/json type are supported now!') return Config(cfg_dict, filename=filename)
def fast_eval_recall(results, coco, max_dets, iou_thrs=np.arange(0.5, 0.96, 0.05)): if is_str(results): assert results.endswith('.pkl') results = load(results) elif not isinstance(results, list): raise TypeError( 'results must be a list of numpy arrays or a filename, not {}'. format(type(results))) gt_bboxes = [] img_ids = coco.getImgIds() for i in range(len(img_ids)): ann_ids = coco.getAnnIds(imgIds=img_ids[i]) ann_info = coco.loadAnns(ann_ids) if len(ann_info) == 0: gt_bboxes.append(np.zeros((0, 4))) continue bboxes = [] for ann in ann_info: if ann.get('ignore', False) or ann['iscrowd']: continue x1, y1, w, h = ann['bbox'] bboxes.append([x1, y1, x1 + w - 1, y1 + h - 1]) bboxes = np.array(bboxes, dtype=np.float32) if bboxes.shape[0] == 0: bboxes = np.zeros((0, 4)) gt_bboxes.append(bboxes) recalls = eval_recalls(gt_bboxes, results, max_dets, iou_thrs, print_summary=False) ar = recalls.mean(axis=1) return ar