code: def collate_fn(batch: list) -> dict[str, Any]:
      """Custom collate function that collates bounding boxes as lists.
  
      Bounding boxes are collated as a list of tensors, while the default collate function is used for all other entries.
  
      Args:
          batch (List): list of items in the batch where len(batch) is equal to the batch size.
  
      Returns:
          dict[str, Any]: Dictionary containing the collated batch information.
      """
      elem = batch[
          0
      ]  # sample an element from the batch to check the type.
      out_dict = {}
      if isinstance(elem, dict):
          if "boxes" in elem.keys():
              # collate boxes as list
              out_dict["boxes"] = [item.pop("boxes") for item in batch]
          # collate other data normally
          out_dict.update(
              {
                  key: default_collate([item[key] for item in batch])
                  for key in elem
              }
          )
          return out_dict
      return default_collate(batch)
  
imports: from __future__ import annotations
  import logging
  from abc import ABC
  from typing import Any
  from pandas import DataFrame
  from pytorch_lightning import LightningDataModule
  from pytorch_lightning.utilities.types import EVAL_DATALOADERS, TRAIN_DATALOADERS
  from torch.utils.data.dataloader import DataLoader, default_collate
  from anomalib.data.base.dataset import AnomalibDataset
  from anomalib.data.synthetic import SyntheticAnomalyDataset
  from anomalib.data.utils import TestSplitMode, ValSplitMode, random_split, split_by_label
label_desc: Use image node_id 1 for calling a global function with example usage: collate_fn(batch) and returns: default_collate, out_dict