def _read_dict(self, split_id=0): if not self.dict_dir.exists(): self.check_raw_file() data_dict = self._get_dict() self._store_dict(data_dict) tmp_data_dict = DataPacker.load(self.dict_dir, self.logger) self.logger.info(tmp_data_dict['info']) images_dir_list = tmp_data_dict['dir'] if 'track_info' in tmp_data_dict: all_track_info = tmp_data_dict['track_info'] else: all_track_info = None assert split_id < len(tmp_data_dict['split']) tmp_data_dict = tmp_data_dict['split'][split_id] self.logger.info('The choosed split info: ' + tmp_data_dict['info']) data_dict = {} data_dict['train'] = np.asarray(tmp_data_dict['train'], np.int64) data_dict['probe'] = np.asarray(tmp_data_dict['probe'], np.int64) data_dict['gallery'] = np.asarray(tmp_data_dict['gallery'], np.int64) data_dict['dir'] = images_dir_list self.storemanager = DataStoreManager(self.store_dir, self.name, self.store_type, data_dict['dir'], all_track_info, self.resize_hw, self.logger) data_dict['shape'] = self.storemanager.img_shape data_dict['dtype'] = self.storemanager.img_dtype self.data_dict = data_dict
def _get_dict(self): self._preprocess() split_paths = [self.split_new_det_json_path, self.split_new_lab_json_path, self.split_classic_det_json_path, self.split_classic_lab_json_path] split_paths_info = ['New detected', 'New labeled', 'Classic detected', 'Classic labeled'] images_list = set() for split_path in split_paths: splits = DataPacker.load(split_path, self.logger) for split in splits: train = split['train'] query = split['query'] gallery = split['gallery'] for data_tmp in [train, query, gallery]: for img_info_tmp in data_tmp: images_list.add(img_info_tmp[0]) images_list = [img_dir for img_dir in images_list] data_splits = [] true_split_id = 0 for split_path_id, split_path in enumerate(split_paths): splits = DataPacker.load(split_path, self.logger) for split_id, split in enumerate(splits): train = split['train'] query = split['query'] gallery = split['gallery'] tqg_info = [] for data_tmp in [train, query, gallery]: data_info = [] for img_info_tmp in data_tmp: idx = images_list.index(img_info_tmp[0]) data_info.append([img_info_tmp[1], img_info_tmp[2], idx, idx+1, 1]) tqg_info.append(data_info) train_images = np.asarray(tqg_info[0], np.int64) probe_images = np.asarray(tqg_info[1], np.int64) gallery_images = np.asarray(tqg_info[2], np.int64) assert np.unique(train_images[:, 2]).size == train_images.shape[0] assert np.unique(probe_images[:, 2]).size == probe_images.shape[0] assert np.unique(gallery_images[:, 2]).size == gallery_images.shape[0] probe_id = np.unique(probe_images[:, 0]) gallery_id = np.unique(gallery_images[:, 0]) assert np.intersect1d(probe_id, gallery_id).size == probe_id.size data_split = {} data_split['train'] = train_images data_split['probe'] = probe_images data_split['gallery'] = gallery_images data_split['info'] = 'CUHK03 dataset. {}. Split ID {:2d}.'.format(split_paths_info[split_path_id], true_split_id) true_split_id += 1 data_splits.append(data_split) data_dict = {} data_dict['dir'] = images_list data_dict['split'] = data_splits data_dict['info'] = 'CUHK03 Dataset. \nSplit ID: 0 New detected\nSplit ID: 1 New labeled\nSplit ID: 2-21 Classic detected\nSplit ID: 22-41 Classic labeled\n' return data_dict
# Add lib to PYTHONPATH lib_path = osp.join(this_dir, '..') add_path(lib_path) model_dir = Path(str(this_dir)).parent / 'tasks' task_list = ['task1', 'task2', 'task3', 'task4', 'task5'] # the name of the task folder epoch_list = None cmc = [] mAP = [] for task_i in task_list: cmc_dir = model_dir / str(str(task_i) + '/output/result') cmc_dir_tmp = cmc_dir.glob('cmc_*.json') cmc_dir_tmp = sorted([x.name for x in cmc_dir_tmp])[-1] print(cmc_dir_tmp) cmc_dir = cmc_dir / cmc_dir_tmp cmc_i = DataPacker.load(cmc_dir) solver_list = list(cmc_i.keys()) if epoch_list is None: epoch_list = list(cmc_i[solver_list[0]].keys()) epoch_list = [int(x) for x in epoch_list] epoch_list.sort() epoch_list = [str(x) for x in epoch_list] for solver_id in solver_list: epoch_list_i = list(cmc_i[solver_list[0]].keys()) epoch_list_i = [int(x) for x in epoch_list_i] epoch_list_i.sort() epoch_list_i = [str(x) for x in epoch_list_i] assert epoch_list_i == epoch_list cmc_tmp = [] mAP_tmp = [] for epoch_id in epoch_list: