def __getitem__(self, index): img = self.LoadImage(index) pts, c, s = self.GetPartInfo(index) r = 0 if self.split == 'train': s = s * (2 ** Rnd(ref.scale)) r = 0 if np.random.random() < 0.6 else Rnd(ref.rotate) inp = Crop(img, c, s, r, ref.inputRes) / 256. out = np.zeros((ref.nJoints, ref.outputRes, ref.outputRes)) Reg = np.zeros((ref.nJoints, 3)) for i in range(ref.nJoints): if pts[i][0] > 1: pt = Transform(pts[i], c, s, r, ref.outputRes) out[i] = DrawGaussian(out[i], pt, ref.hmGauss) Reg[i, :2] = pt Reg[i, 2] = 1 if self.split == 'train': if np.random.random() < 0.5: inp = Flip(inp) out = ShuffleLR(Flip(out)) Reg[:, 1] = Reg[:, 1] * -1 Reg = ShuffleLR(Reg) #print 'before', inp[0].max(), inp[0].mean() inp[0] = np.clip(inp[0] * (np.random.random() * (0.4) + 0.6), 0, 1) inp[1] = np.clip(inp[1] * (np.random.random() * (0.4) + 0.6), 0, 1) inp[2] = np.clip(inp[2] * (np.random.random() * (0.4) + 0.6), 0, 1) #print 'after', inp[0].max(), inp[0].mean() inp = torch.from_numpy(inp) if self.returnMeta: return inp, out, Reg, np.zeros((ref.nJoints, 3)) else: return inp, out
def __getitem__(self, index): img = self.LoadImage(index) pts, c, s = self.GetPartInfo(index) r = 0 if self.split == 'train': s = s * (2**Rnd(ref.scale)) r = 0 if np.random.random() < 0.6 else Rnd(ref.rotate) inp = Crop(img, c, s, r, ref.inputRes) / 256. out = np.zeros((ref.nJoints, ref.outputRes, ref.outputRes)) for i in range(ref.nJoints): if pts[i][0] > 1: pt = Transform(pts[i], c, s, r, ref.outputRes) out[i] = DrawGaussian(out[i], pt, ref.hmGauss) if self.split == 'train': if np.random.random() < 0.5: inp = Flip(inp) out = ShuffleLR(Flip(out)) inp[0] = np.clip(inp[0] * (np.random.random() * (0.4) + 0.6), 0, 1) inp[1] = np.clip(inp[1] * (np.random.random() * (0.4) + 0.6), 0, 1) inp[2] = np.clip(inp[2] * (np.random.random() * (0.4) + 0.6), 0, 1) meta = np.zeros(1) else: meta = {'index': index, 'center': c, 'scale': s, 'rotate': r} return inp, out, meta
def __getitem__(self, index): img = self.LoadImage(index) pts, action, c, s = self.GetPartInfo(index) nb_pts = len(pts) r = 0 flip = False if self.split == 'train': s = s * (2**Rnd(ref.scale)) r = 0 if np.random.random() < 0.6 else Rnd(ref.rotate) inp = old_div(Crop(img, c, s, r, ref.inputRes), 256.) if self.split == 'train': if np.random.random() < 0.5: inp = Flip(inp) flip = True inp[0] = np.clip(inp[0] * (np.random.random() * (0.4) + 0.6), 0, 1) inp[1] = np.clip(inp[1] * (np.random.random() * (0.4) + 0.6), 0, 1) inp[2] = np.clip(inp[2] * (np.random.random() * (0.4) + 0.6), 0, 1) meta = np.zeros(1) else: meta = {'index': index, 'center': c, 'scale': s, 'rotate': r} output = [] for k in range(nb_pts): out = np.zeros((ref.nJoints, ref.outputRes, ref.outputRes)) for i in range(ref.nJoints): if pts[k][i][0] > 1: pt = Transform(pts[k][i], c, s, r, ref.outputRes) out[i] = DrawGaussian(out[i], pt, ref.hmGauss) if self.split == 'train': out = ShuffleLR(Flip(out)) output.append(out) return inp, output, action, meta
def __getitem__(self, index): img = self.LoadImage(index) pts2d, pts3d, emb, c, s = self.GetPartInfo(index) s = min(s, max(img.shape[0], img.shape[1])) * 1.0 pts3d[:, 2] += s / 2 r = 0 if self.split == 'train': s = s * (2**Rnd(ref.scale)) c[1] = c[1] + Rnd(ref.shiftY) r = 0 if np.random.random() < 0.6 else Rnd(ref.rotate) inp = Crop(img, c, s, r, ref.inputRes) inp = inp.transpose(2, 0, 1).astype(np.float32) / 256. starMap = np.zeros((1, ref.outputRes, ref.outputRes)) embMap = np.zeros((3, ref.outputRes, ref.outputRes)) depMap = np.zeros((1, ref.outputRes, ref.outputRes)) mask = np.concatenate([ np.ones((1, ref.outputRes, ref.outputRes)), np.zeros((4, ref.outputRes, ref.outputRes)) ]) for i in range(pts3d.shape[0]): if self.annot['valid'][index][i] > ref.eps: if (self.annot['vis'][index][i] > ref.eps): pt3d = Transform3D(pts3d[i], c, s, r, ref.outputRes).astype(np.int32) pt2d = Transform(pts2d[i], c, s, r, ref.outputRes).astype(np.int32) if pt2d[0] >= 0 and pt2d[0] < ref.outputRes and pt2d[ 1] >= 0 and pt2d[1] < ref.outputRes: embMap[:, pt2d[1], pt2d[0]] = emb[i] depMap[0, pt2d[1], pt2d[0]] = 1.0 * pt3d[2] / ref.outputRes - 0.5 mask[1:, pt2d[1], pt2d[0]] = 1 starMap[0] = np.maximum( starMap[0], DrawGaussian(np.zeros((ref.outputRes, ref.outputRes)), pt2d, ref.hmGauss).copy()) out = starMap if 'emb' in self.opt.task: out = np.concatenate([out, embMap]) if 'dep' in self.opt.task: out = np.concatenate([out, depMap]) mask = mask[:out.shape[0]].copy() if self.split == 'train': if np.random.random() < 0.5: inp = Flip(inp) out = Flip(out) mask = Flip(mask) if 'emb' in self.opt.task: out[1] = -out[1] return inp, out, mask
def __getitem__(self, index): if self.split == 'train': index = np.random.randint(self.nVideos) whichFrames, frameWiseData = self.annotations[index] numFrames = len(whichFrames) if self.loadConsecutive: startpt = random.randint(1, numFrames - (self.nFramesLoad - 1)) inpFrames = np.zeros((3, self.nFramesLoad, 256, 256)) outPts_2ds = np.zeros((ref.nJoints, self.nFramesLoad, 2)) outOutRegs = np.ones((ref.nJoints, self.nFramesLoad, 1)) outPts_3d_monos = -1 * np.ones((ref.nJoints, self.nFramesLoad, 3)) outOutMaps = np.zeros( (ref.nJoints, self.nFramesLoad, ref.outputRes, ref.outputRes)) meta = {} nPersons = len(frameWiseData[whichFrames[startpt]]) if nPersons < 1: return self.__getitem__(index + 1) personIndex = random.randint(0, nPersons - 1) meta['personIndex'] = personIndex scale = 1 angle = 0 flipOrNot = 0 if self.split == 'train': angle = 0 if np.random.random() < 0.5 else Rnd(ref.rotate) scale = (2**Rnd(ref.scale)) flipOrNot = random.random() > 0.5 meta['s'] = scale meta['r'] = angle meta['flip'] = flipOrNot for i in range(self.nFramesLoad): a, b, c, d = self.getitem(startpt + i, meta, whichFrames, frameWiseData) inpFrames[:, i, :, :] = a outOutMaps[:, i, :, :] = b return (inpFrames, outOutMaps, outPts_2ds, outOutRegs, outPts_3d_monos)
def __getitem__(self, index): img = self.LoadImage(index) class_id = self.annot['class_id'][index] c, s, v = self.GetPartInfo(index) s = min(s, max(img.shape[0], img.shape[1])) * 1.0 r = 0 if self.split == 'train': s = s * (2 ** Rnd(ref.scale)) c[1] = c[1] + Rnd(ref.shiftY) r = 0 if np.random.random() < 0.6 else Rnd(ref.rotate) v[2] += r / 180. v[2] += 2 if v[2] < -1 else (-2 if v[2] > 1 else 0) inp = Crop(img, c, s, r, ref.inputRes) inp = inp.transpose(2, 0, 1).astype(np.float32) / 256. if self.split == 'train': if np.random.random() < 0.5: inp = Flip(inp) v[0] = - v[0] v[2] = - v[2] v[2] += 2 if v[2] <= -1 else 0 #https://github.com/shubhtuls/ViewpointsAndKeypoints/blob/master/rcnnVp/rcnnBinnedJointTrainValTestCreate.m#L77 vv = v.copy() if vv[0] < 0: v[0] = self.opt.numBins - 1 - np.floor(-vv[0] * self.opt.numBins / 2.) else: v[0] = np.floor(vv[0] * self.opt.numBins / 2.) v[1] = np.ceil(vv[1] * self.opt.numBins / 2. + self.opt.numBins / 2. - 1) v[2] = np.ceil(vv[2] * self.opt.numBins / 2. + self.opt.numBins / 2. - 1) v = v.astype(np.int32) if self.opt.specificView: vv = np.ones(3 * len(ref.pascalClassId), dtype = np.int32) * self.opt.numBins vv[class_id * 3: class_id * 3 + 3] = v.copy() v = vv.copy() return inp, v