def encode(self,
               keypoints: np.ndarray,
               keypoints_visible: Optional[np.ndarray] = None) -> dict:
        """Encoding keypoints to regression labels and heatmaps.

        Args:
            keypoints (np.ndarray): Keypoint coordinates in shape (N, K, D)
            keypoints_visible (np.ndarray): Keypoint visibilities in shape
                (N, K)

        Returns:
            dict:
            - keypoint_labels (np.ndarray): The normalized regression labels in
                shape (N, K, D) where D is 2 for 2d coordinates
            - heatmaps (np.ndarray): The generated heatmap in shape
                (K, H, W) where [W, H] is the `heatmap_size`
            - keypoint_weights (np.ndarray): The target weights in shape
                (N, K)
        """
        encoded_hm = self.heatmap_codec.encode(keypoints, keypoints_visible)
        encoded_kp = self.keypoint_codec.encode(keypoints, keypoints_visible)

        heatmaps = encoded_hm['heatmaps']
        keypoint_labels = encoded_kp['keypoint_labels']
        keypoint_weights = encoded_kp['keypoint_weights']

        if self.normalize:
            val_sum = heatmaps.sum(axis=(-1, -2)).reshape(-1, 1, 1) + 1e-24
            heatmaps = heatmaps / val_sum

        encoded = dict(
            keypoint_labels=keypoint_labels,
            heatmaps=heatmaps,
            keypoint_weights=keypoint_weights)

        return encoded
Encoding keypoints to regression labels and heatmaps.

        Args:
            keypoints (np.ndarray): Keypoint coordinates in shape (N, K, D)
            keypoints_visible (np.ndarray): Keypoint visibilities in shape
                (N, K)

        Returns:
            dict:
            - keypoint_labels (np.ndarray): The normalized regression labels in
                shape (N, K, D) where D is 2 for 2d coordinates
            - heatmaps (np.ndarray): The generated heatmap in shape
                (K, H, W) where [W, H] is the `heatmap_size`
            - keypoint_weights (np.ndarray): The target weights in shape
                (N, K)
        
mmpose/mmpose/codecs/integral_regression_label.py