def __getitem__()

in eft/datasets/base_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'
            targetIdx = '004906'
            targetIdx = '468792'
            for i in range(len(self.imgname)):
                if targetIdx in self.imgname[i]:
                    index =i
                    break
            print("DEBUG: selected index {}".format(index))
                
        # index=347 #TODO
        # index = 8940 #TODO
        # index = 665 #TODO

        # 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 = {}

        #Get scale/center from multilevel crop information using the chosing crop level [0,7]
        if self.is_train and \
                 self.multilevel_cropinfo is not None and  \
                    self.options is not None and   \
                    self.options.multilevel_crop_rand:

            # print(f"{self.datasetName}: yes multilevel")
            randomNum  =np.random.uniform()
            if randomNum <= self.options.multilevel_crop_rand_prob:

                cropLevel = np.random.randint(1,high=7)     #random 1-6 .. ignore 7 which is whole body
                # print(cropLevel)
                assert cropLevel>=1 and cropLevel<=7
                # print(f"Apply multi-crop: level{cropLevel}")
                scale = np.array(self.multilevel_cropinfo[index][cropLevel]['scale'])
                center = np.array(self.multilevel_cropinfo[index][cropLevel]['center'])
            else:
                scale = self.scale[index].copy()
                center = self.center[index].copy()
        elif self.is_train and self.options is not None and self.options.multilevel_crop>=0:
            cropLevel = self.options.multilevel_crop
            # print(f"Apply multi-crop: level{cropLevel}")
            scale = np.array(self.multilevel_cropinfo[index][cropLevel]['scale'])
            center = np.array(self.multilevel_cropinfo[index][cropLevel]['center'])


        elif 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:
            # print(f"{self.datasetName}: no multilevel")
            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 self.bLoadImage:
            try:
                img = cv2.imread(imgname)[:,:,::-1].copy().astype(np.float32)           ##Note: BGR to RGB. We always use RGB
            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 self.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)

        if self.subjectIds is not None:
            item['subjectId'] = self.subjectIds[index]
        else:
            item['subjectId'] = ""        #Garbage
        # print(item['subjectId'])

        #Processing 3D Hands
        if self.options != None and 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()     #
            S = 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()
            S = 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()            #(49,3)
        #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()       #In original space
        item['keypoints'] = torch.from_numpy(self.j2d_processing(keypoints, center, sc*scale, rot, flip)).float()       #Processing to make in bbox space

        # 2D Hand keypoints
        if self.kp_leftHand_gt is not None:
            lhand_keypoints = self.kp_leftHand_gt[index].copy()            #(49,3)
            item['kp_leftHand_gt'] = torch.from_numpy(self.j2d_processing(lhand_keypoints, center, sc*scale, rot, flip)).float()       #Processing to make in bbox space

        if self.kp_rightHand_gt is not None:
            rhand_keypoints = self.kp_rightHand_gt[index].copy()            #(49,3)
            item['kp_rightHand_gt'] = torch.from_numpy(self.j2d_processing(rhand_keypoints, center, sc*scale, rot, flip)).float()       #Processing to make in bbox space

        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

        if self.is_train == False:
            try:
                item['cam_param'] = self.cam_param[index]
            except AttributeError:
                item['cam_param'] = ''



        #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