def _get_dict(self): cam_a_imgs = sorted(glob.glob(osp.join(self.cam_a_path, '*.bmp'))) cam_b_imgs = sorted(glob.glob(osp.join(self.cam_b_path, '*.bmp'))) assert len(cam_a_imgs) == len(cam_b_imgs) img_list = [] images_info = [] idx = 0 for cam_id, cam_info in enumerate([cam_a_imgs, cam_b_imgs]): for pid, img_path in enumerate(cam_info): img_list.append(img_path) images_info.append([pid, cam_id, idx, idx + 1, 1]) idx += 1 images_info = np.asarray(images_info, dtype=np.int64) splits = self._create_split(images_info) data_dict = {} data_dict['dir'] = img_list data_splits = [] for split_id, split_i in enumerate(splits): data_split = {} train_idx = split_i['train'] test_idx = split_i['test'] data_split['train'] = np_filter(images_info, train_idx) data_split['probe'] = np_filter(images_info, test_idx) data_split['gallery'] = np_filter(images_info, test_idx) data_split['info'] = 'VIPeR dataset. Split ID {:2d}'.format( split_id) train_id = np.unique(data_split['train'][:, 0]) probe_id = np.unique(data_split['probe'][:, 0]) gallery_id = np.unique(data_split['gallery'][:, 0]) assert np.intersect1d(probe_id, gallery_id).size == probe_id.size assert probe_id.size == gallery_id.size assert data_split['probe'].shape == data_split['gallery'].shape data_splits.append(data_split) data_dict['split'] = data_splits data_dict['info'] = 'VIPeR Dataset. 10 Splits.' return data_dict
def person_filter(self, all_track_raw, minframes): track_info = all_track_raw[all_track_raw[:, 4] >= minframes] person_id = np.unique(track_info[:, 0]) person_id_box = [] for i_person in range(person_id.size): person_data = np_filter(track_info, [person_id[i_person]]) person_cam = np.unique(person_data[:, 1]) if person_cam.size >= 2: person_id_box.append(person_id[i_person]) return np.asarray(person_id_box)
def _get_dict(self): img_list = sorted(glob.glob(osp.join(self.raw_data_folder, '*.png'))) images_info = [] for idx, img_path in enumerate(img_list): img_name = osp.basename(img_path) pid = int(img_name[:4]) - 1 camid = (int(img_name[4:7]) - 1) // 2 images_info.append([pid, camid, idx, idx + 1, 1]) images_info = np.asarray(images_info, dtype=np.int64) splits = self._create_split(images_info) data_dict = {} data_dict['dir'] = img_list data_splits = [] for split_id, split_i in enumerate(splits): data_split = {} train_idx = split_i['train'] test_idx = split_i['test'] data_split['train'] = np_filter(images_info, train_idx) data_split['probe'] = np_filter(images_info, test_idx) data_split['gallery'] = np_filter(images_info, test_idx) data_split['info'] = 'CUHK01 dataset. Split ID {:2d}'.format( split_id) probe_id = np.unique(data_split['probe'][:, 0]) gallery_id = np.unique(data_split['gallery'][:, 0]) assert np.intersect1d(probe_id, gallery_id).size == probe_id.size assert probe_id.size == gallery_id.size assert data_split['probe'].shape == data_split['gallery'].shape data_splits.append(data_split) data_dict['split'] = data_splits data_dict['info'] = 'CUHK01 Dataset. 10 Splits.' return data_dict
def _prepare_split(self, images_info): """ Image name format: 0001001.png, where first four digits represent identity and last four digits represent cameras. Camera 1&2 are considered the same view and camera 3&4 are considered the same view. """ self.logger.info("Begin Load 10 random splits") split_mat = loadmat(self.split_mat_path) trainIdxAll = split_mat['trainIdxAll'][0] # length = 10 probe_info_all = images_info[0] gallery_info_all = images_info[1] probe_id_all = np.unique(probe_info_all[:, 0]) gallery_id_all = np.unique(gallery_info_all[:, 0]) splits = [] for split_idx in range(10): train_idxs = trainIdxAll[split_idx][0][0][2][0] assert train_idxs.size == 125 probe_id = np.setdiff1d(probe_id_all, train_idxs) gallery_id = np.setdiff1d(gallery_id_all, train_idxs) train_info = np.concatenate( (np_filter(probe_info_all, train_idxs), np_filter(gallery_info_all, train_idxs)), axis=0) probe_info = np_filter(probe_info_all, probe_id) gallery_info = np_filter(gallery_info_all, gallery_id) assert np.intersect1d(probe_id, gallery_id).size == probe_id.size assert probe_id.size == 125 assert gallery_id.size == 126 split = {} split['train'] = train_info split['probe'] = probe_info split['gallery'] = gallery_info split['info'] = 'GRID dataset. Split ID {:2d}'.format(split_idx) splits.append(split) self.logger.info("Load 10 random splits") return splits
def init(self): self.pids = np.unique(self.data_info[:, 0]).tolist() self.cam_num = np.unique(self.data_info[:, 1]).size self.info_dict = {} self._len = 0 for pid in self.pids: p_info = np_filter(self.data_info, [pid]) cams = np.unique(p_info[:, 1]).tolist() self.info_dict[pid] = {} self.info_dict[pid]['avai_cams'] = cams self.info_dict[pid]['avai_num'] = p_info.shape[0] for cam_i in cams: p_cam_info = np_filter(p_info, [pid], [cam_i]) tmp_p_cam_info = [] p_cam_track_idx = self.npr.permutation(p_cam_info.shape[0]) for p_cam_i in p_cam_track_idx: tmp_p_cam_info.append(p_cam_info[p_cam_i]) self.info_dict[pid][cam_i] = tmp_p_cam_info num = p_info.shape[0] if num < self.sample_num: num = self.sample_num self._len += num - num % self.sample_num
def _get_dict(self): self.logger.info('Begin Get Video List') assert self.cam_a_path.exists() and self.cam_b_path.exists() person_cama_dirs = sorted(glob.glob(osp.join(self.cam_a_path, '*')))[:200] person_camb_dirs = sorted(glob.glob(osp.join(self.cam_b_path, '*')))[:200] person_cama_dirs = [osp.basename(item) for item in person_cama_dirs] person_camb_dirs = [osp.basename(item) for item in person_camb_dirs] assert set(person_cama_dirs) == set(person_camb_dirs) frames_list = [] video = np.zeros((400, 5), dtype=np.int64) video_id = 0 frames_begin = 0 for pid, person in enumerate(person_cama_dirs): for cam_i, cam_path in enumerate( [self.cam_a_path, self.cam_b_path]): frames_name = glob.glob('%s/%s/*.png' % (str(cam_path), person)) num_frames = len(frames_name) frames_name.sort(key=lambda x: int(x[-8:-4])) video[video_id, 0] = pid video[video_id, 1] = cam_i video[video_id, 2] = frames_begin video[video_id, 3] = frames_begin + num_frames video[video_id, 4] = num_frames video_id += 1 frames_list.extend(frames_name) frames_begin = frames_begin + num_frames splits = self._prepare_split(video.copy()) data_dict = {} data_dict['dir'] = frames_list data_splits = [] for split_id, split_i in enumerate(splits): data_split = {} train_idx = split_i['train'] test_idx = split_i['test'] data_split['train'] = np_filter(video, train_idx) data_split['probe'] = np_filter(video, test_idx, [0]) data_split['gallery'] = np_filter(video, test_idx, [1]) data_split['info'] = 'PRID-2011 dataset. Split ID {:2d}'.format( split_id) train_id = np.unique(data_split['train'][:, 0]) probe_id = np.unique(data_split['probe'][:, 0]) gallery_id = np.unique(data_split['gallery'][:, 0]) assert np.intersect1d(probe_id, gallery_id).size == probe_id.size assert probe_id.size == gallery_id.size assert data_split['probe'].shape[0] == data_split['gallery'].shape[ 0] data_splits.append(data_split) data_dict['split'] = data_splits data_dict['track_info'] = video data_dict[ 'info'] = 'PRID-2011 Dataset. Min Frames {:3d}. 10 Splits.'.format( self.minframes) return data_dict
def _check(self, train_info, test_info, probe_info, gallery_info): assert np.unique(test_info[:, 2]).size == test_info.shape[0] if self.minframes is not None: probe_info_new = [] probe_info_drop = [] for probe_i in range(probe_info.shape[0]): data_info = probe_info[probe_i] p_id = data_info[0] p_cam_id = data_info[1] g_info = np_filter(gallery_info, [p_id]) g_cam_id = np.unique(g_info[:, 1]) if np.setdiff1d(g_cam_id, np.asarray([p_cam_id])).size == 0: probe_info_drop.append(data_info) else: probe_info_new.append(data_info) self.logger.info( 'After drop videos less than: train {:2d} test {:2d} frames, check cam number' .format(self.minframes['train'], self.minframes['test'])) if len(probe_info_drop) > 0: for drop_info in probe_info_drop: self.logger.info('No related gallery track. Drop probe ' + str(drop_info)) probe_info = np.stack(probe_info_new) test_info = self._merge_to_test(probe_info, gallery_info) else: self.logger.warn('All probe track have related gallery track.') assert np.sum(train_info[:, 3] - train_info[:, 2] - train_info[:, 4]) == 0 assert np.sum(test_info[:, 3] - test_info[:, 2] - test_info[:, 4]) == 0 assert np.sum(probe_info[:, 3] - probe_info[:, 2] - probe_info[:, 4]) == 0 assert np.sum(gallery_info[:, 3] - gallery_info[:, 2] - gallery_info[:, 4]) == 0 test_id = np.unique(test_info[:, 0]) probe_id = np.unique(probe_info[:, 0]) gallery_id = np.unique(gallery_info[:, 0]) assert -1 not in set( test_id) # junk id set to be -1, it should have been removed. assert np.setdiff1d(probe_id, gallery_id).size == 0 assert set(test_id) == set(probe_id).union(set(gallery_id)) for probe_i in range(probe_info.shape[0]): data_info = probe_info[probe_i] p_id = data_info[0] p_cam_id = data_info[1] g_info = np_filter(gallery_info, [p_id]) g_cam_id = np.unique(g_info[:, 1]) if not np.setdiff1d(g_cam_id, np.asarray([p_cam_id])).size > 0: self.logger.warn( 'All gallery trackets have the same camera id with probe tracklet for ID: ' + str(p_id)) assert np.unique(test_info[:, 2]).size == np.unique( np.concatenate((probe_info, gallery_info))[:, 2]).size assert np.intersect1d(train_info[:, 2], test_info[:, 2]).size == 0 assert np.unique(train_info[:, 2]).size == train_info.shape[0] assert np.unique(test_info[:, 2]).size == test_info.shape[0] assert np.unique(probe_info[:, 2]).size == probe_info.shape[0] assert np.unique(gallery_info[:, 2]).size == gallery_info.shape[0] return test_info, probe_info