def decode(self,
               heatmaps: Tuple[Tensor],
               displacements: Tuple[Tensor],
               test_cfg: ConfigType = {},
               metainfo: dict = {}) -> InstanceList:
        """Decode keypoints from outputs.

        Args:
            heatmaps (Tuple[Tensor]): The output heatmaps inferred from one
                image or multi-scale images.
            displacements (Tuple[Tensor]): The output displacement fields
                inferred from one image or multi-scale images.
            test_cfg (dict): The runtime config for testing process. Defaults
                to {}
            metainfo (dict): The metainfo of test dataset. Defaults to {}

        Returns:
            List[InstanceData]: A list of InstanceData, each contains the
                decoded pose information of the instances of one data sample.
        """

        if self.decoder is None:
            raise RuntimeError(
                f'The decoder has not been set in {self.__class__.__name__}. '
                'Please set the decoder configs in the init parameters to '
                'enable head methods `head.predict()` and `head.decode()`')

        multiscale_test = test_cfg.get('multiscale_test', False)
        skeleton = metainfo.get('skeleton_links', None)

        preds = []
        batch_size = heatmaps[0].shape[0]

        for b in range(batch_size):
            if multiscale_test:
                raise NotImplementedError
            else:
                keypoints, (root_scores,
                            keypoint_scores) = self.decoder.decode(
                                heatmaps[0][b], displacements[0][b])

            # rescore each instance
            if self.rescore_net is not None and skeleton and len(
                    keypoints) > 0:
                instance_scores = self.rescore_net(keypoints, keypoint_scores,
                                                   skeleton)
                instance_scores[torch.isnan(instance_scores)] = 0
                root_scores = root_scores * instance_scores

            # nms
            keypoints, keypoint_scores = to_numpy((keypoints, keypoint_scores))
            scores = to_numpy(root_scores)[..., None] * keypoint_scores
            if len(keypoints) > 0 and test_cfg.get('nms_dist_thr', 0) > 0:
                kpts_db = []
                for i in range(len(keypoints)):
                    kpts_db.append(
                        dict(keypoints=keypoints[i], score=keypoint_scores[i]))
                keep_instance_inds = nearby_joints_nms(
                    kpts_db,
                    test_cfg['nms_dist_thr'],
                    test_cfg.get('nms_joints_thr', None),
                    score_per_joint=True,
                    max_dets=test_cfg.get('max_num_people', 30))
                keypoints = keypoints[keep_instance_inds]
                scores = scores[keep_instance_inds]

            # pack outputs
            preds.append(
                InstanceData(keypoints=keypoints, keypoint_scores=scores))

        return preds
Decode keypoints from outputs.

        Args:
            heatmaps (Tuple[Tensor]): The output heatmaps inferred from one
                image or multi-scale images.
            displacements (Tuple[Tensor]): The output displacement fields
                inferred from one image or multi-scale images.
            test_cfg (dict): The runtime config for testing process. Defaults
                to {}
            metainfo (dict): The metainfo of test dataset. Defaults to {}

        Returns:
            List[InstanceData]: A list of InstanceData, each contains the
                decoded pose information of the instances of one data sample.
        
mmpose/mmpose/models/heads/hybrid_heads/dekr_head.py