def _convert_ann_to_bottomup_batch_data(self, ann_file):
        """Convert annotations to bottomup-style batch data."""
        img2ann = defaultdict(list)
        db = load(ann_file)
        for ann in db['annotations']:
            img2ann[ann['image_id']].append(ann)

        bottomup_data = []
        for img_id, anns in img2ann.items():
            _keypoints = np.array([ann['keypoints'] for ann in anns]).reshape(
                (len(anns), -1, 3))

            gt_instances = {
                'bbox_scores': np.ones((len(anns)), dtype=np.float32),
                'keypoints': _keypoints[..., :2],
                'keypoints_visible': _keypoints[..., 2:3]
            }

            # fake predictions
            keypoints = np.zeros_like(_keypoints)
            keypoints[..., 0] = _keypoints[..., 0] * 0.99
            keypoints[..., 1] = _keypoints[..., 1] * 1.02
            keypoints[..., 2] = _keypoints[..., 2] * 0.8

            pred_instances = {
                'keypoints': keypoints[..., :2],
                'keypoint_scores': keypoints[..., -1],
            }

            data = {'inputs': None}
            data_sample = {
                'id': [ann['id'] for ann in anns],
                'img_id': img_id,
                'gt_instances': gt_instances,
                'pred_instances': pred_instances,
                # dummy image_shape for testing
                'ori_shape': [640, 480],
                'raw_ann_info': copy.deepcopy(anns),
            }

            # batch size = 1
            data_batch = [data]
            data_samples = [data_sample]
            bottomup_data.append((data_batch, data_samples))
        return bottomup_data
Convert annotations to bottomup-style batch data.
mmpose/tests/test_evaluation/test_metrics/test_keypoint_partition_metric.py