original_docstring: Check and load ground-truth keypoints
docstring: Check and load ground-truth keypoints
docstring_tokens: Check and load ground - truth keypoints
code: def _check_load_keypoints(self, coco, entry):
          """Check and load ground-truth keypoints"""
          ann_ids = coco.getAnnIds(imgIds=entry['id'], iscrowd=False)
          objs = coco.loadAnns(ann_ids)
          # check valid bboxes
          valid_objs = []
          width = entry['width']
          height = entry['height']
  
          for obj in objs:
              contiguous_cid = self.json_id_to_contiguous[obj['category_id']]
              if contiguous_cid >= self.num_class:
                  # not class of interest
                  continue
              if max(obj['keypoints']) == 0:
                  continue
              # convert from (x, y, w, h) to (xmin, ymin, xmax, ymax) and clip bound
              xmin, ymin, xmax, ymax = bbox_clip_xyxy(bbox_xywh_to_xyxy(obj['bbox']), width, height)
              # require non-zero box area
              if obj['area'] <= 0 or xmax <= xmin or ymax <= ymin:
                  continue
  
              # joints 3d: (num_joints, 3, 2); 3 is for x, y, z; 2 is for position, visibility
              joints_3d = np.zeros((self.num_joints, 3, 2), dtype=np.float32)
              for i in range(self.num_joints):
                  joints_3d[i, 0, 0] = obj['keypoints'][i * 3 + 0]
                  joints_3d[i, 1, 0] = obj['keypoints'][i * 3 + 1]
                  # joints_3d[i, 2, 0] = 0
                  visible = min(1, obj['keypoints'][i * 3 + 2])
                  joints_3d[i, :2, 1] = visible
                  # joints_3d[i, 2, 1] = 0
  
              if np.sum(joints_3d[:, 0, 1]) < 1:
                  # no visible keypoint
                  continue
  
              if self._check_centers:
                  bbox_center, bbox_area = self._get_box_center_area((xmin, ymin, xmax, ymax))
                  kp_center, num_vis = self._get_keypoints_center_count(joints_3d)
                  ks = np.exp(-2 * np.sum(np.square(bbox_center - kp_center)) / bbox_area)
                  if (num_vis / 80.0 + 47 / 80.0) > ks:
                      continue
  
              valid_objs.append({
                  'bbox': (xmin, ymin, xmax, ymax),
                  'joints_3d': joints_3d
              })
  
          if not valid_objs:
              if not self._skip_empty:
                  # dummy invalid labels if no valid objects are found
                  valid_objs.append({
                      'bbox': np.array([-1, -1, 0, 0]),
                      'joints_3d': np.zeros((self.num_joints, 3, 2), dtype=np.float32)
                  })
          return valid_objs
code_tokens: def _check_load_keypoints ( self , coco , entry ) : ann_ids = coco . getAnnIds ( imgIds = entry [ 'id' ] , iscrowd = False ) objs = coco . loadAnns ( ann_ids ) valid_objs = [ ] width = entry [ 'width' ] height = entry [ 'height' ] for obj in objs : contiguous_cid = self . json_id_to_contiguous [ obj [ 'category_id' ] ] if contiguous_cid >= self . num_class : continue if max ( obj [ 'keypoints' ] ) == 0 : continue xmin , ymin , xmax , ymax = bbox_clip_xyxy ( bbox_xywh_to_xyxy ( obj [ 'bbox' ] ) , width , height ) if obj [ 'area' ] <= 0 or xmax <= xmin or ymax <= ymin : continue joints_3d = np . zeros ( ( self . num_joints , 3 , 2 ) , dtype = np . float32 ) for i in range ( self . num_joints ) : joints_3d [ i , 0 , 0 ] = obj [ 'keypoints' ] [ i * 3 + 0 ] joints_3d [ i , 1 , 0 ] = obj [ 'keypoints' ] [ i * 3 + 1 ] visible = min ( 1 , obj [ 'keypoints' ] [ i * 3 + 2 ] ) joints_3d [ i , : 2 , 1 ] = visible if np . sum ( joints_3d [ : , 0 , 1 ] ) < 1 : continue if self . _check_centers : bbox_center , bbox_area = self . _get_box_center_area ( ( xmin , ymin , xmax , ymax ) ) kp_center , num_vis = self . _get_keypoints_center_count ( joints_3d ) ks = np . exp ( - 2 * np . sum ( np . square ( bbox_center - kp_center ) ) / bbox_area ) if ( num_vis / 80.0 + 47 / 80.0 ) > ks : continue valid_objs . append ( { 'bbox' : ( xmin , ymin , xmax , ymax ) , 'joints_3d' : joints_3d } ) if not valid_objs : if not self . _skip_empty : valid_objs . append ( { 'bbox' : np . array ( [ - 1 , - 1 , 0 , 0 ] ) , 'joints_3d' : np . zeros ( ( self . num_joints , 3 , 2 ) , dtype = np . float32 ) } ) return valid_objs
short_docstring: Check and load ground-truth keypoints
short_docstring_tokens: Check and load ground - truth keypoints
comment: """Check and load ground-truth keypoints"""$SEP$# check valid bboxes$SEP$# not class of interest$SEP$# convert from (x, y, w, h) to (xmin, ymin, xmax, ymax) and clip bound$SEP$# require non-zero box area$SEP$# joints 3d: (num_joints, 3, 2); 3 is for x, y, z; 2 is for position, visibility$SEP$# joints_3d[i, 2, 0] = 0$SEP$# joints_3d[i, 2, 1] = 0$SEP$# no visible keypoint$SEP$# dummy invalid labels if no valid objects are found