code: def get_transforms(
      config: str | A.Compose | None = None,
      image_size: int | tuple | None = None,
      to_tensor: bool = True,
  ) -> A.Compose:
      """Get transforms from config or image size.
  
      Args:
          config (str | A.Compose | None, optional): Albumentations transforms.
              Either config or albumentations ``Compose`` object. Defaults to None.
          image_size (int | tuple | None, optional): Image size to transform. Defaults to None.
          to_tensor (bool, optional): Boolean to convert the final transforms into Torch tensor. Defaults to True.
  
      Raises:
          ValueError: When both ``config`` and ``image_size`` is ``None``.
          ValueError: When ``config`` is not a ``str`` or `A.Compose`` object.
  
      Returns:
          A.Compose: Albumentation ``Compose`` object containing the image transforms.
  
      Examples:
          >>> import skimage
          >>> image = skimage.data.astronaut()
  
          >>> transforms = get_transforms(image_size=256, to_tensor=False)
          >>> output = transforms(image=image)
          >>> output["image"].shape
          (256, 256, 3)
  
          >>> transforms = get_transforms(image_size=256, to_tensor=True)
          >>> output = transforms(image=image)
          >>> output["image"].shape
          torch.Size([3, 256, 256])
  
  
          Transforms could be read from albumentations Compose object.
          >>> import albumentations as A
          >>> from albumentations.pytorch import ToTensorV2
          >>> config = A.Compose([A.Resize(512, 512), ToTensorV2()])
          >>> transforms = get_transforms(config=config, to_tensor=False)
          >>> output = transforms(image=image)
          >>> output["image"].shape
          (512, 512, 3)
          >>> type(output["image"])
          numpy.ndarray
  
          Transforms could be deserialized from a yaml file.
          >>> transforms = A.Compose([A.Resize(1024, 1024), ToTensorV2()])
          >>> A.save(transforms, "/tmp/transforms.yaml", data_format="yaml")
          >>> transforms = get_transforms(config="/tmp/transforms.yaml")
          >>> output = transforms(image=image)
          >>> output["image"].shape
          torch.Size([3, 1024, 1024])
      """
      warnings.warn(
          DeprecationWarning(
              "The function anomalib.pre_processing.pre_process.get_transforms is deprecated and will be removed in a "
              "future release. Please use anomalib.data.utils.transform.get_transforms instead."
          )
      )
  
      if config is None is image_size:
          raise ValueError(
              "Both config and image_size cannot be `None`. "
              "Provide either config file to de-serialize transforms "
              "or image_size to get the default transformations"
          )
  
      transforms: A.Compose
  
      if config is None and image_size is not None:
          logger.warning(
              "Transform configs has not been provided. Images will be normalized using ImageNet statistics."
          )
  
          height, width = get_image_height_and_width(image_size)
          transforms = A.Compose(
              [
                  A.Resize(
                      height=height, width=width, always_apply=True
                  ),
                  A.Normalize(
                      mean=(0.485, 0.456, 0.406),
                      std=(0.229, 0.224, 0.225),
                  ),
                  ToTensorV2(),
              ]
          )
  
      if config is not None:
          if isinstance(config, str):
              transforms = A.load(filepath=config, data_format="yaml")
          elif isinstance(config, A.Compose):
              transforms = config
          else:
              raise ValueError(
                  "config could be either ``str`` or ``A.Compose``"
              )
  
      if not to_tensor:
          if isinstance(transforms[-1], ToTensorV2):
              transforms = A.Compose(transforms[:-1])
  
      # always resize to specified image size
      if (
          not any(
              isinstance(transform, A.Resize)
              for transform in transforms
          )
          and image_size is not None
      ):
          height, width = get_image_height_and_width(image_size)
          transforms = A.Compose(
              [
                  A.Resize(
                      height=height, width=width, always_apply=True
                  ),
                  transforms,
              ]
          )
  
      return transforms
  
file_path: anomalib/src/anomalib/pre_processing/pre_process.py
imports: from __future__ import annotations
  import logging
  import warnings
  from typing import Any
  import albumentations
  from albumentations.pytorch import ToTensorV2
label_desc: Use image node_id 2 for calling a global function with example usage: get_transforms(config, image_size, to_tensor) and returns: transforms