for start, end in training_batch: subdata = imgs_train[start:end].copy() subcom = coms_train[start:end].copy() subcube = cubes_train[start:end].copy() subM = Ms_train[start:end].copy() subgt3Dcrop = gt3Dcrops_train[start:end].copy() resdata = np.ones_like(subdata) resgt3D = np.ones_like(subgt3Dcrop) hts = np.zeros(shape=(batch_size, 24, 24, 14)) jtIs = np.zeros(shape=(batch_size, 42)) for idx in range(batch_size): dm = norm_dm(subdata[idx], subcom[idx], subcube[idx]) s = augmentCrop(dm, subgt3Dcrop[idx], di_train.joint3DToImg(subcom[idx]), subcube[idx], subM[idx], ['com', 'rot', 'none', 'sc'], hd, False, rng=rng) resdata[idx] = s[0] resgt3D[idx] = s[2] mode = s[7] gt3D_ = resgt3D[idx] * subcube[idx][0] / 2. + subcom[idx] jtI_ = transformPoints2D(di_train.joints3DToImg(gt3D_), subM[idx]) jtI_ = np.reshape(jtI_, (1, 42)) ht_ = joints_heatmap_gen([1], jtI_, (24, 24), points=14) hts[idx] = np.transpose(ht_, (0, 2, 3, 1)) / 255.
sess.run(lr_update) for start, end in training_batch: subdata = imgs_train[start:end].copy() subcom = coms_train[start:end].copy() subcube = cubes_train[start:end].copy() subM = Ms_train[start:end].copy() subgt3Dcrop = gt3Dcrops_train[start:end].copy() resdata=np.ones_like(subdata) resgt3D=np.ones_like(subgt3Dcrop) hts=np.zeros(shape=(batch_size,24,24,14)) jtIs=np.zeros(shape=(batch_size,42)) for idx in range(batch_size): dm = norm_dm(subdata[idx], subcom[idx], subcube[idx]) s = augmentCrop(dm, subgt3Dcrop[idx], di_train.joint3DToImg(subcom[idx]), subcube[idx], subM[idx],['com', 'rot', 'none','sc'], hd, False, rng=rng) resdata[idx] = s[0] resgt3D[idx] = s[2] mode=s[7] gt3D_ = resgt3D[idx] * subcube[idx][0] / 2. + subcom[idx] jtI_ = transformPoints2D(di_train.joints3DToImg(gt3D_), subM[idx]) jtI_=np.reshape(jtI_,(1,42)) ht_=joints_heatmap_gen([1],jtI_,(24,24),points=14) hts[idx]=np.transpose(ht_,(0,2,3,1))/255. feed_dict = {inputs: resdata.reshape(-1, 96, 96, 1), label: resgt3D.reshape(-1, 42), gt_ht:hts, is_train:True,
class dataset_hand_NYU(data.Dataset): def __init__(self, specs): seed = specs['seed'] root = specs['root'] subset = specs['subset'] docom = specs['docom'] self.rng = np.random.RandomState(seed) self.sampled_poses = None self.pose_only = False self.nmax = np.inf self.augment = specs['augment'] self.num_sample_poses = specs['sample_poses'] self.joint_subset = specs['joint_subset'] self.aug_modes = ['none', 'com', 'rot'] print("create data") self.flip_y = False com_idx = 32 cube_size = 300 if 'MSRA' in self.joint_subset: self.joint_subset = np.asarray([29, 23, 22, 20, 18, 17, 16, 14, 12, 11, 10,\ 8, 6, 5, 4, 2, 0, 28, 27, 25, 24], dtype='int32') com_idx = 17 elif 'ICVL' in self.joint_subset: self.joint_subset = np.asarray([34, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10,\ 8, 6, 4, 2, 0], dtype='int32') self.flip_y = True com_idx = 34 cube_size = 350 else: self.joint_subset = np.arange(36) self.di = NYUImporter(root, refineNet=None, allJoints=True, com_idx=com_idx, cacheDir='../../cache/') if 'synth' in subset: self.di.default_cubes[subset] = (cube_size, cube_size, cube_size) print(self.di.default_cubes[subset]) self.Seq = self.di.loadSequence(subset, rng=self.rng, shuffle=True, docom=docom) #print(self.Seq.data[0].gt3Dcrop) #self.di.showAnnotatedDepth(self.Seq.data[0]) #print('joint_subset', self.joint_subset) # create training data cube = np.asarray(self.Seq.config['cube'], 'float32') com = np.asarray(self.Seq.data[0].com, 'float32') img = np.asarray(self.Seq.data[0].dpt.copy(), 'float32') img = normalize(img, com, cube) self.hd = HandDetector(img, abs(self.di.fx), abs(self.di.fy), importer=self.di) self.num = len(self.Seq.data) print(' data loaded with %d samples' % self.num) def sample_poses(self): train_cube = np.asarray([self.Seq.config['cube']] * self.num, dtype='float32') train_com = np.asarray([d.com for d in self.Seq.data], dtype='float32') train_gt3D = np.asarray([d.gt3Dcrop for d in self.Seq.data], dtype='float32') self.sampled_poses = self.hd.sampleRandomPoses(self.di, self.rng, train_gt3D, train_com,\ train_cube, self.num_sample_poses, self.nmax, \ self.aug_modes)#.reshape((-1, train_gt3D.shape[1]*3)) self.num = self.sampled_poses.shape[0] self.nmax = self.sampled_poses.shape[0] print('%d sample poses created!' % self.num) def __getitem__(self, i): if self.pose_only and self.sampled_poses is not None: pos = self.sampled_poses[i][self.joint_subset] if self.flip_y: pos[:, 1] *= -1 return pos.flatten() cube = np.asarray(self.Seq.config['cube'], 'float32') com = np.asarray(self.Seq.data[i].com, 'float32') M = np.asarray(self.Seq.data[i].T, dtype='float32') gt3D = np.asarray(self.Seq.data[i].gt3Dcrop, dtype='float32') img = np.asarray(self.Seq.data[i].dpt.copy(), 'float32') img = normalize(img, com, cube) if not self.augment: if self.joint_subset is not None: gt3D = gt3D[self.joint_subset] if self.flip_y: gt3D[:, 1] *= -1 if self.pose_only: return gt3D.flatten() / (cube[2] / 2.) #print(img.shape, gt3D.flatten().shape, com.shape, M.shape, cube.shape) return np.expand_dims( img, axis=0), gt3D.flatten() / (cube[2] / 2.), com, M, cube, cube img, _, gt3D, cube, com2D, M, _ = augmentCrop(img, gt3D, \ self.di.joint3DToImg(com), cube, M, self.aug_modes, self.hd, rng=self.rng) if self.joint_subset is not None: gt3D = gt3D[self.joint_subset] if self.flip_y: gt3D[:, 1] *= -1 if self.pose_only: return gt3D.flatten() #print(imgD.shape, gt3Dn.flatten().shape, com.shape, M.shape, cube.shape) return np.expand_dims( img, axis=0), gt3D.flatten(), self.di.jointImgTo3D(com2D), M, cube, cube def set_nmax(self, frac): self.nmax = int(self.num * frac) print('self.nmax %d' % self.nmax) def __len__(self): return np.minimum(self.num, self.nmax)