def __getitem__()

in eft/datasets/video_dataset.py [0:0]


    def __getitem__(self, index):

        bLoadImage = self.bLoadImage
        # print("Load: {}".format(index) )

        if g_debugMode: ###############  DEBUG MODE ###############  
            import os
            if os.path.exists("exemplarTestTarget.txt"):        #Read target index from this file 
                with open("exemplarTestTarget.txt","r") as f:
                    targetIdx =  f.readlines()[0]
                    print("targetImgFrame: {}".format(targetIdx))
                    self.options.exemplar_targetIdx = targetIdx #Save this. If a new one model should be reinitiated in base_trainer.py
            else: 
                targetIdx = '001'

            for i in range(len(self.imgname)):
                if targetIdx in self.imgname[i]:
                    index =i
                    break
            print("DEBUG: selected index {}".format(index))

        # for i in range(len(self.imgname)):
        #     # if 'COCO_train2014_000000000322' in self.imgname[i]:
        #     if '00_15_00030840' in self.imgname[i]:
        #         index =i
        #         break
        # print("DEBUG: selected index {}".format(index))
        #Good panoptic sample: 171204_pose6/00003110/00_00_00003110.jpg

        item = {}

        if self.bEnforceUpperOnly:      #Always upper only 
            if self.scale_upperbody[index]>0:
                scale = self.scale_upperbody[index].copy()
                center = self.center_upperbody[index].copy()
            else:   #except no valid cropping
                scale = self.scale[index].copy()
                center = self.center[index].copy()

        elif self.is_train and (self.options is not None and self.options.bUpperBodyTest):

            randomNum  =np.random.uniform()
            # print(randomNum)
            if self.scale_upperbody[index]>0 and randomNum <= self.options.upperBodyTest_prob:
                
                if self.options.bFacePartTest:     
                    randomNumAgain  =np.random.uniform()
                    if randomNumAgain<0.5 and self.scale_facePart[index]>0:
                        # print("facepart")
                        scale = self.scale_facePart[index].copy()
                        center = self.center_facePart[index].copy()
                    else:
                        # print("upperbody")
                        scale = self.scale_upperbody[index].copy()
                        center = self.center_upperbody[index].copy()
                        
                else:
                    scale = self.scale_upperbody[index].copy()
                    center = self.center_upperbody[index].copy()

            else:
                scale = self.scale[index].copy()
                center = self.center[index].copy()
        else:
            scale = self.scale[index].copy()
            center = self.center[index].copy()

        # Get augmentation parameters
        if (self.options is not None and self.options.bExemplarMode) or g_debugMode:    #Debug: No augmentation#g_debugMode:     ###############  DEBUG MODE ###############  
            flip = 0            # flipping
            pn = np.ones(3)  # per channel pixel-noise
            rot = 0            # rotation
            sc = 1   
        else:
            flip, pn, rot, sc = self.augm_params()
        
        # Load image
        imgname = join(self.img_dir, self.imgname[index])
        # print("dbName: {} | imgname: {}".format(self.datasetName, imgname))

        if bLoadImage:
            try:
                img = cv2.imread(imgname)[:,:,::-1].copy().astype(np.float32)
            except TypeError:
                print("Error: cannnot find image from: {}".format(imgname) )
            orig_shape = np.array(img.shape)[:2]
        else:
            orig_shape =0

        # Get SMPL parameters, if available
        if self.has_smpl[index]:
            pose = self.pose[index].copy()
            betas = self.betas[index].copy()
        else:
            pose = np.zeros(72)
            betas = np.zeros(10)

        # Process image
        if bLoadImage:
            try:
                img = self.rgb_processing(img, center, sc*scale, rot, flip, pn)
            except:
                # print("Warning: image processing has been failed: {}".format(imgname))
                print("Warning: image processing has been failed: {}: sc{}, rot{}, flipt{},pn{}".format(imgname,sc,rot,flip,pn))
                img = np.zeros((3,224,224), dtype=np.float32)       #generate blank image

            if img is None:
                # print("Warning: image processing has been failed: {}".format(imgname))
                print("Warning: image processing has been failed: {}: sc{}, rot{}, flipt{},pn{}".format(imgname,sc,rot,flip,pn))
                img = np.zeros((3,224,224), dtype=np.float32)       #generate blank image

            img = torch.from_numpy(img).float()
            item['img'] = self.normalize_img(img)
        else:
            item['img'] =''


        # Store image before normalization to use it in visualization
        item['pose'] = torch.from_numpy(self.pose_processing(pose, rot, flip)).float()
        item['betas'] = torch.from_numpy(betas).float()
        item['imgname'] = imgname
        if self.annotIds is not None:
            item['annotId'] = self.annotIds[index]
        else:
            item['annotId'] = -1        #Garbage

        # print("Debug: {}".format(item['annotId']))

        # Get 3D pose, if available
        if self.has_pose_3d:
            S = self.pose_3d[index].copy()
            item['pose_3d'] = torch.from_numpy(self.j3d_processing(S, rot, flip)).float()
        else:
            item['pose_3d'] = torch.zeros(24,4, dtype=torch.float32)

        
        #Processing Hands
        if self.options.bUseHand3D:
            S = np.ones( (self.rhand_3d[index].shape[0], self.rhand_3d[index].shape[1]+1)   )
            S[:,:-1] = self.rhand_3d[index].copy()     #
            item['rhand_3d'] = torch.from_numpy(self.j3d_processing(S, rot, flip)).float()

            S = np.ones( (self.lhand_3d[index].shape[0], self.lhand_3d[index].shape[1]+1)   )
            S[:,:-1] = self.lhand_3d[index].copy()
            item['lhand_3d'] = torch.from_numpy(self.j3d_processing(S, rot, flip)).float()            

        # else:
        #     item['pose_3d'] = torch.zeros(24,4, dtype=torch.float32)


        # Get 2D keypoints and apply augmentation transforms
        keypoints = self.keypoints[index].copy()

        #Disable specifically foot, if too close to boundarys
        imgHeight = orig_shape[0]
        if abs(keypoints[25+0,1] - imgHeight)<10 and keypoints[10,2]<0.1:        #Right Foot. within 10 pix from the boundary
            keypoints[25+0,2] = 0 #Disable
        if abs(keypoints[25+5,1] - imgHeight)<10 and keypoints[13,2]<0.1:       #Left Foot. 
            keypoints[25+5,2] =0 #Disable


        item['keypoints_original'] = self.keypoints[index].copy()
        item['keypoints'] = torch.from_numpy(self.j2d_processing(keypoints, center, sc*scale, rot, flip)).float()
        item['has_smpl'] = self.has_smpl[index]
        item['has_pose_3d'] = self.has_pose_3d
        item['scale'] = float(sc * scale)
        item['center'] = center.astype(np.float32)
        item['orig_shape'] = orig_shape
        item['is_flipped'] = flip
        item['rot_angle'] = np.float32(rot)
        item['gender'] = self.gender[index]
        item['sample_index'] = index
        item['dataset_name'] = self.datasetName

        #for Panoptic DB.... to check existence...bad code.
        # parentIdx = 100* (int(index /100.0) + 1)
        # item['pkl_save_name'] = join(self.img_dir,self.imgname[parentIdx])

        try:
            item['maskname'] = self.maskname[index]
        except AttributeError:
            item['maskname'] = ''
        try:
            item['partname'] = self.partname[index]
        except AttributeError:
            item['partname'] = ''

        return item