def merge_tile_predictions(self, batch_index: int) -> ImageBatch:
        """Join predictions from ensemble into whole image level representation for batch at index batch_index.

        Args:
            batch_index (int): Index of current batch.

        Returns:
            dict[str, Tensor | list]: List of merged predictions for specified batch.
        """
        current_batch_data = self.ensemble_predictions.get_batch_tiles(batch_index)

        # take first tile as base prediction, keep items that are the same over all tiles:
        # image_path, label, mask_path
        merged_predictions = {
            "image_path": current_batch_data[0, 0].image_path,
            "gt_label": current_batch_data[0, 0].gt_label,
        }
        if hasattr(current_batch_data[0, 0], "mask_path"):
            merged_predictions["mask_path"] = current_batch_data[0, 0].mask_path

        tiled_data = ["image", "gt_mask"]
        if hasattr(current_batch_data[0, 0], "anomaly_map") and current_batch_data[0, 0].anomaly_map is not None:
            tiled_data += ["anomaly_map", "pred_mask"]

        # merge all tiled data
        for t_key in tiled_data:
            if hasattr(current_batch_data[0, 0], t_key):
                merged_predictions[t_key] = self.merge_tiles(current_batch_data, t_key)

        # label and score merging
        merged_scores_and_labels = self.merge_labels_and_scores(current_batch_data)
        merged_predictions["pred_label"] = merged_scores_and_labels["pred_label"]
        merged_predictions["pred_score"] = merged_scores_and_labels["pred_score"]

        return ImageBatch(**merged_predictions)
Join predictions from ensemble into whole image level representation for batch at index batch_index.

        Args:
            batch_index (int): Index of current batch.

        Returns:
            dict[str, Tensor | list]: List of merged predictions for specified batch.
        
src/anomalib/pipelines/tiled_ensemble/components/utils/prediction_merging.py