def _load_data_set(self): clk = Clock() self.images = [] self.kp2ds = [] self.boxs = [] self.kp3ds = [] self.shapes = [] self.poses = [] print('start loading hum3.6m data.') anno_file_path = os.path.join(self.data_folder, 'annot.h5') with h5py.File(anno_file_path) as fp: total_kp2d = np.array(fp['gt2d']) total_kp3d = np.array(fp['gt3d']) total_shap = np.array(fp['shape']) total_pose = np.array(fp['pose']) total_image_names = np.array(fp['imagename']) assert len(total_kp2d) == len(total_kp3d) and len(total_kp2d) == len(total_image_names) and \ len(total_kp2d) == len(total_shap) and len(total_kp2d) == len(total_pose) l = len(total_kp2d) def _collect_valid_pts(pts): r = [] for pt in pts: if pt[2] != 0: r.append(pt) return r for index in range(l): kp2d = total_kp2d[index].reshape((-1, 3)) if np.sum(kp2d[:, 2]) < self.min_pts_required: continue lt, rb, v = calc_aabb(_collect_valid_pts(kp2d)) self.kp2ds.append(np.array(kp2d.copy(), dtype=np.float)) self.boxs.append((lt, rb)) self.kp3ds.append(total_kp3d[index].copy().reshape(-1, 3)) self.shapes.append(total_shap[index].copy()) self.poses.append(total_pose[index].copy()) self.images.append( os.path.join(self.data_folder, 'image') + total_image_names[index].decode()) print('finished load hum3.6m data, total {} samples'.format( len(self.kp3ds))) clk.stop()
def _handle_image(self, image_path, kps): pt_valid = [] for pt in kps: if pt[2] == 1: pt_valid.append(pt) lt, rb, valid = calc_aabb(pt_valid) if not valid: return self.kp2ds.append(kps.copy().astype(np.float)) self.images.append(image_path) self.boxs.append((lt, rb))
def loadData(self): self.keyps2d = [] self.keyps3d = [] self.smplShapeParams = [] self.smplPoseParams = [] self.images = [] self.boxes = [] fp = h5py.File( os.path.join(cfg.pathToHuman36m, "data", "annot-copy.h5"), "r") keyps2d = np.array(fp["gt2d"]) keyps3d = np.array(fp["gt3d"]) smplShapeParams = np.array(fp["shape"]) smplPoseParams = np.array(fp["pose"]) images = np.array(fp["imagename"]) assert (len(keyps2d) == len(keyps3d)) assert (len(keyps2d) == len(smplShapeParams)) assert (len(keyps2d) == len(smplPoseParams)) assert (len(keyps2d) == len(images)) def isValid(pts): r = [] for pt in pts: if pt[2] != 0: r.append(pt) return r for idx in cfg.imgsLoad: #range(cfg.nImgsLoad): #range(len(keyps2d)): fullImgPath = os.path.join(cfg.pathToHuman36m, "data") + images[idx].decode() if not os.path.isfile(fullImgPath): continue keyp2d = keyps2d[idx].reshape((-1, 3)) if np.sum(keyp2d[:, 2]) < self.minPtsRequired: continue lt, rb, v = util.calc_aabb(isValid(keyp2d)) self.keyps2d.append(np.array(keyp2d.copy(), dtype=np.float)) self.boxes.append((lt, rb)) self.keyps3d.append(keyps3d[idx].copy().reshape(-1, 3)) self.smplShapeParams.append(smplShapeParams[idx].copy()) self.smplPoseParams.append(smplPoseParams[idx].copy()) self.images.append(fullImgPath)