def load_data(self, path, load_metrics): filename, _ = os.path.splitext(os.path.basename(path)) data = np.load(path, allow_pickle=True, encoding='latin1')['data'].item() data_train = data['train'] data_valid = data['test'] indices_to_select = [0, 1, 4, 7, 2, 5, 8, 6, 12, 15, 17, 19, 21, 16, 18, 20] self._data_train['2d'] = data_train["combined_2d"][:, indices_to_select, :] self._data_train['3d'] = data_train["combined_3d_cam"][:, indices_to_select, :]*1000 self._data_valid['2d'] = data_valid["combined_2d"][:, indices_to_select, :] self._data_valid['3d'] = data_valid["combined_3d_cam"][:, indices_to_select, :]*1000 print("Normalizing screen coordinates") for i in tqdm(range(self._data_train['3d'].shape[0])): self._data_train['3d'][i, :] -= self._data_train['3d'][i, 0] if self.center_2d: self._data_train['2d'][i, :] -= self._data_train['2d'][i, 0] self.plot_random() if not load_metrics: self.mean_2d = np.mean(self._data_train['2d'], axis=0) self.std_2d = np.std(self._data_train['2d'], axis=0) self.mean_3d = np.mean(self._data_train['3d'], axis=0) self.std_3d = np.std(self._data_train['3d'], axis=0) if not os.path.exists(os.path.join("metrics/", filename + "_metrics.npz")): np.savez_compressed( os.path.join("metrics/", filename + "_metrics"), mean_2d=self.mean_2d, std_2d=self.std_2d, mean_3d=self.mean_3d, std_3d=self.std_3d) else: data = np.load(load_metrics) self.mean_2d = data['mean_2d'] self.std_2d = data['std_2d'] self.mean_3d = data['mean_3d'] self.std_3d = data['std_3d'] self._data_train['3d'] = normalize_data(self._data_train['3d'], self.mean_3d, self.std_3d, skip_root=True) self._data_train['2d'] = normalize_data(self._data_train['2d'], self.mean_2d, self.std_2d, skip_root=self.center_2d) for i in tqdm(range(self._data_valid['3d'].shape[0])): self._data_valid['3d'][i, :] -= self._data_valid['3d'][i, 0] if self.center_2d: self._data_valid['2d'][i, :] -= self._data_valid['2d'][i, 0] self._data_valid['3d'] = normalize_data(self._data_valid['3d'], self.mean_3d, self.std_3d, skip_root=True) self._data_valid['2d'] = normalize_data(self._data_valid['2d'], self.mean_2d, self.std_2d, skip_root=self.center_2d) visualize_2d(self._data_train['2d'][0, :, :], 'debug3dpw')
def load_data(self, path_train, path_valid): data_train = np.load(path_train, allow_pickle=True) data_valid = np.load(path_valid, allow_pickle=True) indices_to_arrange = [0, 2, 1, 3, 5, 4, 6, 8, 7, 9, 11, 10, 12, 14, 13, 15, 17, 16, 19, 18, 21, 20, 23, 22] indices_to_select = [0, 1, 4, 7, 2, 5, 8, 6, 12, 15, 17, 19, 21, 16, 18, 20] self._data_train['2d'] = data_train["data_2d"][:, indices_to_arrange, :][:, indices_to_select, :] self._data_train['3d'] = data_train["data_3d"][:, indices_to_arrange, :][:, indices_to_select, :] self._data_valid['2d'] = data_valid["data_2d"][:, indices_to_arrange, :][:, indices_to_select, :] self._data_valid['3d'] = data_valid["data_3d"][:, indices_to_arrange, :][:, indices_to_select, :] # visualize_2d(self._data_train['2d'][0, :, :], 'debug_surreal') print("Normalizing screen coordinates") for i in tqdm(range(self._data_train['3d'].shape[0])): self._data_train['3d'][i, :] -= self._data_train['3d'][i, 0] if self.center_2d: self._data_train['2d'][i, :] -= self._data_train['2d'][i, 0] self.plot_random() self.mean_2d = np.mean(self._data_train['2d'], axis=0) self.std_2d = np.std(self._data_train['2d'], axis=0) self.mean_3d = np.mean(self._data_train['3d'], axis=0) self.std_3d = np.std(self._data_train['3d'], axis=0) self._data_train['3d'] = normalize_data(self._data_train['3d'], self.mean_3d, self.std_3d, skip_root=True) self._data_train['2d'] = normalize_data(self._data_train['2d'], self.mean_2d, self.std_2d, skip_root=self.center_2d) for i in tqdm(range(self._data_valid['3d'].shape[0])): self._data_valid['3d'][i, :] -= self._data_valid['3d'][i, 0] if self.center_2d: self._data_valid['2d'][i, :] -= self._data_valid['2d'][i, 0] self._data_valid['3d'] = normalize_data(self._data_valid['3d'], self.mean_3d, self.std_3d, skip_root=True) self._data_valid['2d'] = normalize_data(self._data_valid['2d'], self.mean_2d, self.std_2d, skip_root=self.center_2d)
def load_data(self, path, load_metrics): filename, _ = os.path.splitext(os.path.basename(path)) indices_to_select_2d = [0, 6, 7, 8, 1, 2, 3, 12, 13, 15, 25, 26, 27, 17, 18, 19] indices_to_select_3d = [1, 2, 3, 6, 7, 8, 12, 13, 14, 15, 17, 18, 19, 25, 26, 27] self.cameras = cameras.load_cameras(os.path.join(path, "cameras.h5")) TRAIN_SUBJECTS = [1, 5, 6, 7, 8] TEST_SUBJECTS = [9, 11] actions = ["Directions","Discussion","Eating","Greeting", "Phoning","Photo","Posing","Purchases", "Sitting","SittingDown","Smoking","Waiting", "WalkDog","Walking","WalkTogether"] trainset = self.load_3d_data(path, TRAIN_SUBJECTS, actions) testset = self.load_3d_data(path, TEST_SUBJECTS, actions) d2d_train, d3d_train = self.project_to_cameras(trainset, augment_count=self.augment_count) d2d_valid, d3d_valid = self.project_to_cameras(testset) if self.center_2d: self._data_train['2d'] = self.root_center(np.array(d2d_train))[:, indices_to_select_2d, :] else: self._data_train['2d'] = np.array(d2d_train)[:, indices_to_select_2d, :] self._data_train['3d'] = self.root_center(np.array(d3d_train))[:, indices_to_select_2d, :] if self.center_2d: self._data_valid['2d'] = self.root_center(np.array(d2d_valid))[:, indices_to_select_2d, :] else: self._data_valid['2d'] = np.array(d2d_valid)[:, indices_to_select_2d, :] self._data_valid['3d'] = self.root_center(np.array(d3d_valid))[:, indices_to_select_2d, :] self.plot_random() if not load_metrics: self.mean_3d = np.mean(self._data_train['3d'], axis=0) self.std_3d = np.std(self._data_train['3d'], axis=0) self.mean_2d = np.mean(self._data_train['2d'], axis=0) self.std_2d = np.std(self._data_train['2d'], axis=0) if not os.path.exists(os.path.join("metrics/", filename + "_metrics.npz")): np.savez_compressed( os.path.join("metrics/", filename + "_metrics"), mean_2d=self.mean_2d, std_2d=self.std_2d, mean_3d=self.mean_3d, std_3d=self.std_3d) else: data = np.load(load_metrics) self.mean_2d = data['mean_2d'] self.std_2d = data['std_2d'] self.mean_3d = data['mean_3d'] self.std_3d = data['std_3d'] self._data_train['3d'] = normalize_data(self._data_train['3d'], self.mean_3d, self.std_3d, skip_root=True) self._data_train['2d'] = normalize_data(self._data_train['2d'], self.mean_2d, self.std_2d, skip_root=self.center_2d) self._data_valid['3d'] = normalize_data(self._data_valid['3d'], self.mean_3d, self.std_3d, skip_root=True) self._data_valid['2d'] = normalize_data(self._data_valid['2d'], self.mean_2d, self.std_2d, skip_root=self.center_2d)
def load_data(self, path, load_metrics): filename = os.path.splitext(os.path.basename(path))[0] data = np.load(path, allow_pickle=True)['data'].item() indices_to_select_2d = [ 0, 1, 2, 3, 6, 7, 8, 12, 13, 15, 17, 18, 19, 25, 26, 27 ] indices_to_select_3d = [ 1, 2, 3, 6, 7, 8, 12, 13, 14, 15, 17, 18, 19, 25, 26, 27 ] actions = [ "Directions", "Discussion", "Eating", "Greeting", "Phoning", "Photo", "Posing", "Purchases", "Sitting", "SittingDown", "Smoking", "Waiting", "WalkDog", "Walking", "WalkTogether" ] d2d = [] d3d = [] for action in actions: d2d.append(data[action]['2d']) d3d.append(data[action]['3d_cam']) d2d = np.vstack(d2d) d3d = np.vstack(d3d) if self.center_2d: self._data_valid['2d'] = self.root_center( d2d)[:, indices_to_select_2d, :] else: self._data_valid['2d'] = d2d[:, indices_to_select_2d, :] self._data_valid['3d'] = self.root_center(d3d)[:, indices_to_select_2d, :] if not load_metrics: self.mean_3d = np.mean(self._data_valid['3d'], axis=0) self.std_3d = np.std(self._data_valid['3d'], axis=0) self.mean_2d = np.mean(self._data_valid['2d'], axis=0) self.std_2d = np.std(self._data_valid['2d'], axis=0) if not os.path.exists( os.path.join("metrics/", filename + "_metrics.npz")): np.savez_compressed(os.path.join("metrics/", filename + "_metrics"), mean_2d=self.mean_2d, std_2d=self.std_2d, mean_3d=self.mean_3d, std_3d=self.std_3d) else: data = np.load(load_metrics) self.mean_2d = data['mean_2d'] self.std_2d = data['std_2d'] self.mean_3d = data['mean_3d'] self.std_3d = data['std_3d'] self._data_valid['3d'] = normalize_data(self._data_valid['3d'], self.mean_3d, self.std_3d, skip_root=True) self._data_valid['2d'] = normalize_data(self._data_valid['2d'], self.mean_2d, self.std_2d, skip_root=self.center_2d)
def load_data(self, path, load_metrics): filename, _ = os.path.splitext(os.path.basename(path)) data = np.load(path, allow_pickle=True, encoding='latin1')['data'].item() data_train = data['train'] data_valid = data['test'] indices_to_select = [ 0, 24, 25, 26, 29, 30, 31, 2, 5, 6, 7, 17, 18, 19, 9, 10, 11 ] indices_to_sort = [ 0, 4, 5, 6, 1, 2, 3, 7, 8, 10, 14, 15, 16, 11, 12, 13 ] self._data_train['2d'] = data_train[ "2d_projected"][:, indices_to_select, :][:, indices_to_sort, :] self._data_train['3d'] = data_train[ "3d"][:, indices_to_select, :][:, indices_to_sort, :] * 1000 # print(self._data_train['3d'][0, :, :]) self._data_valid['2d'] = data_valid[ "2d_projected"][:, indices_to_select, :][:, indices_to_sort, :] self._data_valid['3d'] = data_valid[ "3d"][:, indices_to_select, :][:, indices_to_sort, :] * 1000 for i in range(self._data_train['3d'].shape[0]): self._data_train['3d'][i, :] -= self._data_train['3d'][i, 0] if self.center_2d: self._data_train['2d'][i, :] -= self._data_train['2d'][i, 0] for i in range(self._data_valid['3d'].shape[0]): self._data_valid['3d'][i, :] -= self._data_valid['3d'][i, 0] if self.center_2d: self._data_valid['2d'][i, :] -= self._data_valid['2d'][i, 0] self.plot_random() if not load_metrics: self.mean_2d = np.mean(self._data_train['2d'], axis=0) self.std_2d = np.std(self._data_train['2d'], axis=0) self.mean_3d = np.mean(self._data_train['3d'], axis=0) self.std_3d = np.std(self._data_train['3d'], axis=0) if not os.path.exists( os.path.join("metrics/", filename + "_metrics.npz")): np.savez_compressed(os.path.join("metrics/", filename + "_metrics"), mean_2d=self.mean_2d, std_2d=self.std_2d, mean_3d=self.mean_3d, std_3d=self.std_3d) else: data = np.load(load_metrics) self.mean_2d = data['mean_2d'] self.std_2d = data['std_2d'] self.mean_3d = data['mean_3d'] self.std_3d = data['std_3d'] self._data_train['3d'] = normalize_data(self._data_train['3d'], self.mean_3d, self.std_3d, skip_root=True) self._data_train['2d'] = normalize_data(self._data_train['2d'], self.mean_2d, self.std_2d, skip_root=self.center_2d) self._data_valid['3d'] = normalize_data(self._data_valid['3d'], self.mean_3d, self.std_3d, skip_root=True) self._data_valid['2d'] = normalize_data(self._data_valid['2d'], self.mean_2d, self.std_2d, skip_root=self.center_2d) visualize_2d(self._data_train['2d'][0, :, :], 'debug3dpw')